terradb 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +639 -709
  2. package/package.json +2 -3
package/dist/index.js CHANGED
@@ -22225,7 +22225,7 @@ class SchemaDiffer {
22225
22225
  constraint: primaryKeyChange.desiredPK
22226
22226
  });
22227
22227
  }
22228
- this.collectCheckConstraintAlterations(desiredTable.checkConstraints || [], currentTable.checkConstraints || [], alterations);
22228
+ this.collectCheckConstraintAlterations(desiredTable.name, desiredTable.checkConstraints || [], currentTable.checkConstraints || [], alterations);
22229
22229
  const currentColumns2 = new Set(currentTable.columns.map((c) => c.name));
22230
22230
  const desiredColumns2 = new Set(desiredTable.columns.map((c) => c.name));
22231
22231
  const droppedColumns = new Set([...currentColumns2].filter((col) => !desiredColumns2.has(col)));
@@ -22291,10 +22291,12 @@ class SchemaDiffer {
22291
22291
  }
22292
22292
  }
22293
22293
  }
22294
- collectCheckConstraintAlterations(desiredConstraints, currentConstraints, alterations) {
22294
+ collectCheckConstraintAlterations(tableName, desiredConstraints, currentConstraints, alterations) {
22295
22295
  const findMatchingConstraint = (expr, constraints) => {
22296
22296
  return constraints.find((c) => expressionsEqual(expr, c.expression));
22297
22297
  };
22298
+ const bareTableName = getBareTableName(tableName);
22299
+ const fallbackName = `${bareTableName}_check`;
22298
22300
  const processedCurrentNames = new Set;
22299
22301
  for (const desired of desiredConstraints) {
22300
22302
  const matchingCurrent = findMatchingConstraint(desired.expression, currentConstraints);
@@ -22302,7 +22304,9 @@ class SchemaDiffer {
22302
22304
  if (matchingCurrent.name) {
22303
22305
  processedCurrentNames.add(matchingCurrent.name);
22304
22306
  }
22305
- if (matchingCurrent.name !== desired.name) {
22307
+ const desiredEffectiveName = desired.name || fallbackName;
22308
+ const currentEffectiveName = matchingCurrent.name || fallbackName;
22309
+ if (currentEffectiveName !== desiredEffectiveName) {
22306
22310
  if (matchingCurrent.name) {
22307
22311
  alterations.push({
22308
22312
  type: "drop_check",
@@ -25778,788 +25782,715 @@ var init_postgres = __esm(() => {
25778
25782
  init_errors();
25779
25783
  });
25780
25784
 
25781
- // node_modules/better-sqlite3/lib/util.js
25782
- var require_util = __commonJS((exports) => {
25783
- exports.getBooleanOption = (options, key) => {
25784
- let value = false;
25785
- if (key in options && typeof (value = options[key]) !== "boolean") {
25786
- throw new TypeError(`Expected the "${key}" option to be a boolean`);
25785
+ // node_modules/@neon-rs/load/dist/index.js
25786
+ var require_dist3 = __commonJS((exports) => {
25787
+ var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
25788
+ if (k2 === undefined)
25789
+ k2 = k;
25790
+ var desc = Object.getOwnPropertyDescriptor(m, k);
25791
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
25792
+ desc = { enumerable: true, get: function() {
25793
+ return m[k];
25794
+ } };
25787
25795
  }
25788
- return value;
25796
+ Object.defineProperty(o, k2, desc);
25797
+ } : function(o, m, k, k2) {
25798
+ if (k2 === undefined)
25799
+ k2 = k;
25800
+ o[k2] = m[k];
25801
+ });
25802
+ var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
25803
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25804
+ } : function(o, v) {
25805
+ o["default"] = v;
25806
+ });
25807
+ var __importStar = exports && exports.__importStar || function(mod) {
25808
+ if (mod && mod.__esModule)
25809
+ return mod;
25810
+ var result = {};
25811
+ if (mod != null) {
25812
+ for (var k in mod)
25813
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
25814
+ __createBinding(result, mod, k);
25815
+ }
25816
+ __setModuleDefault(result, mod);
25817
+ return result;
25789
25818
  };
25790
- exports.cppdb = Symbol();
25791
- exports.inspect = Symbol.for("nodejs.util.inspect.custom");
25792
- });
25793
-
25794
- // node_modules/better-sqlite3/lib/sqlite-error.js
25795
- var require_sqlite_error = __commonJS((exports, module) => {
25796
- var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
25797
- function SqliteError(message, code) {
25798
- if (new.target !== SqliteError) {
25799
- return new SqliteError(message, code);
25819
+ Object.defineProperty(exports, "__esModule", { value: true });
25820
+ exports.load = exports.currentTarget = undefined;
25821
+ var path = __importStar(__require("path"));
25822
+ var fs = __importStar(__require("fs"));
25823
+ function currentTarget() {
25824
+ let os3 = null;
25825
+ switch (process.platform) {
25826
+ case "android":
25827
+ switch (process.arch) {
25828
+ case "arm":
25829
+ return "android-arm-eabi";
25830
+ case "arm64":
25831
+ return "android-arm64";
25832
+ }
25833
+ os3 = "Android";
25834
+ break;
25835
+ case "win32":
25836
+ switch (process.arch) {
25837
+ case "x64":
25838
+ return "win32-x64-msvc";
25839
+ case "arm64":
25840
+ return "win32-arm64-msvc";
25841
+ case "ia32":
25842
+ return "win32-ia32-msvc";
25843
+ }
25844
+ os3 = "Windows";
25845
+ break;
25846
+ case "darwin":
25847
+ switch (process.arch) {
25848
+ case "x64":
25849
+ return "darwin-x64";
25850
+ case "arm64":
25851
+ return "darwin-arm64";
25852
+ }
25853
+ os3 = "macOS";
25854
+ break;
25855
+ case "linux":
25856
+ switch (process.arch) {
25857
+ case "x64":
25858
+ case "arm64":
25859
+ return isGlibc() ? `linux-${process.arch}-gnu` : `linux-${process.arch}-musl`;
25860
+ case "arm":
25861
+ return "linux-arm-gnueabihf";
25862
+ }
25863
+ os3 = "Linux";
25864
+ break;
25865
+ case "freebsd":
25866
+ if (process.arch === "x64") {
25867
+ return "freebsd-x64";
25868
+ }
25869
+ os3 = "FreeBSD";
25870
+ break;
25800
25871
  }
25801
- if (typeof code !== "string") {
25802
- throw new TypeError("Expected second argument to be a string");
25872
+ if (os3) {
25873
+ throw new Error(`Neon: unsupported ${os3} architecture: ${process.arch}`);
25803
25874
  }
25804
- Error.call(this, message);
25805
- descriptor.value = "" + message;
25806
- Object.defineProperty(this, "message", descriptor);
25807
- Error.captureStackTrace(this, SqliteError);
25808
- this.code = code;
25875
+ throw new Error(`Neon: unsupported system: ${process.platform}`);
25809
25876
  }
25810
- Object.setPrototypeOf(SqliteError, Error);
25811
- Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
25812
- Object.defineProperty(SqliteError.prototype, "name", descriptor);
25813
- module.exports = SqliteError;
25877
+ exports.currentTarget = currentTarget;
25878
+ function isGlibc() {
25879
+ const report = process.report?.getReport();
25880
+ if (typeof report !== "object" || !report || !("header" in report)) {
25881
+ return false;
25882
+ }
25883
+ const header = report.header;
25884
+ return typeof header === "object" && !!header && "glibcVersionRuntime" in header;
25885
+ }
25886
+ function load2(dirname) {
25887
+ const m = path.join(dirname, "index.node");
25888
+ return fs.existsSync(m) ? __require(m) : null;
25889
+ }
25890
+ exports.load = load2;
25814
25891
  });
25815
25892
 
25816
- // node_modules/file-uri-to-path/index.js
25817
- var require_file_uri_to_path = __commonJS((exports, module) => {
25818
- var sep = __require("path").sep || "/";
25819
- module.exports = fileUriToPath;
25820
- function fileUriToPath(uri) {
25821
- if (typeof uri != "string" || uri.length <= 7 || uri.substring(0, 7) != "file://") {
25822
- throw new TypeError("must pass in a file:// URI to convert to a file path");
25823
- }
25824
- var rest = decodeURI(uri.substring(7));
25825
- var firstSlash = rest.indexOf("/");
25826
- var host = rest.substring(0, firstSlash);
25827
- var path = rest.substring(firstSlash + 1);
25828
- if (host == "localhost")
25829
- host = "";
25830
- if (host) {
25831
- host = sep + sep + host;
25832
- }
25833
- path = path.replace(/^(.+)\|/, "$1:");
25834
- if (sep == "\\") {
25835
- path = path.replace(/\//g, "\\");
25836
- }
25837
- if (/^.+\:/.test(path)) {} else {
25838
- path = sep + path;
25839
- }
25840
- return host + path;
25841
- }
25893
+ // node_modules/detect-libc/lib/process.js
25894
+ var require_process = __commonJS((exports, module) => {
25895
+ var isLinux = () => process.platform === "linux";
25896
+ var report = null;
25897
+ var getReport = () => {
25898
+ if (!report) {
25899
+ report = isLinux() && process.report ? process.report.getReport() : {};
25900
+ }
25901
+ return report;
25902
+ };
25903
+ module.exports = { isLinux, getReport };
25842
25904
  });
25843
25905
 
25844
- // node_modules/bindings/bindings.js
25845
- var require_bindings = __commonJS((exports, module) => {
25846
- var __filename = "/home/runner/work/terradb/terradb/node_modules/bindings/bindings.js";
25906
+ // node_modules/detect-libc/lib/filesystem.js
25907
+ var require_filesystem = __commonJS((exports, module) => {
25847
25908
  var fs = __require("fs");
25848
- var path = __require("path");
25849
- var fileURLToPath = require_file_uri_to_path();
25850
- var join = path.join;
25851
- var dirname = path.dirname;
25852
- var exists = fs.accessSync && function(path2) {
25853
- try {
25854
- fs.accessSync(path2);
25855
- } catch (e) {
25856
- return false;
25909
+ var LDD_PATH = "/usr/bin/ldd";
25910
+ var readFileSync2 = (path) => fs.readFileSync(path, "utf-8");
25911
+ var readFile = (path) => new Promise((resolve, reject) => {
25912
+ fs.readFile(path, "utf-8", (err, data) => {
25913
+ if (err) {
25914
+ reject(err);
25915
+ } else {
25916
+ resolve(data);
25917
+ }
25918
+ });
25919
+ });
25920
+ module.exports = {
25921
+ LDD_PATH,
25922
+ readFileSync: readFileSync2,
25923
+ readFile
25924
+ };
25925
+ });
25926
+
25927
+ // node_modules/detect-libc/lib/detect-libc.js
25928
+ var require_detect_libc = __commonJS((exports, module) => {
25929
+ var childProcess = __require("child_process");
25930
+ var { isLinux, getReport } = require_process();
25931
+ var { LDD_PATH, readFile, readFileSync: readFileSync2 } = require_filesystem();
25932
+ var cachedFamilyFilesystem;
25933
+ var cachedVersionFilesystem;
25934
+ var command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
25935
+ var commandOut = "";
25936
+ var safeCommand = () => {
25937
+ if (!commandOut) {
25938
+ return new Promise((resolve) => {
25939
+ childProcess.exec(command, (err, out) => {
25940
+ commandOut = err ? " " : out;
25941
+ resolve(commandOut);
25942
+ });
25943
+ });
25857
25944
  }
25858
- return true;
25859
- } || fs.existsSync || path.existsSync;
25860
- var defaults2 = {
25861
- arrow: process.env.NODE_BINDINGS_ARROW || " → ",
25862
- compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
25863
- platform: process.platform,
25864
- arch: process.arch,
25865
- nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
25866
- version: process.versions.node,
25867
- bindings: "bindings.node",
25868
- try: [
25869
- ["module_root", "build", "bindings"],
25870
- ["module_root", "build", "Debug", "bindings"],
25871
- ["module_root", "build", "Release", "bindings"],
25872
- ["module_root", "out", "Debug", "bindings"],
25873
- ["module_root", "Debug", "bindings"],
25874
- ["module_root", "out", "Release", "bindings"],
25875
- ["module_root", "Release", "bindings"],
25876
- ["module_root", "build", "default", "bindings"],
25877
- ["module_root", "compiled", "version", "platform", "arch", "bindings"],
25878
- ["module_root", "addon-build", "release", "install-root", "bindings"],
25879
- ["module_root", "addon-build", "debug", "install-root", "bindings"],
25880
- ["module_root", "addon-build", "default", "install-root", "bindings"],
25881
- ["module_root", "lib", "binding", "nodePreGyp", "bindings"]
25882
- ]
25945
+ return commandOut;
25883
25946
  };
25884
- function bindings(opts) {
25885
- if (typeof opts == "string") {
25886
- opts = { bindings: opts };
25887
- } else if (!opts) {
25888
- opts = {};
25889
- }
25890
- Object.keys(defaults2).map(function(i2) {
25891
- if (!(i2 in opts))
25892
- opts[i2] = defaults2[i2];
25893
- });
25894
- if (!opts.module_root) {
25895
- opts.module_root = exports.getRoot(exports.getFileName());
25896
- }
25897
- if (path.extname(opts.bindings) != ".node") {
25898
- opts.bindings += ".node";
25899
- }
25900
- var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
25901
- var tries = [], i = 0, l = opts.try.length, n, b, err;
25902
- for (;i < l; i++) {
25903
- n = join.apply(null, opts.try[i].map(function(p) {
25904
- return opts[p] || p;
25905
- }));
25906
- tries.push(n);
25947
+ var safeCommandSync = () => {
25948
+ if (!commandOut) {
25907
25949
  try {
25908
- b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
25909
- if (!opts.path) {
25910
- b.path = n;
25911
- }
25912
- return b;
25913
- } catch (e) {
25914
- if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
25915
- throw e;
25916
- }
25950
+ commandOut = childProcess.execSync(command, { encoding: "utf8" });
25951
+ } catch (_err) {
25952
+ commandOut = " ";
25917
25953
  }
25918
25954
  }
25919
- err = new Error(`Could not locate the bindings file. Tried:
25920
- ` + tries.map(function(a) {
25921
- return opts.arrow + a;
25922
- }).join(`
25923
- `));
25924
- err.tries = tries;
25925
- throw err;
25926
- }
25927
- module.exports = exports = bindings;
25928
- exports.getFileName = function getFileName(calling_file) {
25929
- var { prepareStackTrace: origPST, stackTraceLimit: origSTL } = Error, dummy = {}, fileName;
25930
- Error.stackTraceLimit = 10;
25931
- Error.prepareStackTrace = function(e, st) {
25932
- for (var i = 0, l = st.length;i < l; i++) {
25933
- fileName = st[i].getFileName();
25934
- if (fileName !== __filename) {
25935
- if (calling_file) {
25936
- if (fileName !== calling_file) {
25937
- return;
25938
- }
25939
- } else {
25940
- return;
25941
- }
25942
- }
25943
- }
25944
- };
25945
- Error.captureStackTrace(dummy);
25946
- dummy.stack;
25947
- Error.prepareStackTrace = origPST;
25948
- Error.stackTraceLimit = origSTL;
25949
- var fileSchema = "file://";
25950
- if (fileName.indexOf(fileSchema) === 0) {
25951
- fileName = fileURLToPath(fileName);
25952
- }
25953
- return fileName;
25955
+ return commandOut;
25954
25956
  };
25955
- exports.getRoot = function getRoot(file) {
25956
- var dir = dirname(file), prev;
25957
- while (true) {
25958
- if (dir === ".") {
25959
- dir = process.cwd();
25957
+ var GLIBC = "glibc";
25958
+ var RE_GLIBC_VERSION = /GLIBC\s(\d+\.\d+)/;
25959
+ var MUSL = "musl";
25960
+ var GLIBC_ON_LDD = GLIBC.toUpperCase();
25961
+ var MUSL_ON_LDD = MUSL.toLowerCase();
25962
+ var isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
25963
+ var familyFromReport = () => {
25964
+ const report = getReport();
25965
+ if (report.header && report.header.glibcVersionRuntime) {
25966
+ return GLIBC;
25967
+ }
25968
+ if (Array.isArray(report.sharedObjects)) {
25969
+ if (report.sharedObjects.some(isFileMusl)) {
25970
+ return MUSL;
25960
25971
  }
25961
- if (exists(join(dir, "package.json")) || exists(join(dir, "node_modules"))) {
25962
- return dir;
25963
- }
25964
- if (prev === dir) {
25965
- throw new Error('Could not find module root given file: "' + file + '". Do you have a `package.json` file? ');
25966
- }
25967
- prev = dir;
25968
- dir = join(dir, "..");
25969
25972
  }
25973
+ return null;
25970
25974
  };
25971
- });
25972
-
25973
- // node_modules/better-sqlite3/lib/methods/wrappers.js
25974
- var require_wrappers = __commonJS((exports) => {
25975
- var { cppdb } = require_util();
25976
- exports.prepare = function prepare(sql) {
25977
- return this[cppdb].prepare(sql, this, false);
25978
- };
25979
- exports.exec = function exec(sql) {
25980
- this[cppdb].exec(sql);
25981
- return this;
25982
- };
25983
- exports.close = function close() {
25984
- this[cppdb].close();
25985
- return this;
25986
- };
25987
- exports.loadExtension = function loadExtension(...args) {
25988
- this[cppdb].loadExtension(...args);
25989
- return this;
25975
+ var familyFromCommand = (out) => {
25976
+ const [getconf, ldd1] = out.split(/[\r\n]+/);
25977
+ if (getconf && getconf.includes(GLIBC)) {
25978
+ return GLIBC;
25979
+ }
25980
+ if (ldd1 && ldd1.includes(MUSL)) {
25981
+ return MUSL;
25982
+ }
25983
+ return null;
25990
25984
  };
25991
- exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
25992
- this[cppdb].defaultSafeIntegers(...args);
25993
- return this;
25985
+ var getFamilyFromLddContent = (content) => {
25986
+ if (content.includes(MUSL_ON_LDD)) {
25987
+ return MUSL;
25988
+ }
25989
+ if (content.includes(GLIBC_ON_LDD)) {
25990
+ return GLIBC;
25991
+ }
25992
+ return null;
25994
25993
  };
25995
- exports.unsafeMode = function unsafeMode(...args) {
25996
- this[cppdb].unsafeMode(...args);
25997
- return this;
25994
+ var familyFromFilesystem = async () => {
25995
+ if (cachedFamilyFilesystem !== undefined) {
25996
+ return cachedFamilyFilesystem;
25997
+ }
25998
+ cachedFamilyFilesystem = null;
25999
+ try {
26000
+ const lddContent = await readFile(LDD_PATH);
26001
+ cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
26002
+ } catch (e) {}
26003
+ return cachedFamilyFilesystem;
25998
26004
  };
25999
- exports.getters = {
26000
- name: {
26001
- get: function name() {
26002
- return this[cppdb].name;
26003
- },
26004
- enumerable: true
26005
- },
26006
- open: {
26007
- get: function open() {
26008
- return this[cppdb].open;
26009
- },
26010
- enumerable: true
26011
- },
26012
- inTransaction: {
26013
- get: function inTransaction() {
26014
- return this[cppdb].inTransaction;
26015
- },
26016
- enumerable: true
26017
- },
26018
- readonly: {
26019
- get: function readonly() {
26020
- return this[cppdb].readonly;
26021
- },
26022
- enumerable: true
26023
- },
26024
- memory: {
26025
- get: function memory() {
26026
- return this[cppdb].memory;
26027
- },
26028
- enumerable: true
26005
+ var familyFromFilesystemSync = () => {
26006
+ if (cachedFamilyFilesystem !== undefined) {
26007
+ return cachedFamilyFilesystem;
26029
26008
  }
26009
+ cachedFamilyFilesystem = null;
26010
+ try {
26011
+ const lddContent = readFileSync2(LDD_PATH);
26012
+ cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
26013
+ } catch (e) {}
26014
+ return cachedFamilyFilesystem;
26030
26015
  };
26031
- });
26032
-
26033
- // node_modules/better-sqlite3/lib/methods/transaction.js
26034
- var require_transaction = __commonJS((exports, module) => {
26035
- var { cppdb } = require_util();
26036
- var controllers = new WeakMap;
26037
- module.exports = function transaction(fn) {
26038
- if (typeof fn !== "function")
26039
- throw new TypeError("Expected first argument to be a function");
26040
- const db = this[cppdb];
26041
- const controller = getController(db, this);
26042
- const { apply } = Function.prototype;
26043
- const properties = {
26044
- default: { value: wrapTransaction(apply, fn, db, controller.default) },
26045
- deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
26046
- immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
26047
- exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
26048
- database: { value: this, enumerable: true }
26049
- };
26050
- Object.defineProperties(properties.default.value, properties);
26051
- Object.defineProperties(properties.deferred.value, properties);
26052
- Object.defineProperties(properties.immediate.value, properties);
26053
- Object.defineProperties(properties.exclusive.value, properties);
26054
- return properties.default.value;
26016
+ var family = async () => {
26017
+ let family2 = null;
26018
+ if (isLinux()) {
26019
+ family2 = await familyFromFilesystem();
26020
+ if (!family2) {
26021
+ family2 = familyFromReport();
26022
+ }
26023
+ if (!family2) {
26024
+ const out = await safeCommand();
26025
+ family2 = familyFromCommand(out);
26026
+ }
26027
+ }
26028
+ return family2;
26055
26029
  };
26056
- var getController = (db, self2) => {
26057
- let controller = controllers.get(db);
26058
- if (!controller) {
26059
- const shared = {
26060
- commit: db.prepare("COMMIT", self2, false),
26061
- rollback: db.prepare("ROLLBACK", self2, false),
26062
- savepoint: db.prepare("SAVEPOINT `\t_bs3.\t`", self2, false),
26063
- release: db.prepare("RELEASE `\t_bs3.\t`", self2, false),
26064
- rollbackTo: db.prepare("ROLLBACK TO `\t_bs3.\t`", self2, false)
26065
- };
26066
- controllers.set(db, controller = {
26067
- default: Object.assign({ begin: db.prepare("BEGIN", self2, false) }, shared),
26068
- deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self2, false) }, shared),
26069
- immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self2, false) }, shared),
26070
- exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self2, false) }, shared)
26071
- });
26030
+ var familySync = () => {
26031
+ let family2 = null;
26032
+ if (isLinux()) {
26033
+ family2 = familyFromFilesystemSync();
26034
+ if (!family2) {
26035
+ family2 = familyFromReport();
26036
+ }
26037
+ if (!family2) {
26038
+ const out = safeCommandSync();
26039
+ family2 = familyFromCommand(out);
26040
+ }
26072
26041
  }
26073
- return controller;
26042
+ return family2;
26074
26043
  };
26075
- var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
26076
- let before, after, undo;
26077
- if (db.inTransaction) {
26078
- before = savepoint;
26079
- after = release;
26080
- undo = rollbackTo;
26081
- } else {
26082
- before = begin;
26083
- after = commit;
26084
- undo = rollback;
26044
+ var isNonGlibcLinux = async () => isLinux() && await family() !== GLIBC;
26045
+ var isNonGlibcLinuxSync = () => isLinux() && familySync() !== GLIBC;
26046
+ var versionFromFilesystem = async () => {
26047
+ if (cachedVersionFilesystem !== undefined) {
26048
+ return cachedVersionFilesystem;
26085
26049
  }
26086
- before.run();
26050
+ cachedVersionFilesystem = null;
26087
26051
  try {
26088
- const result = apply.call(fn, this, arguments);
26089
- if (result && typeof result.then === "function") {
26090
- throw new TypeError("Transaction function cannot return a promise");
26052
+ const lddContent = await readFile(LDD_PATH);
26053
+ const versionMatch = lddContent.match(RE_GLIBC_VERSION);
26054
+ if (versionMatch) {
26055
+ cachedVersionFilesystem = versionMatch[1];
26091
26056
  }
26092
- after.run();
26093
- return result;
26094
- } catch (ex) {
26095
- if (db.inTransaction) {
26096
- undo.run();
26097
- if (undo !== rollback)
26098
- after.run();
26057
+ } catch (e) {}
26058
+ return cachedVersionFilesystem;
26059
+ };
26060
+ var versionFromFilesystemSync = () => {
26061
+ if (cachedVersionFilesystem !== undefined) {
26062
+ return cachedVersionFilesystem;
26063
+ }
26064
+ cachedVersionFilesystem = null;
26065
+ try {
26066
+ const lddContent = readFileSync2(LDD_PATH);
26067
+ const versionMatch = lddContent.match(RE_GLIBC_VERSION);
26068
+ if (versionMatch) {
26069
+ cachedVersionFilesystem = versionMatch[1];
26099
26070
  }
26100
- throw ex;
26071
+ } catch (e) {}
26072
+ return cachedVersionFilesystem;
26073
+ };
26074
+ var versionFromReport = () => {
26075
+ const report = getReport();
26076
+ if (report.header && report.header.glibcVersionRuntime) {
26077
+ return report.header.glibcVersionRuntime;
26101
26078
  }
26079
+ return null;
26102
26080
  };
26103
- });
26104
-
26105
- // node_modules/better-sqlite3/lib/methods/pragma.js
26106
- var require_pragma = __commonJS((exports, module) => {
26107
- var { getBooleanOption, cppdb } = require_util();
26108
- module.exports = function pragma(source, options) {
26109
- if (options == null)
26110
- options = {};
26111
- if (typeof source !== "string")
26112
- throw new TypeError("Expected first argument to be a string");
26113
- if (typeof options !== "object")
26114
- throw new TypeError("Expected second argument to be an options object");
26115
- const simple = getBooleanOption(options, "simple");
26116
- const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
26117
- return simple ? stmt.pluck().get() : stmt.all();
26081
+ var versionSuffix = (s) => s.trim().split(/\s+/)[1];
26082
+ var versionFromCommand = (out) => {
26083
+ const [getconf, ldd1, ldd2] = out.split(/[\r\n]+/);
26084
+ if (getconf && getconf.includes(GLIBC)) {
26085
+ return versionSuffix(getconf);
26086
+ }
26087
+ if (ldd1 && ldd2 && ldd1.includes(MUSL)) {
26088
+ return versionSuffix(ldd2);
26089
+ }
26090
+ return null;
26118
26091
  };
26119
- });
26120
-
26121
- // node_modules/better-sqlite3/lib/methods/backup.js
26122
- var require_backup = __commonJS((exports, module) => {
26123
- var fs = __require("fs");
26124
- var path = __require("path");
26125
- var { promisify } = __require("util");
26126
- var { cppdb } = require_util();
26127
- var fsAccess = promisify(fs.access);
26128
- module.exports = async function backup(filename, options) {
26129
- if (options == null)
26130
- options = {};
26131
- if (typeof filename !== "string")
26132
- throw new TypeError("Expected first argument to be a string");
26133
- if (typeof options !== "object")
26134
- throw new TypeError("Expected second argument to be an options object");
26135
- filename = filename.trim();
26136
- const attachedName = "attached" in options ? options.attached : "main";
26137
- const handler = "progress" in options ? options.progress : null;
26138
- if (!filename)
26139
- throw new TypeError("Backup filename cannot be an empty string");
26140
- if (filename === ":memory:")
26141
- throw new TypeError('Invalid backup filename ":memory:"');
26142
- if (typeof attachedName !== "string")
26143
- throw new TypeError('Expected the "attached" option to be a string');
26144
- if (!attachedName)
26145
- throw new TypeError('The "attached" option cannot be an empty string');
26146
- if (handler != null && typeof handler !== "function")
26147
- throw new TypeError('Expected the "progress" option to be a function');
26148
- await fsAccess(path.dirname(filename)).catch(() => {
26149
- throw new TypeError("Cannot save backup because the directory does not exist");
26150
- });
26151
- const isNewFile = await fsAccess(filename).then(() => false, () => true);
26152
- return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
26092
+ var version = async () => {
26093
+ let version2 = null;
26094
+ if (isLinux()) {
26095
+ version2 = await versionFromFilesystem();
26096
+ if (!version2) {
26097
+ version2 = versionFromReport();
26098
+ }
26099
+ if (!version2) {
26100
+ const out = await safeCommand();
26101
+ version2 = versionFromCommand(out);
26102
+ }
26103
+ }
26104
+ return version2;
26153
26105
  };
26154
- var runBackup = (backup, handler) => {
26155
- let rate = 0;
26156
- let useDefault = true;
26157
- return new Promise((resolve, reject) => {
26158
- setImmediate(function step() {
26159
- try {
26160
- const progress = backup.transfer(rate);
26161
- if (!progress.remainingPages) {
26162
- backup.close();
26163
- resolve(progress);
26164
- return;
26165
- }
26166
- if (useDefault) {
26167
- useDefault = false;
26168
- rate = 100;
26169
- }
26170
- if (handler) {
26171
- const ret = handler(progress);
26172
- if (ret !== undefined) {
26173
- if (typeof ret === "number" && ret === ret)
26174
- rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
26175
- else
26176
- throw new TypeError("Expected progress callback to return a number or undefined");
26177
- }
26178
- }
26179
- setImmediate(step);
26180
- } catch (err) {
26181
- backup.close();
26182
- reject(err);
26183
- }
26184
- });
26185
- });
26106
+ var versionSync = () => {
26107
+ let version2 = null;
26108
+ if (isLinux()) {
26109
+ version2 = versionFromFilesystemSync();
26110
+ if (!version2) {
26111
+ version2 = versionFromReport();
26112
+ }
26113
+ if (!version2) {
26114
+ const out = safeCommandSync();
26115
+ version2 = versionFromCommand(out);
26116
+ }
26117
+ }
26118
+ return version2;
26186
26119
  };
26187
- });
26188
-
26189
- // node_modules/better-sqlite3/lib/methods/serialize.js
26190
- var require_serialize = __commonJS((exports, module) => {
26191
- var { cppdb } = require_util();
26192
- module.exports = function serialize(options) {
26193
- if (options == null)
26194
- options = {};
26195
- if (typeof options !== "object")
26196
- throw new TypeError("Expected first argument to be an options object");
26197
- const attachedName = "attached" in options ? options.attached : "main";
26198
- if (typeof attachedName !== "string")
26199
- throw new TypeError('Expected the "attached" option to be a string');
26200
- if (!attachedName)
26201
- throw new TypeError('The "attached" option cannot be an empty string');
26202
- return this[cppdb].serialize(attachedName);
26120
+ module.exports = {
26121
+ GLIBC,
26122
+ MUSL,
26123
+ family,
26124
+ familySync,
26125
+ isNonGlibcLinux,
26126
+ isNonGlibcLinuxSync,
26127
+ version,
26128
+ versionSync
26203
26129
  };
26204
26130
  });
26205
26131
 
26206
- // node_modules/better-sqlite3/lib/methods/function.js
26207
- var require_function = __commonJS((exports, module) => {
26208
- var { getBooleanOption, cppdb } = require_util();
26209
- module.exports = function defineFunction(name, options, fn) {
26210
- if (options == null)
26211
- options = {};
26212
- if (typeof options === "function") {
26213
- fn = options;
26214
- options = {};
26215
- }
26216
- if (typeof name !== "string")
26217
- throw new TypeError("Expected first argument to be a string");
26218
- if (typeof fn !== "function")
26219
- throw new TypeError("Expected last argument to be a function");
26220
- if (typeof options !== "object")
26221
- throw new TypeError("Expected second argument to be an options object");
26222
- if (!name)
26223
- throw new TypeError("User-defined function name cannot be an empty string");
26224
- const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
26225
- const deterministic = getBooleanOption(options, "deterministic");
26226
- const directOnly = getBooleanOption(options, "directOnly");
26227
- const varargs = getBooleanOption(options, "varargs");
26228
- let argCount = -1;
26229
- if (!varargs) {
26230
- argCount = fn.length;
26231
- if (!Number.isInteger(argCount) || argCount < 0)
26232
- throw new TypeError("Expected function.length to be a positive integer");
26233
- if (argCount > 100)
26234
- throw new RangeError("User-defined functions cannot have more than 100 arguments");
26235
- }
26236
- this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
26237
- return this;
26132
+ // node_modules/libsql/auth.js
26133
+ var require_auth = __commonJS((exports, module) => {
26134
+ var Authorization = {
26135
+ ALLOW: 0,
26136
+ DENY: 1
26238
26137
  };
26138
+ module.exports = Authorization;
26239
26139
  });
26240
26140
 
26241
- // node_modules/better-sqlite3/lib/methods/aggregate.js
26242
- var require_aggregate = __commonJS((exports, module) => {
26243
- var { getBooleanOption, cppdb } = require_util();
26244
- module.exports = function defineAggregate(name, options) {
26245
- if (typeof name !== "string")
26246
- throw new TypeError("Expected first argument to be a string");
26247
- if (typeof options !== "object" || options === null)
26248
- throw new TypeError("Expected second argument to be an options object");
26249
- if (!name)
26250
- throw new TypeError("User-defined function name cannot be an empty string");
26251
- const start = "start" in options ? options.start : null;
26252
- const step = getFunctionOption(options, "step", true);
26253
- const inverse2 = getFunctionOption(options, "inverse", false);
26254
- const result = getFunctionOption(options, "result", false);
26255
- const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
26256
- const deterministic = getBooleanOption(options, "deterministic");
26257
- const directOnly = getBooleanOption(options, "directOnly");
26258
- const varargs = getBooleanOption(options, "varargs");
26259
- let argCount = -1;
26260
- if (!varargs) {
26261
- argCount = Math.max(getLength(step), inverse2 ? getLength(inverse2) : 0);
26262
- if (argCount > 0)
26263
- argCount -= 1;
26264
- if (argCount > 100)
26265
- throw new RangeError("User-defined functions cannot have more than 100 arguments");
26266
- }
26267
- this[cppdb].aggregate(start, step, inverse2, result, name, argCount, safeIntegers, deterministic, directOnly);
26268
- return this;
26269
- };
26270
- var getFunctionOption = (options, key, required) => {
26271
- const value = key in options ? options[key] : null;
26272
- if (typeof value === "function")
26273
- return value;
26274
- if (value != null)
26275
- throw new TypeError(`Expected the "${key}" option to be a function`);
26276
- if (required)
26277
- throw new TypeError(`Missing required option "${key}"`);
26278
- return null;
26279
- };
26280
- var getLength = ({ length }) => {
26281
- if (Number.isInteger(length) && length >= 0)
26282
- return length;
26283
- throw new TypeError("Expected function.length to be a positive integer");
26284
- };
26141
+ // node_modules/libsql/sqlite-error.js
26142
+ var require_sqlite_error = __commonJS((exports, module) => {
26143
+ var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
26144
+ function SqliteError(message, code, rawCode) {
26145
+ if (new.target !== SqliteError) {
26146
+ return new SqliteError(message, code);
26147
+ }
26148
+ if (typeof code !== "string") {
26149
+ throw new TypeError("Expected second argument to be a string");
26150
+ }
26151
+ Error.call(this, message);
26152
+ descriptor.value = "" + message;
26153
+ Object.defineProperty(this, "message", descriptor);
26154
+ Error.captureStackTrace(this, SqliteError);
26155
+ this.code = code;
26156
+ this.rawCode = rawCode;
26157
+ }
26158
+ Object.setPrototypeOf(SqliteError, Error);
26159
+ Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
26160
+ Object.defineProperty(SqliteError.prototype, "name", descriptor);
26161
+ module.exports = SqliteError;
26285
26162
  });
26286
26163
 
26287
- // node_modules/better-sqlite3/lib/methods/table.js
26288
- var require_table = __commonJS((exports, module) => {
26289
- var { cppdb } = require_util();
26290
- module.exports = function defineTable(name, factory) {
26291
- if (typeof name !== "string")
26292
- throw new TypeError("Expected first argument to be a string");
26293
- if (!name)
26294
- throw new TypeError("Virtual table module name cannot be an empty string");
26295
- let eponymous = false;
26296
- if (typeof factory === "object" && factory !== null) {
26297
- eponymous = true;
26298
- factory = defer(parseTableDefinition(factory, "used", name));
26299
- } else {
26300
- if (typeof factory !== "function")
26301
- throw new TypeError("Expected second argument to be a function or a table definition object");
26302
- factory = wrapFactory(factory);
26303
- }
26304
- this[cppdb].table(factory, name, eponymous);
26305
- return this;
26306
- };
26307
- function wrapFactory(factory) {
26308
- return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
26309
- const thisObject = {
26310
- module: moduleName,
26311
- database: databaseName,
26312
- table: tableName
26313
- };
26314
- const def = apply.call(factory, thisObject, args);
26315
- if (typeof def !== "object" || def === null) {
26316
- throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
26164
+ // node_modules/libsql/index.js
26165
+ var require_libsql = __commonJS((exports, module) => {
26166
+ var __dirname = "/home/runner/work/terradb/terradb/node_modules/libsql";
26167
+ var { load: load2, currentTarget } = require_dist3();
26168
+ var { familySync, GLIBC, MUSL } = require_detect_libc();
26169
+ function requireNative() {
26170
+ if (process.env.LIBSQL_JS_DEV) {
26171
+ return load2(__dirname);
26172
+ }
26173
+ let target = currentTarget();
26174
+ if (familySync() == GLIBC) {
26175
+ switch (target) {
26176
+ case "linux-x64-musl":
26177
+ target = "linux-x64-gnu";
26178
+ break;
26179
+ case "linux-arm64-musl":
26180
+ target = "linux-arm64-gnu";
26181
+ break;
26317
26182
  }
26318
- return parseTableDefinition(def, "returned", moduleName);
26319
- };
26183
+ }
26184
+ if (target === "linux-arm-gnueabihf" && familySync() == MUSL) {
26185
+ target = "linux-arm-musleabihf";
26186
+ }
26187
+ return __require(`@libsql/${target}`);
26188
+ }
26189
+ var {
26190
+ databaseOpen,
26191
+ databaseOpenWithSync,
26192
+ databaseInTransaction,
26193
+ databaseInterrupt,
26194
+ databaseClose,
26195
+ databaseSyncSync,
26196
+ databaseSyncUntilSync,
26197
+ databaseExecSync,
26198
+ databasePrepareSync,
26199
+ databaseDefaultSafeIntegers,
26200
+ databaseAuthorizer,
26201
+ databaseLoadExtension,
26202
+ databaseMaxWriteReplicationIndex,
26203
+ statementRaw,
26204
+ statementIsReader,
26205
+ statementGet,
26206
+ statementRun,
26207
+ statementInterrupt,
26208
+ statementRowsSync,
26209
+ statementColumns,
26210
+ statementSafeIntegers,
26211
+ rowsNext
26212
+ } = requireNative();
26213
+ var Authorization = require_auth();
26214
+ var SqliteError = require_sqlite_error();
26215
+ function convertError(err) {
26216
+ if (err.libsqlError) {
26217
+ return new SqliteError(err.message, err.code, err.rawCode);
26218
+ }
26219
+ return err;
26320
26220
  }
26321
- function parseTableDefinition(def, verb, moduleName) {
26322
- if (!hasOwnProperty.call(def, "rows")) {
26323
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
26221
+
26222
+ class Database {
26223
+ constructor(path, opts) {
26224
+ const encryptionCipher = opts?.encryptionCipher ?? "aes256cbc";
26225
+ if (opts && opts.syncUrl) {
26226
+ var authToken = "";
26227
+ if (opts.syncAuth) {
26228
+ console.warn("Warning: The `syncAuth` option is deprecated, please use `authToken` option instead.");
26229
+ authToken = opts.syncAuth;
26230
+ } else if (opts.authToken) {
26231
+ authToken = opts.authToken;
26232
+ }
26233
+ const encryptionKey = opts?.encryptionKey ?? "";
26234
+ const syncPeriod = opts?.syncPeriod ?? 0;
26235
+ const readYourWrites = opts?.readYourWrites ?? true;
26236
+ const offline = opts?.offline ?? false;
26237
+ const remoteEncryptionKey = opts?.remoteEncryptionKey ?? "";
26238
+ this.db = databaseOpenWithSync(path, opts.syncUrl, authToken, encryptionCipher, encryptionKey, syncPeriod, readYourWrites, offline, remoteEncryptionKey);
26239
+ } else {
26240
+ const authToken2 = opts?.authToken ?? "";
26241
+ const encryptionKey = opts?.encryptionKey ?? "";
26242
+ const timeout = opts?.timeout ?? 0;
26243
+ const remoteEncryptionKey = opts?.remoteEncryptionKey ?? "";
26244
+ this.db = databaseOpen(path, authToken2, encryptionCipher, encryptionKey, timeout, remoteEncryptionKey);
26245
+ }
26246
+ this.memory = path === ":memory:";
26247
+ this.readonly = false;
26248
+ this.name = "";
26249
+ this.open = true;
26250
+ const db = this.db;
26251
+ Object.defineProperties(this, {
26252
+ inTransaction: {
26253
+ get() {
26254
+ return databaseInTransaction(db);
26255
+ }
26256
+ }
26257
+ });
26324
26258
  }
26325
- if (!hasOwnProperty.call(def, "columns")) {
26326
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
26259
+ sync() {
26260
+ return databaseSyncSync.call(this.db);
26327
26261
  }
26328
- const rows = def.rows;
26329
- if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
26330
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
26262
+ syncUntil(replicationIndex) {
26263
+ return databaseSyncUntilSync.call(this.db, replicationIndex);
26331
26264
  }
26332
- let columns = def.columns;
26333
- if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
26334
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
26265
+ prepare(sql) {
26266
+ try {
26267
+ const stmt = databasePrepareSync.call(this.db, sql);
26268
+ return new Statement(stmt);
26269
+ } catch (err) {
26270
+ throw convertError(err);
26271
+ }
26335
26272
  }
26336
- if (columns.length !== new Set(columns).size) {
26337
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
26273
+ transaction(fn) {
26274
+ if (typeof fn !== "function")
26275
+ throw new TypeError("Expected first argument to be a function");
26276
+ const db = this;
26277
+ const wrapTxn = (mode) => {
26278
+ return (...bindParameters) => {
26279
+ db.exec("BEGIN " + mode);
26280
+ try {
26281
+ const result = fn(...bindParameters);
26282
+ db.exec("COMMIT");
26283
+ return result;
26284
+ } catch (err) {
26285
+ db.exec("ROLLBACK");
26286
+ throw err;
26287
+ }
26288
+ };
26289
+ };
26290
+ const properties = {
26291
+ default: { value: wrapTxn("") },
26292
+ deferred: { value: wrapTxn("DEFERRED") },
26293
+ immediate: { value: wrapTxn("IMMEDIATE") },
26294
+ exclusive: { value: wrapTxn("EXCLUSIVE") },
26295
+ database: { value: this, enumerable: true }
26296
+ };
26297
+ Object.defineProperties(properties.default.value, properties);
26298
+ Object.defineProperties(properties.deferred.value, properties);
26299
+ Object.defineProperties(properties.immediate.value, properties);
26300
+ Object.defineProperties(properties.exclusive.value, properties);
26301
+ return properties.default.value;
26302
+ }
26303
+ pragma(source, options) {
26304
+ if (options == null)
26305
+ options = {};
26306
+ if (typeof source !== "string")
26307
+ throw new TypeError("Expected first argument to be a string");
26308
+ if (typeof options !== "object")
26309
+ throw new TypeError("Expected second argument to be an options object");
26310
+ const simple = options["simple"];
26311
+ const stmt = this.prepare(`PRAGMA ${source}`, this, true);
26312
+ return simple ? stmt.pluck().get() : stmt.all();
26313
+ }
26314
+ backup(filename, options) {
26315
+ throw new Error("not implemented");
26316
+ }
26317
+ serialize(options) {
26318
+ throw new Error("not implemented");
26319
+ }
26320
+ function(name, options, fn) {
26321
+ if (options == null)
26322
+ options = {};
26323
+ if (typeof options === "function") {
26324
+ fn = options;
26325
+ options = {};
26326
+ }
26327
+ if (typeof name !== "string")
26328
+ throw new TypeError("Expected first argument to be a string");
26329
+ if (typeof fn !== "function")
26330
+ throw new TypeError("Expected last argument to be a function");
26331
+ if (typeof options !== "object")
26332
+ throw new TypeError("Expected second argument to be an options object");
26333
+ if (!name)
26334
+ throw new TypeError("User-defined function name cannot be an empty string");
26335
+ throw new Error("not implemented");
26336
+ }
26337
+ aggregate(name, options) {
26338
+ if (typeof name !== "string")
26339
+ throw new TypeError("Expected first argument to be a string");
26340
+ if (typeof options !== "object" || options === null)
26341
+ throw new TypeError("Expected second argument to be an options object");
26342
+ if (!name)
26343
+ throw new TypeError("User-defined function name cannot be an empty string");
26344
+ throw new Error("not implemented");
26338
26345
  }
26339
- if (!columns.length) {
26340
- throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
26346
+ table(name, factory) {
26347
+ if (typeof name !== "string")
26348
+ throw new TypeError("Expected first argument to be a string");
26349
+ if (!name)
26350
+ throw new TypeError("Virtual table module name cannot be an empty string");
26351
+ throw new Error("not implemented");
26341
26352
  }
26342
- let parameters;
26343
- if (hasOwnProperty.call(def, "parameters")) {
26344
- parameters = def.parameters;
26345
- if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
26346
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
26347
- }
26348
- } else {
26349
- parameters = inferParameters(rows);
26353
+ authorizer(rules) {
26354
+ databaseAuthorizer.call(this.db, rules);
26350
26355
  }
26351
- if (parameters.length !== new Set(parameters).size) {
26352
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
26356
+ loadExtension(...args) {
26357
+ databaseLoadExtension.call(this.db, ...args);
26353
26358
  }
26354
- if (parameters.length > 32) {
26355
- throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
26359
+ maxWriteReplicationIndex() {
26360
+ return databaseMaxWriteReplicationIndex.call(this.db);
26356
26361
  }
26357
- for (const parameter of parameters) {
26358
- if (columns.includes(parameter)) {
26359
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
26362
+ exec(sql) {
26363
+ try {
26364
+ databaseExecSync.call(this.db, sql);
26365
+ } catch (err) {
26366
+ throw convertError(err);
26360
26367
  }
26361
26368
  }
26362
- let safeIntegers = 2;
26363
- if (hasOwnProperty.call(def, "safeIntegers")) {
26364
- const bool = def.safeIntegers;
26365
- if (typeof bool !== "boolean") {
26366
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
26367
- }
26368
- safeIntegers = +bool;
26369
+ interrupt() {
26370
+ databaseInterrupt.call(this.db);
26369
26371
  }
26370
- let directOnly = false;
26371
- if (hasOwnProperty.call(def, "directOnly")) {
26372
- directOnly = def.directOnly;
26373
- if (typeof directOnly !== "boolean") {
26374
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
26375
- }
26372
+ close() {
26373
+ databaseClose.call(this.db);
26374
+ this.open = false;
26375
+ }
26376
+ defaultSafeIntegers(toggle) {
26377
+ databaseDefaultSafeIntegers.call(this.db, toggle ?? true);
26378
+ return this;
26379
+ }
26380
+ unsafeMode(...args) {
26381
+ throw new Error("not implemented");
26376
26382
  }
26377
- const columnDefinitions = [
26378
- ...parameters.map(identifier).map((str) => `${str} HIDDEN`),
26379
- ...columns.map(identifier)
26380
- ];
26381
- return [
26382
- `CREATE TABLE x(${columnDefinitions.join(", ")});`,
26383
- wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
26384
- parameters,
26385
- safeIntegers,
26386
- directOnly
26387
- ];
26388
26383
  }
26389
- function wrapGenerator(generator, columnMap, moduleName) {
26390
- return function* virtualTable(...args) {
26391
- const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
26392
- for (let i = 0;i < columnMap.size; ++i) {
26393
- output.push(null);
26394
- }
26395
- for (const row of generator(...args)) {
26396
- if (Array.isArray(row)) {
26397
- extractRowArray(row, output, columnMap.size, moduleName);
26398
- yield output;
26399
- } else if (typeof row === "object" && row !== null) {
26400
- extractRowObject(row, output, columnMap, moduleName);
26401
- yield output;
26384
+
26385
+ class Statement {
26386
+ constructor(stmt) {
26387
+ this.stmt = stmt;
26388
+ this.pluckMode = false;
26389
+ }
26390
+ raw(raw) {
26391
+ statementRaw.call(this.stmt, raw ?? true);
26392
+ return this;
26393
+ }
26394
+ pluck(pluckMode) {
26395
+ this.pluckMode = pluckMode ?? true;
26396
+ return this;
26397
+ }
26398
+ get reader() {
26399
+ return statementIsReader.call(this.stmt);
26400
+ }
26401
+ run(...bindParameters) {
26402
+ try {
26403
+ if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
26404
+ return statementRun.call(this.stmt, bindParameters[0]);
26402
26405
  } else {
26403
- throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
26406
+ return statementRun.call(this.stmt, bindParameters.flat());
26404
26407
  }
26408
+ } catch (err) {
26409
+ throw convertError(err);
26405
26410
  }
26406
- };
26407
- }
26408
- function extractRowArray(row, output, columnCount, moduleName) {
26409
- if (row.length !== columnCount) {
26410
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
26411
- }
26412
- const offset = output.length - columnCount;
26413
- for (let i = 0;i < columnCount; ++i) {
26414
- output[i + offset] = row[i];
26415
26411
  }
26416
- }
26417
- function extractRowObject(row, output, columnMap, moduleName) {
26418
- let count = 0;
26419
- for (const key of Object.keys(row)) {
26420
- const index = columnMap.get(key);
26421
- if (index === undefined) {
26422
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
26412
+ get(...bindParameters) {
26413
+ try {
26414
+ if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
26415
+ return statementGet.call(this.stmt, bindParameters[0]);
26416
+ } else {
26417
+ return statementGet.call(this.stmt, bindParameters.flat());
26418
+ }
26419
+ } catch (err) {
26420
+ throw convertError(err);
26423
26421
  }
26424
- output[index] = row[key];
26425
- count += 1;
26426
26422
  }
26427
- if (count !== columnMap.size) {
26428
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
26429
- }
26430
- }
26431
- function inferParameters({ length }) {
26432
- if (!Number.isInteger(length) || length < 0) {
26433
- throw new TypeError("Expected function.length to be a positive integer");
26423
+ iterate(...bindParameters) {
26424
+ var rows = undefined;
26425
+ if (bindParameters.length == 1 && typeof bindParameters[0] === "object") {
26426
+ rows = statementRowsSync.call(this.stmt, bindParameters[0]);
26427
+ } else {
26428
+ rows = statementRowsSync.call(this.stmt, bindParameters.flat());
26429
+ }
26430
+ const iter = {
26431
+ nextRows: Array(100),
26432
+ nextRowIndex: 100,
26433
+ next() {
26434
+ try {
26435
+ if (this.nextRowIndex === 100) {
26436
+ rowsNext.call(rows, this.nextRows);
26437
+ this.nextRowIndex = 0;
26438
+ }
26439
+ const row = this.nextRows[this.nextRowIndex];
26440
+ this.nextRows[this.nextRowIndex] = undefined;
26441
+ if (!row) {
26442
+ return { done: true };
26443
+ }
26444
+ this.nextRowIndex++;
26445
+ return { value: row, done: false };
26446
+ } catch (err) {
26447
+ throw convertError(err);
26448
+ }
26449
+ },
26450
+ [Symbol.iterator]() {
26451
+ return this;
26452
+ }
26453
+ };
26454
+ return iter;
26434
26455
  }
26435
- const params = [];
26436
- for (let i = 0;i < length; ++i) {
26437
- params.push(`$${i + 1}`);
26456
+ all(...bindParameters) {
26457
+ try {
26458
+ const result = [];
26459
+ for (const row of this.iterate(...bindParameters)) {
26460
+ if (this.pluckMode) {
26461
+ result.push(row[Object.keys(row)[0]]);
26462
+ } else {
26463
+ result.push(row);
26464
+ }
26465
+ }
26466
+ return result;
26467
+ } catch (err) {
26468
+ throw convertError(err);
26469
+ }
26438
26470
  }
26439
- return params;
26440
- }
26441
- var { hasOwnProperty } = Object.prototype;
26442
- var { apply } = Function.prototype;
26443
- var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {});
26444
- var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
26445
- var defer = (x) => () => x;
26446
- });
26447
-
26448
- // node_modules/better-sqlite3/lib/methods/inspect.js
26449
- var require_inspect = __commonJS((exports, module) => {
26450
- var DatabaseInspection = function Database() {};
26451
- module.exports = function inspect(depth, opts) {
26452
- return Object.assign(new DatabaseInspection, this);
26453
- };
26454
- });
26455
-
26456
- // node_modules/better-sqlite3/lib/database.js
26457
- var require_database = __commonJS((exports, module) => {
26458
- var fs = __require("fs");
26459
- var path = __require("path");
26460
- var util = require_util();
26461
- var SqliteError = require_sqlite_error();
26462
- var DEFAULT_ADDON;
26463
- function Database(filenameGiven, options) {
26464
- if (new.target == null) {
26465
- return new Database(filenameGiven, options);
26466
- }
26467
- let buffer;
26468
- if (Buffer.isBuffer(filenameGiven)) {
26469
- buffer = filenameGiven;
26470
- filenameGiven = ":memory:";
26471
- }
26472
- if (filenameGiven == null)
26473
- filenameGiven = "";
26474
- if (options == null)
26475
- options = {};
26476
- if (typeof filenameGiven !== "string")
26477
- throw new TypeError("Expected first argument to be a string");
26478
- if (typeof options !== "object")
26479
- throw new TypeError("Expected second argument to be an options object");
26480
- if ("readOnly" in options)
26481
- throw new TypeError('Misspelled option "readOnly" should be "readonly"');
26482
- if ("memory" in options)
26483
- throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
26484
- const filename = filenameGiven.trim();
26485
- const anonymous = filename === "" || filename === ":memory:";
26486
- const readonly = util.getBooleanOption(options, "readonly");
26487
- const fileMustExist = util.getBooleanOption(options, "fileMustExist");
26488
- const timeout = "timeout" in options ? options.timeout : 5000;
26489
- const verbose = "verbose" in options ? options.verbose : null;
26490
- const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
26491
- if (readonly && anonymous && !buffer)
26492
- throw new TypeError("In-memory/temporary databases cannot be readonly");
26493
- if (!Number.isInteger(timeout) || timeout < 0)
26494
- throw new TypeError('Expected the "timeout" option to be a positive integer');
26495
- if (timeout > 2147483647)
26496
- throw new RangeError('Option "timeout" cannot be greater than 2147483647');
26497
- if (verbose != null && typeof verbose !== "function")
26498
- throw new TypeError('Expected the "verbose" option to be a function');
26499
- if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object")
26500
- throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
26501
- let addon;
26502
- if (nativeBinding == null) {
26503
- addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
26504
- } else if (typeof nativeBinding === "string") {
26505
- const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : __require;
26506
- addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
26507
- } else {
26508
- addon = nativeBinding;
26471
+ interrupt() {
26472
+ statementInterrupt.call(this.stmt);
26509
26473
  }
26510
- if (!addon.isInitialized) {
26511
- addon.setErrorConstructor(SqliteError);
26512
- addon.isInitialized = true;
26474
+ columns() {
26475
+ return statementColumns.call(this.stmt);
26513
26476
  }
26514
- if (!anonymous && !filename.startsWith("file:") && !fs.existsSync(path.dirname(filename))) {
26515
- throw new TypeError("Cannot open database because the directory does not exist");
26477
+ safeIntegers(toggle) {
26478
+ statementSafeIntegers.call(this.stmt, toggle ?? true);
26479
+ return this;
26516
26480
  }
26517
- Object.defineProperties(this, {
26518
- [util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
26519
- ...wrappers.getters
26520
- });
26521
26481
  }
26522
- var wrappers = require_wrappers();
26523
- Database.prototype.prepare = wrappers.prepare;
26524
- Database.prototype.transaction = require_transaction();
26525
- Database.prototype.pragma = require_pragma();
26526
- Database.prototype.backup = require_backup();
26527
- Database.prototype.serialize = require_serialize();
26528
- Database.prototype.function = require_function();
26529
- Database.prototype.aggregate = require_aggregate();
26530
- Database.prototype.table = require_table();
26531
- Database.prototype.loadExtension = wrappers.loadExtension;
26532
- Database.prototype.exec = wrappers.exec;
26533
- Database.prototype.close = wrappers.close;
26534
- Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
26535
- Database.prototype.unsafeMode = wrappers.unsafeMode;
26536
- Database.prototype[util.inspect] = require_inspect();
26537
26482
  module.exports = Database;
26538
- });
26539
-
26540
- // node_modules/better-sqlite3/lib/index.js
26541
- var require_lib3 = __commonJS((exports, module) => {
26542
- module.exports = require_database();
26543
- module.exports.SqliteError = require_sqlite_error();
26483
+ module.exports.Authorization = Authorization;
26484
+ module.exports.SqliteError = SqliteError;
26544
26485
  });
26545
26486
 
26546
26487
  // src/providers/sqlite/client.ts
26547
- async function loadDatabase(filename) {
26548
- if (isBun) {
26549
- const { Database } = await import("bun:sqlite");
26550
- return new Database(filename);
26551
- } else {
26552
- const Database = (await Promise.resolve().then(() => __toESM(require_lib3(), 1))).default;
26553
- return new Database(filename);
26554
- }
26555
- }
26556
-
26557
26488
  class SQLiteClient {
26558
26489
  db;
26559
26490
  constructor() {}
26560
26491
  static async create(config6) {
26561
26492
  const client = new SQLiteClient;
26562
- client.db = await loadDatabase(config6.filename);
26493
+ client.db = new import_libsql.default(config6.filename);
26563
26494
  client.db.exec("PRAGMA foreign_keys = ON");
26564
26495
  return client;
26565
26496
  }
@@ -26591,9 +26522,9 @@ class SQLiteClient {
26591
26522
  return this.db.transaction(fn)();
26592
26523
  }
26593
26524
  }
26594
- var isBun;
26525
+ var import_libsql;
26595
26526
  var init_client = __esm(() => {
26596
- isBun = typeof globalThis.Bun !== "undefined";
26527
+ import_libsql = __toESM(require_libsql(), 1);
26597
26528
  });
26598
26529
 
26599
26530
  // src/providers/sqlite/inspector.ts
@@ -30483,7 +30414,7 @@ async function applyCommand(options, connectionStringOrConfig) {
30483
30414
  // package.json
30484
30415
  var package_default = {
30485
30416
  name: "terradb",
30486
- version: "0.5.3",
30417
+ version: "0.5.5",
30487
30418
  description: "Declarative schema management for PostgreSQL and SQLite",
30488
30419
  keywords: [
30489
30420
  "postgres",
@@ -30552,18 +30483,17 @@ var package_default = {
30552
30483
  "release:major": "bun run tools/release.ts major"
30553
30484
  },
30554
30485
  dependencies: {
30555
- "better-sqlite3": "^12.5.0",
30556
30486
  boxen: "^8.0.1",
30557
30487
  chalk: "^5.3.0",
30558
30488
  commander: "^11.1.0",
30559
30489
  diff: "^5.1.0",
30490
+ libsql: "^0.5.22",
30560
30491
  ora: "^9.0.0",
30561
30492
  pg: "^8.11.3",
30562
30493
  "pgsql-parser": "^17.8.2",
30563
30494
  "sql.js": "^1.13.0"
30564
30495
  },
30565
30496
  devDependencies: {
30566
- "@types/better-sqlite3": "^7.6.13",
30567
30497
  "@types/bun": "latest",
30568
30498
  "@types/diff": "^5.0.8",
30569
30499
  "@types/pg": "^8.10.9",