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

1 line
15 KiB
JSON

{"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 new TypeError(`Invalid value for intMode, expected \"number\", \"bigint\" or \"string\", got ${JSON.stringify(intMode)}`);\n }\n if (uri.fragment !== undefined) {\n throw new api_js_1.LibsqlError(`URL fragments are not supported: ${JSON.stringify(\"#\" + uri.fragment)}`, \"URL_INVALID\");\n }\n if (isInMemoryMode) {\n return {\n scheme: \"file\",\n tls: false,\n path,\n intMode,\n concurrency,\n syncUrl: config.syncUrl,\n syncInterval: config.syncInterval,\n fetch: config.fetch,\n authToken: undefined,\n encryptionKey: undefined,\n authority: undefined\n };\n }\n return {\n scheme,\n tls,\n authority: uri.authority,\n path,\n authToken,\n intMode,\n concurrency,\n encryptionKey: config.encryptionKey,\n syncUrl: config.syncUrl,\n syncInterval: config.syncInterval,\n fetch: config.fetch\n };\n}\nexports.expandConfig = expandConfig;","map":{"version":3,"names":["Object","defineProperty","exports","value","expandConfig","isInMemoryConfig","api_js_1","require","uri_js_1","util_js_1","inMemoryMode","config","scheme","path","startsWith","preferHttp","TypeError","url","authToken","tls","intMode","concurrency","Math","max","connectionQueryParams","uri","parseUri","originalUriScheme","toLowerCase","isInMemoryMode","authority","undefined","queryParamsDef","cache","values","update","key","push","_","query","pairs","hasOwn","LibsqlError","JSON","stringify","queryParamDef","includes","map","x","join","connectionQueryParamsString","length","port","supportedUrlLink","fragment","syncUrl","syncInterval","fetch","encryptionKey"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/core/lib-cjs/config.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\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\" &&\n (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 { url, authToken, tls, intMode, concurrency } = 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\" &&\n uri.path === inMemoryMode &&\n 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 }\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 { key, value } 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 &&\n !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\n ? \"\"\n : `?${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 }\n else {\n scheme = preferHttp ? \"https\" : \"wss\";\n }\n }\n else {\n scheme = originalUriScheme;\n }\n if (scheme === \"http\" || scheme === \"ws\") {\n tls ??= false;\n }\n else {\n tls ??= true;\n }\n if (scheme !== \"http\" &&\n scheme !== \"ws\" &&\n scheme !== \"https\" &&\n scheme !== \"wss\" &&\n scheme !== \"file\") {\n throw new api_js_1.LibsqlError('The client supports only \"libsql:\", \"wss:\", \"ws:\", \"https:\", \"http:\" and \"file:\" URLs, ' +\n `got ${JSON.stringify(uri.scheme + \":\")}. ` +\n `For more information, please read ${util_js_1.supportedUrlLink}`, \"URL_SCHEME_NOT_SUPPORTED\");\n }\n if (intMode !== \"number\" && intMode !== \"bigint\" && intMode !== \"string\") {\n throw new TypeError(`Invalid value for intMode, expected \"number\", \"bigint\" or \"string\", got ${JSON.stringify(intMode)}`);\n }\n if (uri.fragment !== undefined) {\n throw new api_js_1.LibsqlError(`URL fragments are not supported: ${JSON.stringify(\"#\" + uri.fragment)}`, \"URL_INVALID\");\n }\n if (isInMemoryMode) {\n return {\n scheme: \"file\",\n tls: false,\n path,\n intMode,\n concurrency,\n syncUrl: config.syncUrl,\n syncInterval: config.syncInterval,\n fetch: config.fetch,\n authToken: undefined,\n encryptionKey: undefined,\n authority: undefined,\n };\n }\n return {\n scheme,\n tls,\n authority: uri.authority,\n path,\n authToken,\n intMode,\n concurrency,\n encryptionKey: config.encryptionKey,\n syncUrl: config.syncUrl,\n syncInterval: config.syncInterval,\n fetch: config.fetch,\n };\n}\nexports.expandConfig = expandConfig;\n"],"mappings":"AAAA,YAAY;;AACZA,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,YAAY,GAAGF,OAAO,CAACG,gBAAgB,GAAG,KAAK,CAAC;AACxD,MAAMC,QAAQ,GAAGC,OAAO,CAAC,UAAU,CAAC;AACpC,MAAMC,QAAQ,GAAGD,OAAO,CAAC,UAAU,CAAC;AACpC,MAAME,SAAS,GAAGF,OAAO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