1 line
19 KiB
JSON
1 line
19 KiB
JSON
|
{"ast":null,"code":"\"use strict\";\n\nvar __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = {\n enumerable: true,\n get: function () {\n return m[k];\n }\n };\n }\n Object.defineProperty(o, k2, desc);\n} : function (o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\nvar __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {\n Object.defineProperty(o, \"default\", {\n enumerable: true,\n value: v\n });\n} : function (o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = this && this.__importStar || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.HttpCursor = void 0;\nconst byte_queue_js_1 = require(\"../byte_queue.js\");\nconst cursor_js_1 = require(\"../cursor.js\");\nconst jsond = __importStar(require(\"../encoding/json/decode.js\"));\nconst protobufd = __importStar(require(\"../encoding/protobuf/decode.js\"));\nconst errors_js_1 = require(\"../errors.js\");\nconst util_js_1 = require(\"../util.js\");\nconst json_decode_js_1 = require(\"./json_decode.js\");\nconst protobuf_decode_js_1 = require(\"./protobuf_decode.js\");\nconst json_decode_js_2 = require(\"../shared/json_decode.js\");\nconst protobuf_decode_js_2 = require(\"../shared/protobuf_decode.js\");\nclass HttpCursor extends cursor_js_1.Cursor {\n #stream;\n #encoding;\n #reader;\n #queue;\n #closed;\n #done;\n /** @private */\n constructor(stream, encoding) {\n super();\n this.#stream = stream;\n this.#encoding = encoding;\n this.#reader = undefined;\n this.#queue = new byte_queue_js_1.ByteQueue(16 * 1024);\n this.#closed = undefined;\n this.#done = false;\n }\n async open(response) {\n if (response.body === null) {\n throw new errors_js_1.ProtoError(\"No response body for cursor request\");\n }\n this.#reader = response.body.getReader();\n const respBody = await this.#nextItem(json_decode_js_1.CursorRespBody, protobuf_decode_js_1.CursorRespBody);\n if (respBody === undefined) {\n throw new errors_js_1.ProtoError(\"Empty response to cursor request\");\n }\n return respBody;\n }\n /** Fetch the next entry from the cursor. */\n next() {\n return this.#nextItem(json_decode_js_2.CursorEntry, protobuf_decode_js_2.CursorEntry);\n }\n /** Close the cursor. */\n close() {\n this._setClosed(new errors_js_1.ClientError(\"Cursor was manually closed\"));\n }\n /** @private */\n _setClosed(error) {\n if (this.#closed !== undefined) {\n return;\n }\n this.#closed = error;\n this.#stream._cursorClosed(this);\n if (this.#reader !== undefined) {\n this.#reader.cancel();\n }\n }\n /** True if the cursor is closed. */\n get closed() {\n return this.#closed !== undefined;\n }\n async #nextItem(jsonFun, protobufDef) {\n for (;;) {\n if (this.#done) {\n return undefined;\n } else if (this.#closed !== undefined) {\n throw new errors_js_1.ClosedError(\"Cursor is closed\", this.#closed);\n }\n if (this.#encoding === \"json\") {\n const jsonData = this.#parseItemJson();\n if (jsonData !== undefined) {\n const jsonText = new TextDecoder().decode(jsonData);\n const jsonValue = JSON.parse(jsonText);\n return jsond.readJsonObject(jsonValue, jsonFun);\n }\n } else if (this.#encoding === \"protobuf\") {\n const protobufData = this.#parseItemProtobuf();\n if (protobufData !== undefined) {\n return protobufd.readProtobufMessage(protobufData, protobuf
|