the-forest/client/node_modules/.cache/babel-loader/4b433353012331ad77a77acc8acf0f42d1d38086cfaad6957f9d52ad53ef771b.json

1 line
7.6 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"import { ClientError, ClosedError } from \"../errors.js\";\nimport { Cursor } from \"../cursor.js\";\nimport { Queue } from \"../queue.js\";\nconst fetchChunkSize = 1000;\nconst fetchQueueSize = 10;\nexport class WsCursor extends 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();\n this.#fetchQueue = new 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 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 ClientError(\"Cursor was manually closed\"));\n }\n /** True if the cursor is closed. */\n get closed() {\n return this.#closed !== undefined;\n }\n}","map":{"version":3,"names":["ClientError","ClosedError","Cursor","Queue","fetchChunkSize","fetchQueueSize","WsCursor","client","stream","cursorId","entryQueue","fetchQueue","closed","done","constructor","undefined","next","length","push","fetch","entry","shift","then","response","entries","#fetch","_sendCursorRequest","type","maxCount","resp","error","_setClosed","catch","_cursorClosed","close"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-esm/ws/cursor.js"],"sourcesContent":["import { ClientError, ClosedError } from \"../errors.js\";\nimport { Cursor } from \"../cursor.js\";\nimport { Queue } from \"../queue.js\";\nconst fetchChunkSize = 1000;\nconst fetchQueueSize = 10;\nexport class WsCursor extends 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();\n this.#fetchQueue = new 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 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