the-forest/client/node_modules/.cache/babel-loader/cac9505fc4e3966819140aabe4a3f2fc18bbaf9707fda843757dd7b2737bb805.json

1 line
13 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"import { Base64 } from \"js-base64\";\nimport { ProtoError } from \"../errors.js\";\nimport * as d from \"../encoding/json/decode.js\";\nexport function Error(obj) {\n const message = d.string(obj[\"message\"]);\n const code = d.stringOpt(obj[\"code\"]);\n return {\n message,\n code\n };\n}\nexport function StmtResult(obj) {\n const cols = d.arrayObjectsMap(obj[\"cols\"], Col);\n const rows = d.array(obj[\"rows\"]).map(rowObj => d.arrayObjectsMap(rowObj, Value));\n const affectedRowCount = d.number(obj[\"affected_row_count\"]);\n const lastInsertRowidStr = d.stringOpt(obj[\"last_insert_rowid\"]);\n const lastInsertRowid = lastInsertRowidStr !== undefined ? BigInt(lastInsertRowidStr) : undefined;\n return {\n cols,\n rows,\n affectedRowCount,\n lastInsertRowid\n };\n}\nfunction Col(obj) {\n const name = d.stringOpt(obj[\"name\"]);\n const decltype = d.stringOpt(obj[\"decltype\"]);\n return {\n name,\n decltype\n };\n}\nexport function BatchResult(obj) {\n const stepResults = new Map();\n d.array(obj[\"step_results\"]).forEach((value, i) => {\n if (value !== null) {\n stepResults.set(i, StmtResult(d.object(value)));\n }\n });\n const stepErrors = new Map();\n d.array(obj[\"step_errors\"]).forEach((value, i) => {\n if (value !== null) {\n stepErrors.set(i, Error(d.object(value)));\n }\n });\n return {\n stepResults,\n stepErrors\n };\n}\nexport function CursorEntry(obj) {\n const type = d.string(obj[\"type\"]);\n if (type === \"step_begin\") {\n const step = d.number(obj[\"step\"]);\n const cols = d.arrayObjectsMap(obj[\"cols\"], Col);\n return {\n type: \"step_begin\",\n step,\n cols\n };\n } else if (type === \"step_end\") {\n const affectedRowCount = d.number(obj[\"affected_row_count\"]);\n const lastInsertRowidStr = d.stringOpt(obj[\"last_insert_rowid\"]);\n const lastInsertRowid = lastInsertRowidStr !== undefined ? BigInt(lastInsertRowidStr) : undefined;\n return {\n type: \"step_end\",\n affectedRowCount,\n lastInsertRowid\n };\n } else if (type === \"step_error\") {\n const step = d.number(obj[\"step\"]);\n const error = Error(d.object(obj[\"error\"]));\n return {\n type: \"step_error\",\n step,\n error\n };\n } else if (type === \"row\") {\n const row = d.arrayObjectsMap(obj[\"row\"], Value);\n return {\n type: \"row\",\n row\n };\n } else if (type === \"error\") {\n const error = Error(d.object(obj[\"error\"]));\n return {\n type: \"error\",\n error\n };\n } else {\n throw new ProtoError(\"Unexpected type of CursorEntry\");\n }\n}\nexport function DescribeResult(obj) {\n const params = d.arrayObjectsMap(obj[\"params\"], DescribeParam);\n const cols = d.arrayObjectsMap(obj[\"cols\"], DescribeCol);\n const isExplain = d.boolean(obj[\"is_explain\"]);\n const isReadonly = d.boolean(obj[\"is_readonly\"]);\n return {\n params,\n cols,\n isExplain,\n isReadonly\n };\n}\nfunction DescribeParam(obj) {\n const name = d.stringOpt(obj[\"name\"]);\n return {\n name\n };\n}\nfunction DescribeCol(obj) {\n const name = d.string(obj[\"name\"]);\n const decltype = d.stringOpt(obj[\"decltype\"]);\n return {\n name,\n decltype\n };\n}\nexport function Value(obj) {\n const type = d.string(obj[\"type\"]);\n if (type === \"null\") {\n return null;\n } else if (type === \"integer\") {\n const value = d.string(obj[\"value\"]);\n return BigInt(value);\n } else if (type === \"float\") {\n return d.number(obj[\"value\"]);\n } else if (type === \"text\") {\n return d.string(obj[\"value\"]);\n } else if (type === \"blob\") {\n return Base64.toUint8Array(d.string(obj[\"base64\"]));\n } else {\n throw new ProtoError(\"Unexpected type of Value\");\n }\n}","map":{"version":3,"names":["Base64","ProtoError","d","Error","obj","message","string","code","stringOpt","StmtResult","cols","arrayObjectsMap","Col","rows","array","map","rowObj","Value","affectedRowCount","n