the-forest/client/node_modules/.cache/babel-loader/23c92b682878fd186e19993e826ccfbb9702e1df64e6e28f3f6ac45d3365ab58.json

1 line
15 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.expandConfig = exports.isInMemoryConfig = void 0;\nconst api_js_1 = require(\"./api.js\");\nconst uri_js_1 = require(\"./uri.js\");\nconst util_js_1 = require(\"./util.js\");\nconst inMemoryMode = \":memory:\";\nfunction isInMemoryConfig(config) {\n return config.scheme === \"file\" && (config.path === \":memory:\" || config.path.startsWith(\":memory:?\"));\n}\nexports.isInMemoryConfig = isInMemoryConfig;\nfunction expandConfig(config, preferHttp) {\n if (typeof config !== \"object\") {\n // produce a reasonable error message in the common case where users type\n // `createClient(\"libsql://...\")` instead of `createClient({url: \"libsql://...\"})`\n throw new TypeError(`Expected client configuration as object, got ${typeof config}`);\n }\n let {\n url,\n authToken,\n tls,\n intMode,\n concurrency\n } = config;\n // fill simple defaults right here\n concurrency = Math.max(0, concurrency || 20);\n intMode ??= \"number\";\n let connectionQueryParams = []; // recognized query parameters which we sanitize through white list of valid key-value pairs\n // convert plain :memory: url to URI format to make logic more uniform\n if (url === inMemoryMode) {\n url = \"file::memory:\";\n }\n // parse url parameters first and override config with update values\n const uri = (0, uri_js_1.parseUri)(url);\n const originalUriScheme = uri.scheme.toLowerCase();\n const isInMemoryMode = originalUriScheme === \"file\" && uri.path === inMemoryMode && uri.authority === undefined;\n let queryParamsDef;\n if (isInMemoryMode) {\n queryParamsDef = {\n cache: {\n values: [\"shared\", \"private\"],\n update: (key, value) => connectionQueryParams.push(`${key}=${value}`)\n }\n };\n } else {\n queryParamsDef = {\n tls: {\n values: [\"0\", \"1\"],\n update: (_, value) => tls = value === \"1\"\n },\n authToken: {\n update: (_, value) => authToken = value\n }\n };\n }\n for (const {\n key,\n value\n } of uri.query?.pairs ?? []) {\n if (!Object.hasOwn(queryParamsDef, key)) {\n throw new api_js_1.LibsqlError(`Unsupported URL query parameter ${JSON.stringify(key)}`, \"URL_PARAM_NOT_SUPPORTED\");\n }\n const queryParamDef = queryParamsDef[key];\n if (queryParamDef.values !== undefined && !queryParamDef.values.includes(value)) {\n throw new api_js_1.LibsqlError(`Unknown value for the \"${key}\" query argument: ${JSON.stringify(value)}. Supported values are: [${queryParamDef.values.map(x => '\"' + x + '\"').join(\", \")}]`, \"URL_INVALID\");\n }\n if (queryParamDef.update !== undefined) {\n queryParamDef?.update(key, value);\n }\n }\n // fill complex defaults & validate config\n const connectionQueryParamsString = connectionQueryParams.length === 0 ? \"\" : `?${connectionQueryParams.join(\"&\")}`;\n const path = uri.path + connectionQueryParamsString;\n let scheme;\n if (originalUriScheme === \"libsql\") {\n if (tls === false) {\n if (uri.authority?.port === undefined) {\n throw new api_js_1.LibsqlError('A \"libsql:\" URL with ?tls=0 must specify an explicit port', \"URL_INVALID\");\n }\n scheme = preferHttp ? \"http\" : \"ws\";\n } else {\n scheme = preferHttp ? \"https\" : \"wss\";\n }\n } else {\n scheme = originalUriScheme;\n }\n if (scheme === \"http\" || scheme === \"ws\") {\n tls ??= false;\n } else {\n tls ??= true;\n }\n if (scheme !== \"http\" && scheme !== \"ws\" && scheme !== \"https\" && scheme !== \"wss\" && scheme !== \"file\") {\n throw new api_js_1.LibsqlError('The client supports only \"libsql:\", \"wss:\", \"ws:\", \"https:\", \"http:\" and \"file:\" URLs, ' + `got ${JSON.stringify(uri.scheme + \":\")}. ` + `For more information, please read ${util_js_1.supportedUrlLink}`, \"URL_SCHEME_NOT_SUPPORTED\");\n }\n if (intMode !== \"number\" && intMode !== \"bigint\" && intMode !== \"string\") {\n throw ne