the-forest/client/node_modules/.cache/babel-loader/033b1a3d7b441d737172487cea6ef085adc9b972e52a4b9393a39146f63a5596.json

1 line
22 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.WsStream = void 0;\nconst errors_js_1 = require(\"../errors.js\");\nconst queue_js_1 = require(\"../queue.js\");\nconst stream_js_1 = require(\"../stream.js\");\nconst cursor_js_1 = require(\"./cursor.js\");\nclass WsStream extends stream_js_1.Stream {\n #client;\n #streamId;\n #queue;\n #cursor;\n #closing;\n #closed;\n /** @private */\n static open(client) {\n const streamId = client._streamIdAlloc.alloc();\n const stream = new WsStream(client, streamId);\n const responseCallback = () => undefined;\n const errorCallback = e => stream.#setClosed(e);\n const request = {\n type: \"open_stream\",\n streamId\n };\n client._sendRequest(request, {\n responseCallback,\n errorCallback\n });\n return stream;\n }\n /** @private */\n constructor(client, streamId) {\n super(client.intMode);\n this.#client = client;\n this.#streamId = streamId;\n this.#queue = new queue_js_1.Queue();\n this.#cursor = undefined;\n this.#closing = false;\n this.#closed = undefined;\n }\n /** Get the {@link WsClient} object that this stream belongs to. */\n client() {\n return this.#client;\n }\n /** @private */\n _sqlOwner() {\n return this.#client;\n }\n /** @private */\n _execute(stmt) {\n return this.#sendStreamRequest({\n type: \"execute\",\n streamId: this.#streamId,\n stmt\n }).then(response => {\n return response.result;\n });\n }\n /** @private */\n _batch(batch) {\n return this.#sendStreamRequest({\n type: \"batch\",\n streamId: this.#streamId,\n batch\n }).then(response => {\n return response.result;\n });\n }\n /** @private */\n _describe(protoSql) {\n this.#client._ensureVersion(2, \"describe()\");\n return this.#sendStreamRequest({\n type: \"describe\",\n streamId: this.#streamId,\n sql: protoSql.sql,\n sqlId: protoSql.sqlId\n }).then(response => {\n return response.result;\n });\n }\n /** @private */\n _sequence(protoSql) {\n this.#client._ensureVersion(2, \"sequence()\");\n return this.#sendStreamRequest({\n type: \"sequence\",\n streamId: this.#streamId,\n sql: protoSql.sql,\n sqlId: protoSql.sqlId\n }).then(_response => {\n return undefined;\n });\n }\n /** Check whether the SQL connection underlying this stream is in autocommit state (i.e., outside of an\n * explicit transaction). This requires protocol version 3 or higher.\n */\n getAutocommit() {\n this.#client._ensureVersion(3, \"getAutocommit()\");\n return this.#sendStreamRequest({\n type: \"get_autocommit\",\n streamId: this.#streamId\n }).then(response => {\n return response.isAutocommit;\n });\n }\n #sendStreamRequest(request) {\n return new Promise((responseCallback, errorCallback) => {\n this.#pushToQueue({\n type: \"request\",\n request,\n responseCallback,\n errorCallback\n });\n });\n }\n /** @private */\n _openCursor(batch) {\n this.#client._ensureVersion(3, \"cursor\");\n return new Promise((cursorCallback, errorCallback) => {\n this.#pushToQueue({\n type: \"cursor\",\n batch,\n cursorCallback,\n errorCallback\n });\n });\n }\n /** @private */\n _sendCursorRequest(cursor, request) {\n if (cursor !== this.#cursor) {\n throw new errors_js_1.InternalError(\"Cursor not associated with the stream attempted to execute a request\");\n }\n return new Promise((responseCallback, errorCallback) => {\n if (this.#closed !== undefined) {\n errorCallback(new errors_js_1.ClosedError(\"Stream is closed\", this.#closed));\n } else {\n this.#client._sendRequest(request, {\n responseCallback,\n errorCallback\n });\n }\n });\n }\n /** @private */\n _cursorClosed(cursor) {\n if (cursor !== this.#cursor) {\n throw new errors_js_1.Inte