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

1 line
8.7 KiB
JSON

{"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 argument: ${JSON.stringify(value)}`);\n }\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 }\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 }\n else if (url.protocol === \"ws:\" || url.protocol === \"wss:\") {\n hranaWsScheme = url.protocol;\n }\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 }\n else {\n hranaHttpScheme = \"https:\";\n hranaWsScheme = \"wss:\";\n }\n }\n else {\n throw new LibsqlUrlParseError(`This client does not support ${JSON.stringify(url.protocol)} URLs. ` +\n '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. \" +\n '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\n ? `${hranaWsScheme}//${url.host}${hranaPath}` : undefined;\n const hranaHttpUrl = hranaHttpScheme !== undefined\n ? `${hranaHttpScheme}//${url.host}${hranaPath}` : undefined;\n return { hranaWsUrl, hranaHttpUrl, authToken };\n}\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,aAAa;AACjD;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAACC,MAAM,EAAE;EACnC,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAACF,MAAM,CAAC;EAC3B,IAAIG,SAAS,GAAGC,SAAS;EACzB,IAAIC,GA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