1 line
8.3 KiB
JSON
1 line
8.3 KiB
JSON
|
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.WsCursor = void 0;\nconst errors_js_1 = require(\"../errors.js\");\nconst cursor_js_1 = require(\"../cursor.js\");\nconst queue_js_1 = require(\"../queue.js\");\nconst fetchChunkSize = 1000;\nconst fetchQueueSize = 10;\nclass WsCursor extends cursor_js_1.Cursor {\n #client;\n #stream;\n #cursorId;\n #entryQueue;\n #fetchQueue;\n #closed;\n #done;\n /** @private */\n constructor(client, stream, cursorId) {\n super();\n this.#client = client;\n this.#stream = stream;\n this.#cursorId = cursorId;\n this.#entryQueue = new queue_js_1.Queue();\n this.#fetchQueue = new queue_js_1.Queue();\n this.#closed = undefined;\n this.#done = false;\n }\n /** Fetch the next entry from the cursor. */\n async next() {\n for (;;) {\n if (this.#closed !== undefined) {\n throw new errors_js_1.ClosedError(\"Cursor is closed\", this.#closed);\n }\n while (!this.#done && this.#fetchQueue.length < fetchQueueSize) {\n this.#fetchQueue.push(this.#fetch());\n }\n const entry = this.#entryQueue.shift();\n if (this.#done || entry !== undefined) {\n return entry;\n }\n // we assume that `Cursor.next()` is never called concurrently\n await this.#fetchQueue.shift().then(response => {\n if (response === undefined) {\n return;\n }\n for (const entry of response.entries) {\n this.#entryQueue.push(entry);\n }\n this.#done ||= response.done;\n });\n }\n }\n #fetch() {\n return this.#stream._sendCursorRequest(this, {\n type: \"fetch_cursor\",\n cursorId: this.#cursorId,\n maxCount: fetchChunkSize\n }).then(resp => resp, error => {\n this._setClosed(error);\n return undefined;\n });\n }\n /** @private */\n _setClosed(error) {\n if (this.#closed !== undefined) {\n return;\n }\n this.#closed = error;\n this.#stream._sendCursorRequest(this, {\n type: \"close_cursor\",\n cursorId: this.#cursorId\n }).catch(() => undefined);\n this.#stream._cursorClosed(this);\n }\n /** Close the cursor. */\n close() {\n this._setClosed(new errors_js_1.ClientError(\"Cursor was manually closed\"));\n }\n /** True if the cursor is closed. */\n get closed() {\n return this.#closed !== undefined;\n }\n}\nexports.WsCursor = WsCursor;","map":{"version":3,"names":["Object","defineProperty","exports","value","WsCursor","errors_js_1","require","cursor_js_1","queue_js_1","fetchChunkSize","fetchQueueSize","Cursor","client","stream","cursorId","entryQueue","fetchQueue","closed","done","constructor","Queue","undefined","next","ClosedError","length","push","fetch","entry","shift","then","response","entries","#fetch","_sendCursorRequest","type","maxCount","resp","error","_setClosed","catch","_cursorClosed","close","ClientError"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-cjs/ws/cursor.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.WsCursor = void 0;\nconst errors_js_1 = require(\"../errors.js\");\nconst cursor_js_1 = require(\"../cursor.js\");\nconst queue_js_1 = require(\"../queue.js\");\nconst fetchChunkSize = 1000;\nconst fetchQueueSize = 10;\nclass WsCursor extends cursor_js_1.Cursor {\n #client;\n #stream;\n #cursorId;\n #entryQueue;\n #fetchQueue;\n #closed;\n #done;\n /** @private */\n constructor(client, stream, cursorId) {\n super();\n this.#client = client;\n this.#stream = stream;\n this.#cursorId = cursorId;\n this.#entryQueue = new queue_js_1.Queue();\n this.#fetchQueue = new queue_js_1.Queue();\n this.#closed = undefined;\n this.#done = false;\n }\n /** Fetch the next entry from the cursor. */\n async next() {\n for (;;) {\n if (this.#closed !== undefined) {\n throw new errors_js_1.ClosedError
|