1 line
41 KiB
JSON
1 line
41 KiB
JSON
|
{"ast":null,"code":"\"use strict\";\n\nvar __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = {\n enumerable: true,\n get: function () {\n return m[k];\n }\n };\n }\n Object.defineProperty(o, k2, desc);\n} : function (o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\nvar __exportStar = this && this.__exportStar || function (m, exports) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);\n};\nvar __importDefault = this && this.__importDefault || function (mod) {\n return mod && mod.__esModule ? mod : {\n \"default\": mod\n };\n};\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.Sqlite3Transaction = exports.Sqlite3Client = exports._createClient = exports.createClient = void 0;\nconst libsql_1 = __importDefault(require(\"libsql\"));\nconst node_buffer_1 = require(\"node:buffer\");\nconst api_1 = require(\"@libsql/core/api\");\nconst config_1 = require(\"@libsql/core/config\");\nconst util_1 = require(\"@libsql/core/util\");\n__exportStar(require(\"@libsql/core/api\"), exports);\nfunction createClient(config) {\n return _createClient((0, config_1.expandConfig)(config, true));\n}\nexports.createClient = createClient;\n/** @private */\nfunction _createClient(config) {\n if (config.scheme !== \"file\") {\n throw new api_1.LibsqlError(`URL scheme ${JSON.stringify(config.scheme + \":\")} is not supported by the local sqlite3 client. ` + `For more information, please read ${util_1.supportedUrlLink}`, \"URL_SCHEME_NOT_SUPPORTED\");\n }\n const authority = config.authority;\n if (authority !== undefined) {\n const host = authority.host.toLowerCase();\n if (host !== \"\" && host !== \"localhost\") {\n throw new api_1.LibsqlError(`Invalid host in file URL: ${JSON.stringify(authority.host)}. ` + 'A \"file:\" URL with an absolute path should start with one slash (\"file:/absolute/path.db\") ' + 'or with three slashes (\"file:///absolute/path.db\"). ' + `For more information, please read ${util_1.supportedUrlLink}`, \"URL_INVALID\");\n }\n if (authority.port !== undefined) {\n throw new api_1.LibsqlError(\"File URL cannot have a port\", \"URL_INVALID\");\n }\n if (authority.userinfo !== undefined) {\n throw new api_1.LibsqlError(\"File URL cannot have username and password\", \"URL_INVALID\");\n }\n }\n let isInMemory = (0, config_1.isInMemoryConfig)(config);\n if (isInMemory && config.syncUrl) {\n throw new api_1.LibsqlError(`Embedded replica must use file for local db but URI with in-memory mode were provided instead: ${config.path}`, \"URL_INVALID\");\n }\n let path = config.path;\n if (isInMemory) {\n // note: we should prepend file scheme in order for SQLite3 to recognize :memory: connection query parameters\n path = `${config.scheme}:${config.path}`;\n }\n const options = {\n authToken: config.authToken,\n encryptionKey: config.encryptionKey,\n syncUrl: config.syncUrl,\n syncPeriod: config.syncInterval\n };\n const db = new libsql_1.default(path, options);\n executeStmt(db, \"SELECT 1 AS checkThatTheDatabaseCanBeOpened\", config.intMode);\n return new Sqlite3Client(path, options, db, config.intMode);\n}\nexports._createClient = _createClient;\nclass Sqlite3Client {\n #path;\n #options;\n #db;\n #intMode;\n closed;\n protocol;\n /** @private */\n constructor(path, options, db, intMode) {\n this.#path = path;\n this.#options = options;\n this.#db = db;\n this.#intMode = intMode;\n this.closed = false;\n this.protocol = \"file\";\n }\n async execute(stmtOrSql, args) {\n let stmt;\n if (typeof stmtOrSql === \"string\") {\n stmt = {\n sql: stmtOrSql,\n args: args || []\n };\n } else {\n stmt = stmtOrSql;\n }\n
|