1 line
7.6 KiB
JSON
1 line
7.6 KiB
JSON
{"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 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}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,WAAW,QAAQ,cAAc;AACvD,SAASC,MAAM,QAAQ,cAAc;AACrC,SAASC,KAAK,QAAQ,aAAa;AACnC,MAAMC,cAAc,GAAG,IAAI;AAC3B,MAAMC,cAAc,GAAG,EAAE;AACzB,OAAO,MAAMC,QAAQ,SAASJ,MAAM,CAAC;EACjC,CAACK,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,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,CAACQ,UAAU,GAAG,IAAIR,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,CAACS,MAAM,GAAGG,SAAS;IACxB,IAAI,CAAC,CAACF,IAAI,GAAG,KAAK;EACtB;EACA;EACA,MAAMG,IAAIA,CAAA,EAAG;IACT,SAAS;MACL,IAAI,IAAI,CAAC,CAACJ,MAAM,KAAKG,SAAS,EAAE;QAC5B,MAAM,IAAId,WAAW,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAACW,MAAM,CAAC;MAC3D;MACA,OAAO,CAAC,IAAI,CAAC,CAACC,IAAI,IAAI,IAAI,CAAC,CAACF,UAAU,CAACM,MAAM,GAAGZ,cAAc,EAAE;QAC5D,IAAI,CAAC,CAACM,UAAU,CAACO,IAAI,CAAC,IAAI,CAAC,CAACC,KAAK,CAAC,CAAC,CA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