1 line
7.2 KiB
JSON
1 line
7.2 KiB
JSON
|
{"ast":null,"code":"import { Base64 } from \"js-base64\";\nimport { impossible } from \"../util.js\";\nexport function Stmt(w, msg) {\n if (msg.sql !== undefined) {\n w.string(\"sql\", msg.sql);\n }\n if (msg.sqlId !== undefined) {\n w.number(\"sql_id\", msg.sqlId);\n }\n w.arrayObjects(\"args\", msg.args, Value);\n w.arrayObjects(\"named_args\", msg.namedArgs, NamedArg);\n w.boolean(\"want_rows\", msg.wantRows);\n}\nfunction NamedArg(w, msg) {\n w.string(\"name\", msg.name);\n w.object(\"value\", msg.value, Value);\n}\nexport function Batch(w, msg) {\n w.arrayObjects(\"steps\", msg.steps, BatchStep);\n}\nfunction BatchStep(w, msg) {\n if (msg.condition !== undefined) {\n w.object(\"condition\", msg.condition, BatchCond);\n }\n w.object(\"stmt\", msg.stmt, Stmt);\n}\nfunction BatchCond(w, msg) {\n w.stringRaw(\"type\", msg.type);\n if (msg.type === \"ok\" || msg.type === \"error\") {\n w.number(\"step\", msg.step);\n } else if (msg.type === \"not\") {\n w.object(\"cond\", msg.cond, BatchCond);\n } else if (msg.type === \"and\" || msg.type === \"or\") {\n w.arrayObjects(\"conds\", msg.conds, BatchCond);\n } else if (msg.type === \"is_autocommit\") {\n // do nothing\n } else {\n throw impossible(msg, \"Impossible type of BatchCond\");\n }\n}\nfunction Value(w, msg) {\n if (msg === null) {\n w.stringRaw(\"type\", \"null\");\n } else if (typeof msg === \"bigint\") {\n w.stringRaw(\"type\", \"integer\");\n w.stringRaw(\"value\", \"\" + msg);\n } else if (typeof msg === \"number\") {\n w.stringRaw(\"type\", \"float\");\n w.number(\"value\", msg);\n } else if (typeof msg === \"string\") {\n w.stringRaw(\"type\", \"text\");\n w.string(\"value\", msg);\n } else if (msg instanceof Uint8Array) {\n w.stringRaw(\"type\", \"blob\");\n w.stringRaw(\"base64\", Base64.fromUint8Array(msg));\n } else if (msg === undefined) {\n // do nothing\n } else {\n throw impossible(msg, \"Impossible type of Value\");\n }\n}","map":{"version":3,"names":["Base64","impossible","Stmt","w","msg","sql","undefined","string","sqlId","number","arrayObjects","args","Value","namedArgs","NamedArg","boolean","wantRows","name","object","value","Batch","steps","BatchStep","condition","BatchCond","stmt","stringRaw","type","step","cond","conds","Uint8Array","fromUint8Array"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-esm/shared/json_encode.js"],"sourcesContent":["import { Base64 } from \"js-base64\";\nimport { impossible } from \"../util.js\";\nexport function Stmt(w, msg) {\n if (msg.sql !== undefined) {\n w.string(\"sql\", msg.sql);\n }\n if (msg.sqlId !== undefined) {\n w.number(\"sql_id\", msg.sqlId);\n }\n w.arrayObjects(\"args\", msg.args, Value);\n w.arrayObjects(\"named_args\", msg.namedArgs, NamedArg);\n w.boolean(\"want_rows\", msg.wantRows);\n}\nfunction NamedArg(w, msg) {\n w.string(\"name\", msg.name);\n w.object(\"value\", msg.value, Value);\n}\nexport function Batch(w, msg) {\n w.arrayObjects(\"steps\", msg.steps, BatchStep);\n}\nfunction BatchStep(w, msg) {\n if (msg.condition !== undefined) {\n w.object(\"condition\", msg.condition, BatchCond);\n }\n w.object(\"stmt\", msg.stmt, Stmt);\n}\nfunction BatchCond(w, msg) {\n w.stringRaw(\"type\", msg.type);\n if (msg.type === \"ok\" || msg.type === \"error\") {\n w.number(\"step\", msg.step);\n }\n else if (msg.type === \"not\") {\n w.object(\"cond\", msg.cond, BatchCond);\n }\n else if (msg.type === \"and\" || msg.type === \"or\") {\n w.arrayObjects(\"conds\", msg.conds, BatchCond);\n }\n else if (msg.type === \"is_autocommit\") {\n // do nothing\n }\n else {\n throw impossible(msg, \"Impossible type of BatchCond\");\n }\n}\nfunction Value(w, msg) {\n if (msg === null) {\n w.stringRaw(\"type\", \"null\");\n }\n else if (typeof msg === \"bigint\") {\n w.stringRaw(\"type\", \"integer\");\n w.stringRaw(\"value\", \"\" + msg);\n
|