the-forest/client/node_modules/.cache/babel-loader/2d71f1b6fddcf962124ae61e8a1d1eb4d463a40da5e2e5f0b79b7fa4942c52ed.json

1 line
40 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"import { Request, Headers } from \"@libsql/isomorphic-fetch\";\nimport { ClientError, HttpServerError, ProtocolVersionError, ProtoError, ClosedError, InternalError } from \"../errors.js\";\nimport { readJsonObject, writeJsonObject, readProtobufMessage, writeProtobufMessage } from \"../encoding/index.js\";\nimport { IdAlloc } from \"../id_alloc.js\";\nimport { Queue } from \"../queue.js\";\nimport { queueMicrotask } from \"../queue_microtask.js\";\nimport { errorFromProto } from \"../result.js\";\nimport { Sql } from \"../sql.js\";\nimport { Stream } from \"../stream.js\";\nimport { impossible } from \"../util.js\";\nimport { HttpCursor } from \"./cursor.js\";\nimport { PipelineReqBody as json_PipelineReqBody } from \"./json_encode.js\";\nimport { PipelineReqBody as protobuf_PipelineReqBody } from \"./protobuf_encode.js\";\nimport { CursorReqBody as json_CursorReqBody } from \"./json_encode.js\";\nimport { CursorReqBody as protobuf_CursorReqBody } from \"./protobuf_encode.js\";\nimport { PipelineRespBody as json_PipelineRespBody } from \"./json_decode.js\";\nimport { PipelineRespBody as protobuf_PipelineRespBody } from \"./protobuf_decode.js\";\nexport class HttpStream extends Stream {\n #client;\n #baseUrl;\n #jwt;\n #fetch;\n #baton;\n #queue;\n #flushing;\n #cursor;\n #closing;\n #closeQueued;\n #closed;\n #sqlIdAlloc;\n /** @private */\n constructor(client, baseUrl, jwt, customFetch) {\n super(client.intMode);\n this.#client = client;\n this.#baseUrl = baseUrl.toString();\n this.#jwt = jwt;\n this.#fetch = customFetch;\n this.#baton = undefined;\n this.#queue = new Queue();\n this.#flushing = false;\n this.#closing = false;\n this.#closeQueued = false;\n this.#closed = undefined;\n this.#sqlIdAlloc = new IdAlloc();\n }\n /** Get the {@link HttpClient} object that this stream belongs to. */\n client() {\n return this.#client;\n }\n /** @private */\n _sqlOwner() {\n return this;\n }\n /** Cache a SQL text on the server. */\n storeSql(sql) {\n const sqlId = this.#sqlIdAlloc.alloc();\n this.#sendStreamRequest({\n type: \"store_sql\",\n sqlId,\n sql\n }).then(() => undefined, error => this._setClosed(error));\n return new Sql(this, sqlId);\n }\n /** @private */\n _closeSql(sqlId) {\n if (this.#closed !== undefined) {\n return;\n }\n this.#sendStreamRequest({\n type: \"close_sql\",\n sqlId\n }).then(() => this.#sqlIdAlloc.free(sqlId), error => this._setClosed(error));\n }\n /** @private */\n _execute(stmt) {\n return this.#sendStreamRequest({\n type: \"execute\",\n stmt\n }).then(response => {\n return response.result;\n });\n }\n /** @private */\n _batch(batch) {\n return this.#sendStreamRequest({\n type: \"batch\",\n batch\n }).then(response => {\n return response.result;\n });\n }\n /** @private */\n _describe(protoSql) {\n return this.#sendStreamRequest({\n type: \"describe\",\n sql: protoSql.sql,\n sqlId: protoSql.sqlId\n }).then(response => {\n return response.result;\n });\n }\n /** @private */\n _sequence(protoSql) {\n return this.#sendStreamRequest({\n type: \"sequence\",\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 }).then(response => {\n return response.isAutocommit;\n });\n }\n #sendStreamRequest(request) {\n return new Promise((responseCallback, errorCallback) => {\n this.#pushToQueue({\n type: \"pipeline\",\n request,\n responseCallback,\n errorCallback\n });\n });\n }\n /** @private */\n _openCursor(batch) {