1 line
14 KiB
JSON
1 line
14 KiB
JSON
{"ast":null,"code":"import { LibsqlError } from \"./api.js\";\nimport { parseUri } from \"./uri.js\";\nimport { supportedUrlLink } from \"./util.js\";\nconst inMemoryMode = \":memory:\";\nexport function isInMemoryConfig(config) {\n return config.scheme === \"file\" && (config.path === \":memory:\" || config.path.startsWith(\":memory:?\"));\n}\nexport function 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 = 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 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 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 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 LibsqlError('The client supports only \"libsql:\", \"wss:\", \"ws:\", \"https:\", \"http:\" and \"file:\" URLs, ' + `got ${JSON.stringify(uri.scheme + \":\")}. ` + `For more information, please read ${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 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}","map":{"version":3,"names":["LibsqlError","parseUri","supportedUrlLink","inMemoryMode","isInMemoryConfig","config","scheme","path","startsWith","expandConfig","preferHttp","TypeError","url","authToken","tls","intMode","concurrency","Math","max","connectionQueryParams","uri","originalUriScheme","toLowerCase","isInMemoryMode","authority","undefined","queryParamsDef","cache","values","update","key","value","push","_","query","pairs","Object","hasOwn","JSON","stringify","queryParamDef","includes","map","x","join","connectionQueryParamsString","length","port","fragment","syncUrl","syncInterval","fetch","encryptionKey"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/core/lib-esm/config.js"],"sourcesContent":["import { LibsqlError } from \"./api.js\";\nimport { parseUri } from \"./uri.js\";\nimport { supportedUrlLink } from \"./util.js\";\nconst inMemoryMode = \":memory:\";\nexport function isInMemoryConfig(config) {\n return (config.scheme === \"file\" &&\n (config.path === \":memory:\" || config.path.startsWith(\":memory:?\")));\n}\nexport function 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 = 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 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 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 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 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 ${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 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}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,UAAU;AACtC,SAASC,QAAQ,QAAQ,UAAU;AACnC,SAASC,gBAAgB,QAAQ,WAAW;AAC5C,MAAMC,YAAY,GAAG,UAAU;AAC/B,OAAO,SAASC,gBAAgBA,CAACC,MAAM,EAAE;EACrC,OAAQA,MAAM,CAACC,MAAM,KAAK,MAAM,KAC3BD,MAAM,CAACE,IAAI,KAAK,UAAU,IAAIF,MAAM,CAACE,IAAI,CAACC,UAAU,CAAC,WAAW,CAAC,CAAC;AAC3E;AACA,OAAO,SAASC,YAAYA,CAACJ,MAAM,EAAEK,UAAU,EAAE;EAC7C,IAAI,OAAOL,MAAM,KAAK,QAAQ,EAAE;IAC5B;IACA;IACA,MAAM,IAAIM,SAAS,CAAC,gDAAgD,OAAON,MAAM,EAAE,CAAC;EACxF;EACA,IAAI;IAAEO,GAAG;IAAEC,SAAS;IAAEC,GAAG;IAAEC,OAAO;IAAEC;EAAY,CAAC,GAAGX,MAAM;EAC1D;EACAW,WAAW,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEF,WAAW,IAAI,EAAE,CAAC;EAC5CD,OAAO,KAAK,QAAQ;EACpB,IAAII,qBAAqB,GAAG,EAAE,CAAC,CAAC;EAChC;EACA,IAAIP,GAAG,KAAKT,YAAY,EAAE;IACt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