1 line
8.5 KiB
JSON
1 line
8.5 KiB
JSON
|
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.valueFromProto = exports.valueToProto = void 0;\nconst errors_js_1 = require(\"./errors.js\");\nconst util_js_1 = require(\"./util.js\");\nfunction 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}\nexports.valueToProto = valueToProto;\nconst minInteger = -9223372036854775808n;\nconst maxInteger = 9223372036854775807n;\nfunction 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 errors_js_1.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 errors_js_1.ProtoError(\"Received unrecognized type of Value\");\n } else {\n throw (0, util_js_1.impossible)(value, \"Impossible type of Value\");\n }\n}\nexports.valueFromProto = valueFromProto;","map":{"version":3,"names":["Object","defineProperty","exports","value","valueFromProto","valueToProto","errors_js_1","require","util_js_1","Number","isFinite","RangeError","minInteger","maxInteger","ArrayBuffer","Uint8Array","Date","valueOf","toString","TypeError","intMode","num","isSafeInteger","MisuseError","slice","buffer","undefined","ProtoError","impossible"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-cjs/value.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.valueFromProto = exports.valueToProto = void 0;\nconst errors_js_1 = require(\"./errors.js\");\nconst util_js_1 = require(\"./util.js\");\nfunction 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
|