the-forest/client/node_modules/.cache/babel-loader/10d46795af572aa2dac2a85e1061d519f86a4cbffe7e2deaaf6fd0732febad08.json
2024-09-17 20:35:18 -04:00

1 line
7.7 KiB
JSON

{"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 (typeof value === \"object\") {\n return \"\" + value.toString();\n }\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 }\n else if (typeof value === \"number\") {\n return value;\n }\n else if (typeof value === \"string\") {\n return value;\n }\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 }\n else if (intMode === \"bigint\") {\n return value;\n }\n else if (intMode === \"string\") {\n return \"\" + value;\n }\n else {\n throw new MisuseError(\"Invalid value for IntMode\");\n }\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 }\n else if (value === undefined) {\n throw new ProtoError(\"Received unrecognized type of Value\");\n }\n else {\n throw impossible(value, \"Impossible type of Value\");\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,WAAW,QAAQ,aAAa;AACrD,SAASC,UAAU,QAAQ,WAAW;AACtC,OAAO,SAASC,YAAYA,CAACC,KAAK,EAAE;EAChC,IAAIA,KAAK,KAAK,IAAI,EAAE;IAChB,OAAO,IAAI;EACf,CAAC,MACI,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAChC,OAAOA,KAAK;EAChB,CAAC,MACI,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAChC,IAAI,CAACC,MAAM,CAACC,QAAQ,CAACF,KAAK,CAAC,EAAE;MACzB,MAAM,IAAIG,UAAU,CAAC,sEAAsE,CAAC;IAChG;IACA,OAAOH,KAAK;EAChB,CAAC,MACI,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAChC,IAAIA,KAAK,GAAGI,UAAU,IAAIJ,KAAK,GAAGK,UAAU,EAAE;MAC1C,MAAM,IAAIF,UAAU,CAAC,6FAA6F,CAAC;IACvH;IACA,OAAOH,KAAK;EAChB,CAAC,MACI,IAAI,OAAOA,KAAK,KAAK,SAAS,EAAE;IACjC,OAAOA,KAAK,GAAG,EAAE,GAAG,EAAE;EAC1B,CAAC,MACI,IAAIA,KAAK,YAAYM,WAAW,EAAE;IACnC,OAAO,IAAIC,UAAU,CAACP,KAAK,CAAC;EAChC,CAAC,MACI,IAAIA,KAAK,YAAYO,UAAU,EAAE;IAClC,OAAOP,KAAK;EAChB,CAAC,MACI,IAAIA,KAAK,YAAYQ,IAAI,EAAE;IAC5B,OAAO,CAACR,KA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