the-forest/client/node_modules/.cache/babel-loader/10d46795af572aa2dac2a85e1061d519f86a4cbffe7e2deaaf6fd0732febad08.json

1 line
7.7 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"import { ProtoError, MisuseError } from \"./errors.js\";\nimport { impossible } from \"./util.js\";\nexport function valueToProto(value) {\n if (value === null) {\n return null;\n } else if (typeof value === \"string\") {\n return value;\n } else if (typeof value === \"number\") {\n if (!Number.isFinite(value)) {\n throw new RangeError(\"Only finite numbers (not Infinity or NaN) can be passed as arguments\");\n }\n return value;\n } else if (typeof value === \"bigint\") {\n if (value < minInteger || value > maxInteger) {\n throw new RangeError(\"This bigint value is too large to be represented as a 64-bit integer and passed as argument\");\n }\n return value;\n } else if (typeof value === \"boolean\") {\n return value ? 1n : 0n;\n } else if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n } else if (value instanceof Uint8Array) {\n return value;\n } else if (value instanceof Date) {\n return +value.valueOf();\n } else if (typeof value === \"object\") {\n return \"\" + value.toString();\n } else {\n throw new TypeError(\"Unsupported type of value\");\n }\n}\nconst minInteger = -9223372036854775808n;\nconst maxInteger = 9223372036854775807n;\nexport function valueFromProto(value, intMode) {\n if (value === null) {\n return null;\n } else if (typeof value === \"number\") {\n return value;\n } else if (typeof value === \"string\") {\n return value;\n } else if (typeof value === \"bigint\") {\n if (intMode === \"number\") {\n const num = Number(value);\n if (!Number.isSafeInteger(num)) {\n throw new RangeError(\"Received integer which is too large to be safely represented as a JavaScript number\");\n }\n return num;\n } else if (intMode === \"bigint\") {\n return value;\n } else if (intMode === \"string\") {\n return \"\" + value;\n } else {\n throw new MisuseError(\"Invalid value for IntMode\");\n }\n } else if (value instanceof Uint8Array) {\n // TODO: we need to copy data from `Uint8Array` to return an `ArrayBuffer`. Perhaps we should add a\n // `blobMode` parameter, similar to `intMode`, which would allow the user to choose between receiving\n // `ArrayBuffer` (default, convenient) and `Uint8Array` (zero copy)?\n return value.slice().buffer;\n } else if (value === undefined) {\n throw new ProtoError(\"Received unrecognized type of Value\");\n } else {\n throw impossible(value, \"Impossible type of Value\");\n }\n}","map":{"version":3,"names":["ProtoError","MisuseError","impossible","valueToProto","value","Number","isFinite","RangeError","minInteger","maxInteger","ArrayBuffer","Uint8Array","Date","valueOf","toString","TypeError","valueFromProto","intMode","num","isSafeInteger","slice","buffer","undefined"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-esm/value.js"],"sourcesContent":["import { ProtoError, MisuseError } from \"./errors.js\";\nimport { impossible } from \"./util.js\";\nexport function valueToProto(value) {\n if (value === null) {\n return null;\n }\n else if (typeof value === \"string\") {\n return value;\n }\n else if (typeof value === \"number\") {\n if (!Number.isFinite(value)) {\n throw new RangeError(\"Only finite numbers (not Infinity or NaN) can be passed as arguments\");\n }\n return value;\n }\n else if (typeof value === \"bigint\") {\n if (value < minInteger || value > maxInteger) {\n throw new RangeError(\"This bigint value is too large to be represented as a 64-bit integer and passed as argument\");\n }\n return value;\n }\n else if (typeof value === \"boolean\") {\n return value ? 1n : 0n;\n }\n else if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n }\n else if (value instanceof Uint8Array) {\n return value;\n }\n else if (value instanceof Date) {\n return +value.valueOf();\n }\n else if (type