1 line
42 KiB
JSON
1 line
42 KiB
JSON
|
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.HttpStream = void 0;\nconst isomorphic_fetch_1 = require(\"@libsql/isomorphic-fetch\");\nconst errors_js_1 = require(\"../errors.js\");\nconst index_js_1 = require(\"../encoding/index.js\");\nconst id_alloc_js_1 = require(\"../id_alloc.js\");\nconst queue_js_1 = require(\"../queue.js\");\nconst queue_microtask_js_1 = require(\"../queue_microtask.js\");\nconst result_js_1 = require(\"../result.js\");\nconst sql_js_1 = require(\"../sql.js\");\nconst stream_js_1 = require(\"../stream.js\");\nconst util_js_1 = require(\"../util.js\");\nconst cursor_js_1 = require(\"./cursor.js\");\nconst json_encode_js_1 = require(\"./json_encode.js\");\nconst protobuf_encode_js_1 = require(\"./protobuf_encode.js\");\nconst json_encode_js_2 = require(\"./json_encode.js\");\nconst protobuf_encode_js_2 = require(\"./protobuf_encode.js\");\nconst json_decode_js_1 = require(\"./json_decode.js\");\nconst protobuf_decode_js_1 = require(\"./protobuf_decode.js\");\nclass HttpStream extends stream_js_1.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_js_1.Queue();\n this.#flushing = false;\n this.#closing = false;\n this.#closeQueued = false;\n this.#closed = undefined;\n this.#sqlIdAlloc = new id_alloc_js_1.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_js_1.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) {\n return new Promise((cursorCallback, errorCallback) => {\n this.#p
|