UNPKG

@aptpod/iscp-ts

Version:

iSCP 2.0 client library for TypeScript

542 lines 28.4 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _Upstream_instances, _Upstream_logger, _Upstream_id, _Upstream_idAlias, _Upstream_serverTime, _Upstream_sessionId, _Upstream_ackInterval, _Upstream_expiryInterval, _Upstream_qos, _Upstream_persist, _Upstream_flushPolicy, _Upstream_closeTimeout, _Upstream_closeSession, _Upstream_event, _Upstream_totalDataPoints, _Upstream_resolver, _Upstream_sendBuffer, _Upstream_lock, _Upstream_aliasMap, _Upstream_sequenceNumber, _Upstream_requester, _Upstream_sender, _Upstream_streamReader, _Upstream_abortController, _Upstream_start, _Upstream_readAckLoop, _Upstream_readReopenLoop, _Upstream_flushBufferSizeLoop, _Upstream_flushIntervalLoop, _Upstream_flush, _Upstream_close; Object.defineProperty(exports, "__esModule", { value: true }); exports.Upstream = exports.UpstreamAfterReceiveAckEvent = exports.UpstreamBeforeSendDataPointsEvent = exports.UpstreamClosedEvent = void 0; const await_lock_1 = __importDefault(require("await-lock")); const exceptions_1 = require("./exceptions"); const constant_1 = require("./constant"); const flush_policy_1 = require("./flush-policy"); const model_1 = require("./model"); const message_1 = require("./message"); const sequence_1 = require("./sequence"); const alias_map_1 = require("./utils/alias-map"); const resolver_1 = require("./utils/resolver"); const condition_1 = require("./utils/condition"); const timeout_1 = require("./utils/timeout"); const typed_event_1 = require("./utils/typed-event"); const stream_reader_iterator_1 = require("./utils/stream-reader-iterator"); /** * アップストリームをクローズした時に呼び出されるイベントです。 * @category Upstream */ class UpstreamClosedEvent { constructor(init) { this.state = init.state; this.error = init.error; } } exports.UpstreamClosedEvent = UpstreamClosedEvent; /** * データポイントを送信する直前に呼び出されるイベントです。 * @category Upstream */ class UpstreamBeforeSendDataPointsEvent { constructor(init) { this.streamId = init.streamId; this.chunk = init.chunk; } } exports.UpstreamBeforeSendDataPointsEvent = UpstreamBeforeSendDataPointsEvent; /** * アップストリームチャンクに対する確認応答を受信した時に呼び出されるイベントです。 * @category Upstream */ class UpstreamAfterReceiveAckEvent { constructor(init) { this.streamId = init.streamId; this.chunkAck = init.chunkAck; } } exports.UpstreamAfterReceiveAckEvent = UpstreamAfterReceiveAckEvent; /** * アップストリームを表すクラスです。 * * @attention このクラスのオブジェクトは、必ず{@link Conn}の{@link Conn.openUpstream}を使用して生成してください。 * * @category Upstream */ class Upstream { /** * @internal */ constructor(config) { _Upstream_instances.add(this); _Upstream_logger.set(this, void 0); _Upstream_id.set(this, void 0); _Upstream_idAlias.set(this, void 0); _Upstream_serverTime.set(this, void 0); _Upstream_sessionId.set(this, void 0); _Upstream_ackInterval.set(this, void 0); _Upstream_expiryInterval.set(this, void 0); _Upstream_qos.set(this, void 0); _Upstream_persist.set(this, void 0); _Upstream_flushPolicy.set(this, void 0); _Upstream_closeTimeout.set(this, void 0); _Upstream_closeSession.set(this, void 0); _Upstream_event.set(this, void 0); _Upstream_totalDataPoints.set(this, void 0); _Upstream_resolver.set(this, void 0); _Upstream_sendBuffer.set(this, void 0); _Upstream_lock.set(this, void 0); _Upstream_aliasMap.set(this, void 0); _Upstream_sequenceNumber.set(this, void 0); _Upstream_requester.set(this, void 0); _Upstream_sender.set(this, void 0); _Upstream_streamReader.set(this, void 0); _Upstream_abortController.set(this, void 0); __classPrivateFieldSet(this, _Upstream_logger, config.logger, "f"); __classPrivateFieldSet(this, _Upstream_id, config.id, "f"); __classPrivateFieldSet(this, _Upstream_idAlias, config.idAlias, "f"); __classPrivateFieldSet(this, _Upstream_serverTime, config.serverTime, "f"); __classPrivateFieldSet(this, _Upstream_sessionId, config.sessionId, "f"); __classPrivateFieldSet(this, _Upstream_ackInterval, config.ackInterval, "f"); __classPrivateFieldSet(this, _Upstream_expiryInterval, config.expiryInterval, "f"); __classPrivateFieldSet(this, _Upstream_qos, config.qos, "f"); __classPrivateFieldSet(this, _Upstream_persist, config.persist, "f"); __classPrivateFieldSet(this, _Upstream_flushPolicy, config.flushPolicy, "f"); __classPrivateFieldSet(this, _Upstream_closeTimeout, config.closeTimeout, "f"); __classPrivateFieldSet(this, _Upstream_closeSession, config.closeSession, "f"); __classPrivateFieldSet(this, _Upstream_event, { [Upstream.EVENT.BEFORE_SEND_DATA_POINTS]: new typed_event_1.TypedEvent(), [Upstream.EVENT.AFTER_RECEIVE_ACK]: new typed_event_1.TypedEvent(), [Upstream.EVENT.CLOSED]: new typed_event_1.TypedEvent(), }, "f"); __classPrivateFieldSet(this, _Upstream_totalDataPoints, 0n, "f"); __classPrivateFieldSet(this, _Upstream_resolver, { didAllTask: new resolver_1.Resolver(), isDraining: new resolver_1.Resolver(), receivedAllAck: new resolver_1.Resolver(), isClosed: new resolver_1.Resolver(), }, "f"); __classPrivateFieldSet(this, _Upstream_sendBuffer, { dataPointsMap: new Map(), size: 0, condition: new condition_1.Condition(), }, "f"); __classPrivateFieldSet(this, _Upstream_lock, { sendBuffer: new await_lock_1.default(), flush: new await_lock_1.default(), }, "f"); __classPrivateFieldSet(this, _Upstream_aliasMap, { dataId: alias_map_1.AliasMap.fromAliases(config.dataIdAliases), }, "f"); __classPrivateFieldSet(this, _Upstream_sequenceNumber, { sequence: sequence_1.Sequence.forSequenceNumber(), final: 0, waitingNumbers: new Set(), }, "f"); __classPrivateFieldSet(this, _Upstream_requester, { resume: config.resumeRequester, close: config.closeRequester, }, "f"); __classPrivateFieldSet(this, _Upstream_sender, { chunk: config.chunkSender, }, "f"); __classPrivateFieldSet(this, _Upstream_streamReader, { chunkAck: config.chunkAckStreamReader, reopen: config.reopenStreamReader, }, "f"); __classPrivateFieldSet(this, _Upstream_abortController, new AbortController(), "f"); } /** * ストリームIDを取得します。 * @returns ストリームID */ get id() { return __classPrivateFieldGet(this, _Upstream_id, "f"); } /** * アップストリームを開いた時のサーバー時刻(ナノ秒)を取得します。 * @returns アップストリームを開いた時のサーバー時刻(ナノ秒) */ get serverTime() { return __classPrivateFieldGet(this, _Upstream_serverTime, "f"); } /** * ストリームの状態を取得します。 * @returns アップストリームの状態 */ get state() { return new model_1.UpstreamState({ dataIdAliases: __classPrivateFieldGet(this, _Upstream_aliasMap, "f").dataId.toAliases(), totalDataPoints: __classPrivateFieldGet(this, _Upstream_totalDataPoints, "f"), lastIssuedSequenceNumber: __classPrivateFieldGet(this, _Upstream_sequenceNumber, "f").sequence.current, dataPointsBuffer: [...__classPrivateFieldGet(this, _Upstream_sendBuffer, "f").dataPointsMap].map(([serializedDataId, dataPoints]) => { return new model_1.DataPointGroup({ dataId: message_1.DataId.parse(serializedDataId), dataPoints: dataPoints.map((dataPoint) => { return new message_1.DataPoint({ elapsedTime: dataPoint.elapsedTime, payload: dataPoint.payload.slice(), }); }), }); }), }); } /** * セッションIDを取得します。 * @returns セッションID */ get sessionId() { return __classPrivateFieldGet(this, _Upstream_sessionId, "f"); } /** * Ackの返却間隔を取得します。 * @returns Ackの返却間隔(秒) */ get ackInterval() { return __classPrivateFieldGet(this, _Upstream_ackInterval, "f"); } /** * 有効期限を取得します。 * @returns ストリームの有効期限(秒) */ get expiryInterval() { return __classPrivateFieldGet(this, _Upstream_expiryInterval, "f"); } /** * QoSを取得します。 * @returns QoS */ get qos() { return __classPrivateFieldGet(this, _Upstream_qos, "f"); } /** * 永続化フラグを取得します。 * @returns 永続化フラグ */ get persist() { return __classPrivateFieldGet(this, _Upstream_persist, "f"); } /** * フラッシュポリシーを取得します。 * @returns フラッシュポリシー */ get flushPolicy() { return __classPrivateFieldGet(this, _Upstream_flushPolicy, "f"); } /** * クローズタイムアウト(秒)を取得します。 * @returns クローズタイムアウト(秒) */ get closeTimeout() { return __classPrivateFieldGet(this, _Upstream_closeTimeout, "f"); } /** * クローズ時にセッションをクローズするかどうかを取得します。 * @returns クローズ時にセッションをクローズするかどうか */ get closeSession() { return __classPrivateFieldGet(this, _Upstream_closeSession, "f"); } /** * @internal */ static async start(config) { const upstream = new Upstream(config); __classPrivateFieldGet(upstream, _Upstream_instances, "m", _Upstream_start).call(upstream); return upstream; } /** * アップストリームを閉じます。 * @param options アップストリームに指定するオプションです。 */ async close(options) { await __classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_close).call(this, { overwriteCloseSession: options?.overwriteCloseSession, }); } /** * アップストリームが閉じるまで待機します。 */ async waitClosed() { await __classPrivateFieldGet(this, _Upstream_resolver, "f").isClosed.wait(); } /** * データポイントの内部バッファをUpstreamChunkとしてサーバーへ送信します。 */ async flush() { await __classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_flush).call(this); } /** * データポイントを送信します。 * @param dataId データID。 * @param dataPoints データポイントのリスト。 */ async writeDataPoints(dataId, dataPoints) { await __classPrivateFieldGet(this, _Upstream_lock, "f").sendBuffer.acquireAsync(); if (__classPrivateFieldGet(this, _Upstream_resolver, "f").isDraining.isDone) { throw new exceptions_1.ISCPTransportClosedError('already closed.'); } // // update sendBuffer // const serializedDataId = dataId.toString(); const sendBuffer = __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").dataPointsMap.get(serializedDataId) ?? []; sendBuffer.push(...dataPoints); __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").dataPointsMap.set(serializedDataId, sendBuffer); // // update sendBufferSize // const dataPointSize = dataPoints.reduce((prev, cur) => prev + cur.payload.byteLength, 0); __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").size += dataPointSize; __classPrivateFieldGet(this, _Upstream_lock, "f").sendBuffer.release(); // // Notify // __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").condition.notify(); } addEventListener(name, listener, options) { if (name in __classPrivateFieldGet(this, _Upstream_event, "f")) { const event = __classPrivateFieldGet(this, _Upstream_event, "f")[name]; options?.once ? event.once(listener) : event.on(listener); return; } throw new exceptions_1.ISCPException('Unrecognized EventName.'); } removeEventListener(name, listener) { if (name in __classPrivateFieldGet(this, _Upstream_event, "f")) { __classPrivateFieldGet(this, _Upstream_event, "f")[name].off(listener); return; } throw new exceptions_1.ISCPException('Unrecognized EventName.'); } } exports.Upstream = Upstream; _Upstream_logger = new WeakMap(), _Upstream_id = new WeakMap(), _Upstream_idAlias = new WeakMap(), _Upstream_serverTime = new WeakMap(), _Upstream_sessionId = new WeakMap(), _Upstream_ackInterval = new WeakMap(), _Upstream_expiryInterval = new WeakMap(), _Upstream_qos = new WeakMap(), _Upstream_persist = new WeakMap(), _Upstream_flushPolicy = new WeakMap(), _Upstream_closeTimeout = new WeakMap(), _Upstream_closeSession = new WeakMap(), _Upstream_event = new WeakMap(), _Upstream_totalDataPoints = new WeakMap(), _Upstream_resolver = new WeakMap(), _Upstream_sendBuffer = new WeakMap(), _Upstream_lock = new WeakMap(), _Upstream_aliasMap = new WeakMap(), _Upstream_sequenceNumber = new WeakMap(), _Upstream_requester = new WeakMap(), _Upstream_sender = new WeakMap(), _Upstream_streamReader = new WeakMap(), _Upstream_abortController = new WeakMap(), _Upstream_instances = new WeakSet(), _Upstream_start = async function _Upstream_start() { Promise.all([__classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_readAckLoop).call(this), __classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_readReopenLoop).call(this), __classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_flushBufferSizeLoop).call(this), __classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_flushIntervalLoop).call(this)]) .catch((error) => { const overwriteError = error instanceof Error ? error : new Error(String(error)); __classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_close).call(this, { overwriteError, }); }) .finally(() => { __classPrivateFieldGet(this, _Upstream_resolver, "f").didAllTask.resolve(); }); }, _Upstream_readAckLoop = async function _Upstream_readAckLoop() { __classPrivateFieldGet(this, _Upstream_abortController, "f").signal.addEventListener('abort', () => { __classPrivateFieldGet(this, _Upstream_sequenceNumber, "f").waitingNumbers.clear(); __classPrivateFieldGet(this, _Upstream_streamReader, "f").chunkAck.cancel(); }); const resolveReceivedAllAckIfComplete = () => { if (__classPrivateFieldGet(this, _Upstream_resolver, "f").isDraining.isDone && __classPrivateFieldGet(this, _Upstream_sequenceNumber, "f").waitingNumbers.size === 0) { __classPrivateFieldGet(this, _Upstream_resolver, "f").receivedAllAck.resolve(); } }; __classPrivateFieldGet(this, _Upstream_resolver, "f").isDraining.wait().then(() => { resolveReceivedAllAckIfComplete(); }); for (;;) { const chunkAckResult = await __classPrivateFieldGet(this, _Upstream_streamReader, "f").chunkAck.read(); if (chunkAckResult.done) { resolveReceivedAllAckIfComplete(); break; } const chunkAck = chunkAckResult.value; for (const [maybeDataIdAlias, dataId] of Object.entries(chunkAck.dataIdAliases)) { __classPrivateFieldGet(this, _Upstream_aliasMap, "f").dataId.set(Number(maybeDataIdAlias), dataId); } const afterReceiveAckEvent = new UpstreamAfterReceiveAckEvent({ streamId: __classPrivateFieldGet(this, _Upstream_id, "f"), chunkAck: new model_1.UpstreamChunkAck({ results: chunkAck.results.map((result) => { return new model_1.UpstreamChunkResult({ sequenceNumber: result.sequenceNumber, resultCode: result.resultCode, resultString: result.resultString, }); }), }), }); __classPrivateFieldGet(this, _Upstream_event, "f")[Upstream.EVENT.AFTER_RECEIVE_ACK].emit(afterReceiveAckEvent); for (const { sequenceNumber } of chunkAck.results) { __classPrivateFieldGet(this, _Upstream_sequenceNumber, "f").waitingNumbers.delete(sequenceNumber); } resolveReceivedAllAckIfComplete(); } }, _Upstream_readReopenLoop = async function _Upstream_readReopenLoop() { const reopenIterator = new stream_reader_iterator_1.StreamReaderIterator(__classPrivateFieldGet(this, _Upstream_streamReader, "f").reopen); __classPrivateFieldGet(this, _Upstream_abortController, "f").signal.addEventListener('abort', () => { reopenIterator.cancel(); }); // eslint-disable-next-line @typescript-eslint/no-unused-vars for await (const _ of reopenIterator) { const response = await __classPrivateFieldGet(this, _Upstream_requester, "f").resume(new message_1.UpstreamResumeRequest({ requestId: 0, streamId: __classPrivateFieldGet(this, _Upstream_id, "f"), extensionFields: new message_1.UpstreamResumeRequestExtensionFields(), })); if (response.resultCode !== message_1.RESULT_CODE.SUCCEEDED) { throw new exceptions_1.ISCPFailedMessageError(response); } } }, _Upstream_flushBufferSizeLoop = async function _Upstream_flushBufferSizeLoop() { for (;;) { // @memo wait の promise を先に取得しておき、loopの最後にawaitで評価する const sendBufferConditionWait = __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").condition.wait(); if (__classPrivateFieldGet(this, _Upstream_abortController, "f").signal.aborted) { break; } if (__classPrivateFieldGet(this, _Upstream_resolver, "f").isDraining.isDone) { break; } const isFlush = flush_policy_1.FlushPolicyHelper.isFlush(__classPrivateFieldGet(this, _Upstream_flushPolicy, "f"), __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").size); if (isFlush) { await __classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_flush).call(this); } await sendBufferConditionWait; } }, _Upstream_flushIntervalLoop = async function _Upstream_flushIntervalLoop() { const ticker = flush_policy_1.FlushPolicyHelper.ticker(__classPrivateFieldGet(this, _Upstream_flushPolicy, "f"), __classPrivateFieldGet(this, _Upstream_abortController, "f").signal); if (!ticker) { return; } // eslint-disable-next-line @typescript-eslint/no-unused-vars for await (const _ of ticker) { // @memo wait の promise を先に取得しておき、loopの最後にawaitで評価する const sendBufferConditionWait = __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").condition.wait(); if (__classPrivateFieldGet(this, _Upstream_abortController, "f").signal.aborted) { break; } if (__classPrivateFieldGet(this, _Upstream_resolver, "f").isDraining.isDone) { break; } await __classPrivateFieldGet(this, _Upstream_instances, "m", _Upstream_flush).call(this); await sendBufferConditionWait; } }, _Upstream_flush = async function _Upstream_flush() { const dataIds = []; const dataPointGroups = []; const modelDataPointGroups = []; try { await __classPrivateFieldGet(this, _Upstream_lock, "f").flush.acquireAsync(); await __classPrivateFieldGet(this, _Upstream_lock, "f").sendBuffer.acquireAsync(); if (__classPrivateFieldGet(this, _Upstream_sendBuffer, "f").dataPointsMap.size === 0) { return; } for (const [serializedDataId, dataPoints] of __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").dataPointsMap.entries()) { const dataId = message_1.DataId.parse(serializedDataId); modelDataPointGroups.push(new model_1.DataPointGroup({ dataId, dataPoints })); __classPrivateFieldSet(this, _Upstream_totalDataPoints, __classPrivateFieldGet(this, _Upstream_totalDataPoints, "f") + BigInt(dataPoints.length), "f"); if (__classPrivateFieldGet(this, _Upstream_totalDataPoints, "f") > constant_1.MAX_UINT64) { throw new exceptions_1.ISCPException('maximum total_data_points exceeded.'); } const dataIdAlias = __classPrivateFieldGet(this, _Upstream_aliasMap, "f").dataId.findAlias(dataId); if (typeof dataIdAlias === 'undefined') { dataIds.push(dataId); dataPointGroups.push(new message_1.DataPointGroup({ dataIdOrAlias: dataId, dataPoints })); continue; } dataPointGroups.push(new message_1.DataPointGroup({ dataIdOrAlias: dataIdAlias, dataPoints })); } const sequenceNumber = __classPrivateFieldGet(this, _Upstream_sequenceNumber, "f").sequence.next(); const chunk = new message_1.UpstreamChunk({ streamIdAlias: __classPrivateFieldGet(this, _Upstream_idAlias, "f"), streamChunk: new message_1.StreamChunk({ sequenceNumber, dataPointGroups, }), dataIds, extensionFields: new message_1.UpstreamChunkExtensionFields(), }); __classPrivateFieldGet(this, _Upstream_sequenceNumber, "f").final = sequenceNumber; __classPrivateFieldGet(this, _Upstream_sequenceNumber, "f").waitingNumbers.add(sequenceNumber); const beforeSendDataPointsEvent = new UpstreamBeforeSendDataPointsEvent({ streamId: __classPrivateFieldGet(this, _Upstream_id, "f"), chunk: new model_1.UpstreamChunk({ sequenceNumber, dataPointGroups: modelDataPointGroups, }), }); __classPrivateFieldGet(this, _Upstream_event, "f")[Upstream.EVENT.BEFORE_SEND_DATA_POINTS].emit(beforeSendDataPointsEvent); await __classPrivateFieldGet(this, _Upstream_sender, "f").chunk(chunk); __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").dataPointsMap.clear(); __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").size = 0; } finally { __classPrivateFieldGet(this, _Upstream_lock, "f").flush.release(); __classPrivateFieldGet(this, _Upstream_lock, "f").sendBuffer.release(); } }, _Upstream_close = async function _Upstream_close(config) { const { overwriteError, overwriteCloseSession } = config; let finalError = overwriteError; if (__classPrivateFieldGet(this, _Upstream_resolver, "f").isClosed.isDone) { return; } if (__classPrivateFieldGet(this, _Upstream_resolver, "f").isDraining.isDone) { throw new exceptions_1.ISCPException('already draining.'); } __classPrivateFieldGet(this, _Upstream_resolver, "f").isDraining.resolve(); try { __classPrivateFieldGet(this, _Upstream_sendBuffer, "f").condition.notify(); const receivedAllAckTimeout = new timeout_1.Timeout(); const waitingSendBufferResult = await Promise.race([ __classPrivateFieldGet(this, _Upstream_resolver, "f").receivedAllAck.wait(), receivedAllAckTimeout.run(new exceptions_1.ISCPTimeoutError(), __classPrivateFieldGet(this, _Upstream_closeTimeout, "f") * 1e3), ]).finally(() => { receivedAllAckTimeout.cancel(); }); if (waitingSendBufferResult instanceof exceptions_1.ISCPTimeoutError) { __classPrivateFieldGet(this, _Upstream_logger, "f").warn(constant_1.LOGGER_TAG.UPSTREAM, waitingSendBufferResult); } __classPrivateFieldGet(this, _Upstream_abortController, "f").abort(); await __classPrivateFieldGet(this, _Upstream_resolver, "f").didAllTask.wait(); } catch (error) { __classPrivateFieldGet(this, _Upstream_logger, "f").warn(constant_1.LOGGER_TAG.UPSTREAM, error); if (typeof finalError === 'undefined') { finalError = error instanceof Error ? error : new Error(String(error)); } } try { const response = await __classPrivateFieldGet(this, _Upstream_requester, "f").close(new message_1.UpstreamCloseRequest({ requestId: 0, streamId: __classPrivateFieldGet(this, _Upstream_id, "f"), totalDataPoints: __classPrivateFieldGet(this, _Upstream_totalDataPoints, "f"), finalSequenceNumber: __classPrivateFieldGet(this, _Upstream_sequenceNumber, "f").final, extensionFields: new message_1.UpstreamCloseRequestExtensionFields({ closeSession: overwriteCloseSession ?? __classPrivateFieldGet(this, _Upstream_closeSession, "f"), }), })); if (response.resultCode !== message_1.RESULT_CODE.SUCCEEDED) { __classPrivateFieldGet(this, _Upstream_logger, "f").error(constant_1.LOGGER_TAG.UPSTREAM, `Failed to close a upstream. streamId ${__classPrivateFieldGet(this, _Upstream_id, "f")} msg=${response.resultString}`); } } finally { __classPrivateFieldGet(this, _Upstream_resolver, "f").isClosed.resolve(); const closedEvent = new UpstreamClosedEvent({ state: this.state, error: finalError }); __classPrivateFieldGet(this, _Upstream_event, "f")[Upstream.EVENT.CLOSED].emit(closedEvent); } try { ; [...Object.values(__classPrivateFieldGet(this, _Upstream_event, "f"))].forEach((event) => event.dispose()); } catch (error) { __classPrivateFieldGet(this, _Upstream_logger, "f").warn(constant_1.LOGGER_TAG.UPSTREAM, `Failed to close a upstream dispose. streamId ${__classPrivateFieldGet(this, _Upstream_id, "f")}`); } }; Upstream.EVENT = { /** データポイントを送信する直前に呼び出されるイベントです。 */ BEFORE_SEND_DATA_POINTS: 'beforeSendDataPoints', /** アップストリームチャンクに対する確認応答を受信した時に呼び出されるイベントです。 */ AFTER_RECEIVE_ACK: 'afterReceiveAck', /** アップストリームチャンクに対する確認応答を受信した時に呼び出されるイベントです。 */ CLOSED: 'closed', }; //# sourceMappingURL=upstream.js.map