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

1 line
8.7 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"import { LibsqlUrlParseError } from \"./errors.js\";\n;\n/** Parses a URL compatible with the libsql client (`@libsql/client`). This URL may have the \"libsql:\" scheme\n * and may contain query parameters. */\nexport function parseLibsqlUrl(urlStr) {\n const url = new URL(urlStr);\n let authToken = undefined;\n let tls = undefined;\n for (const [key, value] of url.searchParams.entries()) {\n if (key === \"authToken\") {\n authToken = value;\n } else if (key === \"tls\") {\n if (value === \"0\") {\n tls = false;\n } else if (value === \"1\") {\n tls = true;\n } else {\n throw new LibsqlUrlParseError(`Unknown value for the \"tls\" query argument: ${JSON.stringify(value)}`);\n }\n } else {\n throw new LibsqlUrlParseError(`Unknown URL query argument ${JSON.stringify(key)}`);\n }\n }\n let hranaWsScheme;\n let hranaHttpScheme;\n if ((url.protocol === \"http:\" || url.protocol === \"ws:\") && tls === true) {\n throw new LibsqlUrlParseError(`A ${JSON.stringify(url.protocol)} URL cannot opt into TLS using ?tls=1`);\n } else if ((url.protocol === \"https:\" || url.protocol === \"wss:\") && tls === false) {\n throw new LibsqlUrlParseError(`A ${JSON.stringify(url.protocol)} URL cannot opt out of TLS using ?tls=0`);\n }\n if (url.protocol === \"http:\" || url.protocol === \"https:\") {\n hranaHttpScheme = url.protocol;\n } else if (url.protocol === \"ws:\" || url.protocol === \"wss:\") {\n hranaWsScheme = url.protocol;\n } else if (url.protocol === \"libsql:\") {\n if (tls === false) {\n if (!url.port) {\n throw new LibsqlUrlParseError(`A \"libsql:\" URL with ?tls=0 must specify an explicit port`);\n }\n hranaHttpScheme = \"http:\";\n hranaWsScheme = \"ws:\";\n } else {\n hranaHttpScheme = \"https:\";\n hranaWsScheme = \"wss:\";\n }\n } else {\n throw new LibsqlUrlParseError(`This client does not support ${JSON.stringify(url.protocol)} URLs. ` + 'Please use a \"libsql:\", \"ws:\", \"wss:\", \"http:\" or \"https:\" URL instead.');\n }\n if (url.username || url.password) {\n throw new LibsqlUrlParseError(\"This client does not support HTTP Basic authentication with a username and password. \" + 'You can authenticate using a token passed in the \"authToken\" URL query parameter.');\n }\n if (url.hash) {\n throw new LibsqlUrlParseError(\"URL fragments are not supported\");\n }\n let hranaPath = url.pathname;\n if (hranaPath === \"/\") {\n hranaPath = \"\";\n }\n const hranaWsUrl = hranaWsScheme !== undefined ? `${hranaWsScheme}//${url.host}${hranaPath}` : undefined;\n const hranaHttpUrl = hranaHttpScheme !== undefined ? `${hranaHttpScheme}//${url.host}${hranaPath}` : undefined;\n return {\n hranaWsUrl,\n hranaHttpUrl,\n authToken\n };\n}","map":{"version":3,"names":["LibsqlUrlParseError","parseLibsqlUrl","urlStr","url","URL","authToken","undefined","tls","key","value","searchParams","entries","JSON","stringify","hranaWsScheme","hranaHttpScheme","protocol","port","username","password","hash","hranaPath","pathname","hranaWsUrl","host","hranaHttpUrl"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-esm/libsql_url.js"],"sourcesContent":["import { LibsqlUrlParseError } from \"./errors.js\";\n;\n/** Parses a URL compatible with the libsql client (`@libsql/client`). This URL may have the \"libsql:\" scheme\n * and may contain query parameters. */\nexport function parseLibsqlUrl(urlStr) {\n const url = new URL(urlStr);\n let authToken = undefined;\n let tls = undefined;\n for (const [key, value] of url.searchParams.entries()) {\n if (key === \"authToken\") {\n authToken = value;\n }\n else if (key === \"tls\") {\n if (value === \"0\") {\n tls = false;\n }\n else if (value === \"1\") {\n tls = true;\n }\n else {\n throw new LibsqlUrlParseError(`Unknown value for the \"tls\" query a