{"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(\"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;\n"],"mappings":"AAAA,YAAY;;AACZA,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,QAAQ,GAAG,KAAK,CAAC;AACzB,MAAMC,WAAW,GAAGC,OAAO,CAAC,cAAc,CAAC;AAC3C,MAAMC,WAAW,GAAGD,OAAO,CAAC,cAAc,CAAC;AAC3C,MAAME,UAAU,GAAGF,OAAO,CAAC,aAAa,CAAC;AACzC,MAAMG,cAAc,GAAG,IAAI;AAC3B,MAAMC,cAAc,GAAG,EAAE;AACzB,MAAMN,QAAQ,SAASG,WAAW,CAACI,MAAM,CAAC;EACtC,CAACC,MAAM;EACP,CAACC,MAAM;EACP,CAACC,QAAQ;EACT,CAACC,UAAU;EACX,CAACC,UAAU;EACX,CAACC,MAAM;EACP,CAACC,IAAI;EACL;EACAC,WAAWA,CAACP,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAE;IAClC,KAAK,CAAC,CAAC;IACP,IAAI,CAAC,CAACF,MAAM,GAAGA,MAAM;IACrB,IAAI,CAAC,CAACC,MAAM,GAAGA,MAAM;IACrB,IAAI,CAAC,CAACC,QAAQ,GAAGA,QAAQ;IACzB,IAAI,CAAC,CAACC,UAAU,GAAG,IAAIP,UAAU,CAACY,KAAK,CAAC,CAAC;IACzC,IAAI,CAAC,CAACJ,UAAU,GAAG,IAAI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