the-forest/client/node_modules/.cache/babel-loader/567b7a808bbffeeb0370ed80911a945f01944b4242d27f79042e3c39904a180c.json

1 line
30 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.BatchCond = exports.BatchStep = exports.Batch = void 0;\nconst errors_js_1 = require(\"./errors.js\");\nconst result_js_1 = require(\"./result.js\");\nconst stmt_js_1 = require(\"./stmt.js\");\nconst util_js_1 = require(\"./util.js\");\n/** A builder for creating a batch and executing it on the server. */\nclass Batch {\n /** @private */\n _stream;\n #useCursor;\n /** @private */\n _steps;\n #executed;\n /** @private */\n constructor(stream, useCursor) {\n this._stream = stream;\n this.#useCursor = useCursor;\n this._steps = [];\n this.#executed = false;\n }\n /** Return a builder for adding a step to the batch. */\n step() {\n return new BatchStep(this);\n }\n /** Execute the batch. */\n execute() {\n if (this.#executed) {\n throw new errors_js_1.MisuseError(\"This batch has already been executed\");\n }\n this.#executed = true;\n const batch = {\n steps: this._steps.map(step => step.proto)\n };\n if (this.#useCursor) {\n return executeCursor(this._stream, this._steps, batch);\n } else {\n return executeRegular(this._stream, this._steps, batch);\n }\n }\n}\nexports.Batch = Batch;\nfunction executeRegular(stream, steps, batch) {\n return stream._batch(batch).then(result => {\n for (let step = 0; step < steps.length; ++step) {\n const stepResult = result.stepResults.get(step);\n const stepError = result.stepErrors.get(step);\n steps[step].callback(stepResult, stepError);\n }\n });\n}\nasync function executeCursor(stream, steps, batch) {\n const cursor = await stream._openCursor(batch);\n try {\n let nextStep = 0;\n let beginEntry = undefined;\n let rows = [];\n for (;;) {\n const entry = await cursor.next();\n if (entry === undefined) {\n break;\n }\n if (entry.type === \"step_begin\") {\n if (entry.step < nextStep || entry.step >= steps.length) {\n throw new errors_js_1.ProtoError(\"Server produced StepBeginEntry for unexpected step\");\n } else if (beginEntry !== undefined) {\n throw new errors_js_1.ProtoError(\"Server produced StepBeginEntry before terminating previous step\");\n }\n for (let step = nextStep; step < entry.step; ++step) {\n steps[step].callback(undefined, undefined);\n }\n nextStep = entry.step + 1;\n beginEntry = entry;\n rows = [];\n } else if (entry.type === \"step_end\") {\n if (beginEntry === undefined) {\n throw new errors_js_1.ProtoError(\"Server produced StepEndEntry but no step is active\");\n }\n const stmtResult = {\n cols: beginEntry.cols,\n rows,\n affectedRowCount: entry.affectedRowCount,\n lastInsertRowid: entry.lastInsertRowid\n };\n steps[beginEntry.step].callback(stmtResult, undefined);\n beginEntry = undefined;\n rows = [];\n } else if (entry.type === \"step_error\") {\n if (beginEntry === undefined) {\n if (entry.step >= steps.length) {\n throw new errors_js_1.ProtoError(\"Server produced StepErrorEntry for unexpected step\");\n }\n for (let step = nextStep; step < entry.step; ++step) {\n steps[step].callback(undefined, undefined);\n }\n } else {\n if (entry.step !== beginEntry.step) {\n throw new errors_js_1.ProtoError(\"Server produced StepErrorEntry for unexpected step\");\n }\n beginEntry = undefined;\n rows = [];\n }\n steps[entry.step].callback(undefined, entry.error);\n nextStep = entry.step + 1;\n } else if (entry.type === \"row\") {\n if (beginEntry === undefined) {\n throw new errors_js_1.ProtoError(\"Server produced RowEntry but no step is active\");\n }\n rows.push(entry.row);\n } else if (entry.type === \"error\") {\n throw (0, result_js_1.errorFromProt