drizzle-kit 0.20.0-78ed9a3 → 0.20.0-a6a840b

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.
package/index.cjs CHANGED
@@ -4542,6 +4542,9 @@ Is ${source_default.bold.blue(
4542
4542
  });
4543
4543
 
4544
4544
  // src/global.ts
4545
+ function assertUnreachable(x) {
4546
+ throw new Error("Didn't expect to get here");
4547
+ }
4545
4548
  var originUUID, snapshotVersion;
4546
4549
  var init_global = __esm({
4547
4550
  "src/global.ts"() {
@@ -4555,7 +4558,7 @@ var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, d
4555
4558
  var init_mysqlSchema = __esm({
4556
4559
  "src/serializer/mysqlSchema.ts"() {
4557
4560
  init_global();
4558
- init_utils4();
4561
+ init_utils5();
4559
4562
  init_lib();
4560
4563
  index = objectType({
4561
4564
  name: stringType(),
@@ -4835,7 +4838,7 @@ var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, ta
4835
4838
  var init_pgSchema = __esm({
4836
4839
  "src/serializer/pgSchema.ts"() {
4837
4840
  init_global();
4838
- init_utils4();
4841
+ init_utils5();
4839
4842
  init_lib();
4840
4843
  indexV2 = objectType({
4841
4844
  name: stringType(),
@@ -5193,7 +5196,7 @@ var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dia
5193
5196
  var init_sqliteSchema = __esm({
5194
5197
  "src/serializer/sqliteSchema.ts"() {
5195
5198
  init_global();
5196
- init_utils4();
5199
+ init_utils5();
5197
5200
  init_lib();
5198
5201
  index3 = objectType({
5199
5202
  name: stringType(),
@@ -11376,9 +11379,6 @@ var init_utils = __esm({
11376
11379
  readDrizzleConfig = async (configPath) => {
11377
11380
  const defaultTsConfigExists = (0, import_fs.existsSync)((0, import_path.join)((0, import_path.resolve)("drizzle.config.ts")));
11378
11381
  const defaultJsConfigExists = (0, import_fs.existsSync)((0, import_path.join)((0, import_path.resolve)("drizzle.config.js")));
11379
- const defaultJsonConfigExists = (0, import_fs.existsSync)(
11380
- (0, import_path.join)((0, import_path.resolve)("drizzle.config.json"))
11381
- );
11382
11382
  const defaultConfigPath = defaultTsConfigExists ? "drizzle.config.ts" : defaultJsConfigExists ? "drizzle.config.js" : "drizzle.config.json";
11383
11383
  if (configPath) {
11384
11384
  console.log(
@@ -11483,7 +11483,7 @@ var init_outputs = __esm({
11483
11483
  connection: {
11484
11484
  driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
11485
11485
  required: () => withStyle.error(
11486
- `Either "connectionString" or "host", "database" are required for database connection`
11486
+ `Either "uri" or "host", "database" are required for database connection`
11487
11487
  )
11488
11488
  }
11489
11489
  },
@@ -12701,7 +12701,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
12701
12701
  }
12702
12702
  }
12703
12703
  };
12704
- toDrizzle = (schema4) => {
12704
+ toDrizzle = (schema4, schemaName) => {
12705
12705
  const tables = {};
12706
12706
  Object.values(schema4.tables).forEach((t) => {
12707
12707
  const columns = {};
@@ -12775,17 +12775,31 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
12775
12775
  }
12776
12776
  columns[columnName] = columnBuilder;
12777
12777
  });
12778
- tables[t.name] = (0, import_pg_core2.pgTable)(t.name, columns, (cb) => {
12779
- const res = {};
12780
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12781
- const gh = cpk.columns.map((c) => cb[c]);
12782
- res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12783
- gh,
12784
- cpk.name
12785
- );
12778
+ if (schemaName === "public") {
12779
+ tables[t.name] = (0, import_pg_core2.pgTable)(t.name, columns, (cb) => {
12780
+ const res = {};
12781
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12782
+ const gh = cpk.columns.map((c) => cb[c]);
12783
+ res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12784
+ gh,
12785
+ cpk.name
12786
+ );
12787
+ });
12788
+ return res;
12786
12789
  });
12787
- return res;
12788
- });
12790
+ } else {
12791
+ tables[t.name] = (0, import_pg_core2.pgSchema)(schemaName).table(t.name, columns, (cb) => {
12792
+ const res = {};
12793
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12794
+ const gh = cpk.columns.map((c) => cb[c]);
12795
+ res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12796
+ gh,
12797
+ cpk.name
12798
+ );
12799
+ });
12800
+ return res;
12801
+ });
12802
+ }
12789
12803
  });
12790
12804
  return tables;
12791
12805
  };
@@ -14801,7 +14815,7 @@ var init_migrate = __esm({
14801
14815
  init_pgSchema();
14802
14816
  init_sqliteSchema();
14803
14817
  init_mysqlSchema();
14804
- init_utils4();
14818
+ init_utils5();
14805
14819
  init_words();
14806
14820
  init_outputs();
14807
14821
  prepareAndMigratePg = async (config) => {
@@ -17175,7 +17189,7 @@ var init_snapshotsDiffer = __esm({
17175
17189
  init_lib();
17176
17190
  init_jsonDiffer();
17177
17191
  init_jsonStatements();
17178
- init_utils4();
17192
+ init_utils5();
17179
17193
  init_sqliteSchema();
17180
17194
  init_mysqlSchema();
17181
17195
  makeChanged = (schema4) => {
@@ -17797,7 +17811,7 @@ var init_pgUp = __esm({
17797
17811
  import_fs5 = require("fs");
17798
17812
  init_global();
17799
17813
  init_pgSchema();
17800
- init_utils4();
17814
+ init_utils5();
17801
17815
  upPgHandlerV4toV5 = (obj) => {
17802
17816
  const mappedTables = {};
17803
17817
  for (const [key, table4] of Object.entries(obj.tables)) {
@@ -18034,7 +18048,7 @@ var init_mysqlUp = __esm({
18034
18048
  init_source();
18035
18049
  import_fs6 = __toESM(require("fs"));
18036
18050
  init_mysqlSchema();
18037
- init_utils4();
18051
+ init_utils5();
18038
18052
  upMysqlHandler = (out) => {
18039
18053
  };
18040
18054
  upMySqlHandlerV4toV5 = (obj) => {
@@ -18147,7 +18161,7 @@ var init_upFolders = __esm({
18147
18161
  init_mysqlSchema();
18148
18162
  init_sqliteSchema();
18149
18163
  init_snapshotsDiffer();
18150
- init_utils4();
18164
+ init_utils5();
18151
18165
  init_words();
18152
18166
  init_pgUp();
18153
18167
  init_pgSchema();
@@ -21582,9 +21596,9 @@ var require_pg_types = __commonJS({
21582
21596
  }
21583
21597
  });
21584
21598
 
21585
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/defaults.js
21599
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/defaults.js
21586
21600
  var require_defaults = __commonJS({
21587
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/defaults.js"(exports, module2) {
21601
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/defaults.js"(exports, module2) {
21588
21602
  "use strict";
21589
21603
  module2.exports = {
21590
21604
  // database host. defaults to localhost
@@ -21644,11 +21658,10 @@ var require_defaults = __commonJS({
21644
21658
  }
21645
21659
  });
21646
21660
 
21647
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/utils.js
21661
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/utils.js
21648
21662
  var require_utils2 = __commonJS({
21649
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/utils.js"(exports, module2) {
21663
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/utils.js"(exports, module2) {
21650
21664
  "use strict";
21651
- var crypto = require("crypto");
21652
21665
  var defaults3 = require_defaults();
21653
21666
  function escapeElement(elementRepresentation) {
21654
21667
  var escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
@@ -21763,30 +21776,138 @@ var require_utils2 = __commonJS({
21763
21776
  }
21764
21777
  return config;
21765
21778
  }
21766
- var md5 = function(string) {
21767
- return crypto.createHash("md5").update(string, "utf-8").digest("hex");
21779
+ var escapeIdentifier = function(str) {
21780
+ return '"' + str.replace(/"/g, '""') + '"';
21768
21781
  };
21769
- var postgresMd5PasswordHash = function(user, password, salt) {
21770
- var inner = md5(password + user);
21771
- var outer = md5(Buffer.concat([Buffer.from(inner), salt]));
21772
- return "md5" + outer;
21782
+ var escapeLiteral = function(str) {
21783
+ var hasBackslash = false;
21784
+ var escaped = "'";
21785
+ for (var i = 0; i < str.length; i++) {
21786
+ var c = str[i];
21787
+ if (c === "'") {
21788
+ escaped += c + c;
21789
+ } else if (c === "\\") {
21790
+ escaped += c + c;
21791
+ hasBackslash = true;
21792
+ } else {
21793
+ escaped += c;
21794
+ }
21795
+ }
21796
+ escaped += "'";
21797
+ if (hasBackslash === true) {
21798
+ escaped = " E" + escaped;
21799
+ }
21800
+ return escaped;
21773
21801
  };
21774
21802
  module2.exports = {
21775
21803
  prepareValue: function prepareValueWrapper(value) {
21776
21804
  return prepareValue(value);
21777
21805
  },
21778
21806
  normalizeQueryConfig,
21807
+ escapeIdentifier,
21808
+ escapeLiteral
21809
+ };
21810
+ }
21811
+ });
21812
+
21813
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/crypto/utils-legacy.js
21814
+ var require_utils_legacy = __commonJS({
21815
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/crypto/utils-legacy.js"(exports, module2) {
21816
+ "use strict";
21817
+ var nodeCrypto = require("crypto");
21818
+ function md5(string) {
21819
+ return nodeCrypto.createHash("md5").update(string, "utf-8").digest("hex");
21820
+ }
21821
+ function postgresMd5PasswordHash(user, password, salt) {
21822
+ var inner = md5(password + user);
21823
+ var outer = md5(Buffer.concat([Buffer.from(inner), salt]));
21824
+ return "md5" + outer;
21825
+ }
21826
+ function sha256(text) {
21827
+ return nodeCrypto.createHash("sha256").update(text).digest();
21828
+ }
21829
+ function hmacSha256(key, msg) {
21830
+ return nodeCrypto.createHmac("sha256", key).update(msg).digest();
21831
+ }
21832
+ async function deriveKey(password, salt, iterations) {
21833
+ return nodeCrypto.pbkdf2Sync(password, salt, iterations, 32, "sha256");
21834
+ }
21835
+ module2.exports = {
21779
21836
  postgresMd5PasswordHash,
21837
+ randomBytes: nodeCrypto.randomBytes,
21838
+ deriveKey,
21839
+ sha256,
21840
+ hmacSha256,
21780
21841
  md5
21781
21842
  };
21782
21843
  }
21783
21844
  });
21784
21845
 
21785
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/sasl.js
21846
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/crypto/utils-webcrypto.js
21847
+ var require_utils_webcrypto = __commonJS({
21848
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/crypto/utils-webcrypto.js"(exports, module2) {
21849
+ var nodeCrypto = require("crypto");
21850
+ module2.exports = {
21851
+ postgresMd5PasswordHash,
21852
+ randomBytes,
21853
+ deriveKey,
21854
+ sha256,
21855
+ hmacSha256,
21856
+ md5
21857
+ };
21858
+ var webCrypto = nodeCrypto.webcrypto || globalThis.crypto;
21859
+ var subtleCrypto = webCrypto.subtle;
21860
+ var textEncoder = new TextEncoder();
21861
+ function randomBytes(length) {
21862
+ return webCrypto.getRandomValues(Buffer.alloc(length));
21863
+ }
21864
+ async function md5(string) {
21865
+ try {
21866
+ return nodeCrypto.createHash("md5").update(string, "utf-8").digest("hex");
21867
+ } catch (e) {
21868
+ const data = typeof string === "string" ? textEncoder.encode(string) : string;
21869
+ const hash = await subtleCrypto.digest("MD5", data);
21870
+ return Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("");
21871
+ }
21872
+ }
21873
+ async function postgresMd5PasswordHash(user, password, salt) {
21874
+ var inner = await md5(password + user);
21875
+ var outer = await md5(Buffer.concat([Buffer.from(inner), salt]));
21876
+ return "md5" + outer;
21877
+ }
21878
+ async function sha256(text) {
21879
+ return await subtleCrypto.digest("SHA-256", text);
21880
+ }
21881
+ async function hmacSha256(keyBuffer, msg) {
21882
+ const key = await subtleCrypto.importKey("raw", keyBuffer, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
21883
+ return await subtleCrypto.sign("HMAC", key, textEncoder.encode(msg));
21884
+ }
21885
+ async function deriveKey(password, salt, iterations) {
21886
+ const key = await subtleCrypto.importKey("raw", textEncoder.encode(password), "PBKDF2", false, ["deriveBits"]);
21887
+ const params = { name: "PBKDF2", hash: "SHA-256", salt, iterations };
21888
+ return await subtleCrypto.deriveBits(params, key, 32 * 8, ["deriveBits"]);
21889
+ }
21890
+ }
21891
+ });
21892
+
21893
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/crypto/utils.js
21894
+ var require_utils3 = __commonJS({
21895
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/crypto/utils.js"(exports, module2) {
21896
+ "use strict";
21897
+ var useLegacyCrypto = parseInt(process.versions && process.versions.node && process.versions.node.split(".")[0]) < 15;
21898
+ if (useLegacyCrypto) {
21899
+ module2.exports = require_utils_legacy();
21900
+ } else {
21901
+ module2.exports = require_utils_webcrypto();
21902
+ }
21903
+ }
21904
+ });
21905
+
21906
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/crypto/sasl.js
21786
21907
  var require_sasl = __commonJS({
21787
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/sasl.js"(exports, module2) {
21908
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/crypto/sasl.js"(exports, module2) {
21788
21909
  "use strict";
21789
- var crypto = require("crypto");
21910
+ var crypto = require_utils3();
21790
21911
  function startSession(mechanisms) {
21791
21912
  if (mechanisms.indexOf("SCRAM-SHA-256") === -1) {
21792
21913
  throw new Error("SASL: Only mechanism SCRAM-SHA-256 is currently supported");
@@ -21799,13 +21920,16 @@ var require_sasl = __commonJS({
21799
21920
  message: "SASLInitialResponse"
21800
21921
  };
21801
21922
  }
21802
- function continueSession(session, password, serverData) {
21923
+ async function continueSession(session, password, serverData) {
21803
21924
  if (session.message !== "SASLInitialResponse") {
21804
21925
  throw new Error("SASL: Last message was not SASLInitialResponse");
21805
21926
  }
21806
21927
  if (typeof password !== "string") {
21807
21928
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string");
21808
21929
  }
21930
+ if (password === "") {
21931
+ throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string");
21932
+ }
21809
21933
  if (typeof serverData !== "string") {
21810
21934
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: serverData must be a string");
21811
21935
  }
@@ -21815,21 +21939,20 @@ var require_sasl = __commonJS({
21815
21939
  } else if (sv.nonce.length === session.clientNonce.length) {
21816
21940
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce is too short");
21817
21941
  }
21818
- var saltBytes = Buffer.from(sv.salt, "base64");
21819
- var saltedPassword = Hi(password, saltBytes, sv.iteration);
21820
- var clientKey = hmacSha256(saltedPassword, "Client Key");
21821
- var storedKey = sha256(clientKey);
21822
21942
  var clientFirstMessageBare = "n=*,r=" + session.clientNonce;
21823
21943
  var serverFirstMessage = "r=" + sv.nonce + ",s=" + sv.salt + ",i=" + sv.iteration;
21824
21944
  var clientFinalMessageWithoutProof = "c=biws,r=" + sv.nonce;
21825
21945
  var authMessage = clientFirstMessageBare + "," + serverFirstMessage + "," + clientFinalMessageWithoutProof;
21826
- var clientSignature = hmacSha256(storedKey, authMessage);
21827
- var clientProofBytes = xorBuffers(clientKey, clientSignature);
21828
- var clientProof = clientProofBytes.toString("base64");
21829
- var serverKey = hmacSha256(saltedPassword, "Server Key");
21830
- var serverSignatureBytes = hmacSha256(serverKey, authMessage);
21946
+ var saltBytes = Buffer.from(sv.salt, "base64");
21947
+ var saltedPassword = await crypto.deriveKey(password, saltBytes, sv.iteration);
21948
+ var clientKey = await crypto.hmacSha256(saltedPassword, "Client Key");
21949
+ var storedKey = await crypto.sha256(clientKey);
21950
+ var clientSignature = await crypto.hmacSha256(storedKey, authMessage);
21951
+ var clientProof = xorBuffers(Buffer.from(clientKey), Buffer.from(clientSignature)).toString("base64");
21952
+ var serverKey = await crypto.hmacSha256(saltedPassword, "Server Key");
21953
+ var serverSignatureBytes = await crypto.hmacSha256(serverKey, authMessage);
21831
21954
  session.message = "SASLResponse";
21832
- session.serverSignature = serverSignatureBytes.toString("base64");
21955
+ session.serverSignature = Buffer.from(serverSignatureBytes).toString("base64");
21833
21956
  session.response = clientFinalMessageWithoutProof + ",p=" + clientProof;
21834
21957
  }
21835
21958
  function finalizeSession(session, serverData) {
@@ -21922,21 +22045,6 @@ var require_sasl = __commonJS({
21922
22045
  }
21923
22046
  return Buffer.from(a.map((_, i) => a[i] ^ b[i]));
21924
22047
  }
21925
- function sha256(text) {
21926
- return crypto.createHash("sha256").update(text).digest();
21927
- }
21928
- function hmacSha256(key, msg) {
21929
- return crypto.createHmac("sha256", key).update(msg).digest();
21930
- }
21931
- function Hi(password, saltBytes, iterations) {
21932
- var ui1 = hmacSha256(password, Buffer.concat([saltBytes, Buffer.from([0, 0, 0, 1])]));
21933
- var ui = ui1;
21934
- for (var i = 0; i < iterations - 1; i++) {
21935
- ui1 = hmacSha256(password, ui1);
21936
- ui = xorBuffers(ui, ui1);
21937
- }
21938
- return ui;
21939
- }
21940
22048
  module2.exports = {
21941
22049
  startSession,
21942
22050
  continueSession,
@@ -21945,303 +22053,9 @@ var require_sasl = __commonJS({
21945
22053
  }
21946
22054
  });
21947
22055
 
21948
- // node_modules/.pnpm/split2@4.2.0/node_modules/split2/index.js
21949
- var require_split2 = __commonJS({
21950
- "node_modules/.pnpm/split2@4.2.0/node_modules/split2/index.js"(exports, module2) {
21951
- "use strict";
21952
- var { Transform: Transform2 } = require("stream");
21953
- var { StringDecoder } = require("string_decoder");
21954
- var kLast = Symbol("last");
21955
- var kDecoder = Symbol("decoder");
21956
- function transform(chunk, enc, cb) {
21957
- let list;
21958
- if (this.overflow) {
21959
- const buf = this[kDecoder].write(chunk);
21960
- list = buf.split(this.matcher);
21961
- if (list.length === 1)
21962
- return cb();
21963
- list.shift();
21964
- this.overflow = false;
21965
- } else {
21966
- this[kLast] += this[kDecoder].write(chunk);
21967
- list = this[kLast].split(this.matcher);
21968
- }
21969
- this[kLast] = list.pop();
21970
- for (let i = 0; i < list.length; i++) {
21971
- try {
21972
- push(this, this.mapper(list[i]));
21973
- } catch (error2) {
21974
- return cb(error2);
21975
- }
21976
- }
21977
- this.overflow = this[kLast].length > this.maxLength;
21978
- if (this.overflow && !this.skipOverflow) {
21979
- cb(new Error("maximum buffer reached"));
21980
- return;
21981
- }
21982
- cb();
21983
- }
21984
- function flush(cb) {
21985
- this[kLast] += this[kDecoder].end();
21986
- if (this[kLast]) {
21987
- try {
21988
- push(this, this.mapper(this[kLast]));
21989
- } catch (error2) {
21990
- return cb(error2);
21991
- }
21992
- }
21993
- cb();
21994
- }
21995
- function push(self2, val) {
21996
- if (val !== void 0) {
21997
- self2.push(val);
21998
- }
21999
- }
22000
- function noop2(incoming) {
22001
- return incoming;
22002
- }
22003
- function split(matcher, mapper, options) {
22004
- matcher = matcher || /\r?\n/;
22005
- mapper = mapper || noop2;
22006
- options = options || {};
22007
- switch (arguments.length) {
22008
- case 1:
22009
- if (typeof matcher === "function") {
22010
- mapper = matcher;
22011
- matcher = /\r?\n/;
22012
- } else if (typeof matcher === "object" && !(matcher instanceof RegExp) && !matcher[Symbol.split]) {
22013
- options = matcher;
22014
- matcher = /\r?\n/;
22015
- }
22016
- break;
22017
- case 2:
22018
- if (typeof matcher === "function") {
22019
- options = mapper;
22020
- mapper = matcher;
22021
- matcher = /\r?\n/;
22022
- } else if (typeof mapper === "object") {
22023
- options = mapper;
22024
- mapper = noop2;
22025
- }
22026
- }
22027
- options = Object.assign({}, options);
22028
- options.autoDestroy = true;
22029
- options.transform = transform;
22030
- options.flush = flush;
22031
- options.readableObjectMode = true;
22032
- const stream = new Transform2(options);
22033
- stream[kLast] = "";
22034
- stream[kDecoder] = new StringDecoder("utf8");
22035
- stream.matcher = matcher;
22036
- stream.mapper = mapper;
22037
- stream.maxLength = options.maxLength;
22038
- stream.skipOverflow = options.skipOverflow || false;
22039
- stream.overflow = false;
22040
- stream._destroy = function(err2, cb) {
22041
- this._writableState.errorEmitted = false;
22042
- cb(err2);
22043
- };
22044
- return stream;
22045
- }
22046
- module2.exports = split;
22047
- }
22048
- });
22049
-
22050
- // node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/helper.js
22051
- var require_helper = __commonJS({
22052
- "node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/helper.js"(exports, module2) {
22053
- "use strict";
22054
- var path4 = require("path");
22055
- var Stream = require("stream").Stream;
22056
- var split = require_split2();
22057
- var util2 = require("util");
22058
- var defaultPort = 5432;
22059
- var isWin = process.platform === "win32";
22060
- var warnStream = process.stderr;
22061
- var S_IRWXG = 56;
22062
- var S_IRWXO = 7;
22063
- var S_IFMT = 61440;
22064
- var S_IFREG = 32768;
22065
- function isRegFile(mode) {
22066
- return (mode & S_IFMT) == S_IFREG;
22067
- }
22068
- var fieldNames = ["host", "port", "database", "user", "password"];
22069
- var nrOfFields = fieldNames.length;
22070
- var passKey = fieldNames[nrOfFields - 1];
22071
- function warn() {
22072
- var isWritable = warnStream instanceof Stream && true === warnStream.writable;
22073
- if (isWritable) {
22074
- var args = Array.prototype.slice.call(arguments).concat("\n");
22075
- warnStream.write(util2.format.apply(util2, args));
22076
- }
22077
- }
22078
- Object.defineProperty(module2.exports, "isWin", {
22079
- get: function() {
22080
- return isWin;
22081
- },
22082
- set: function(val) {
22083
- isWin = val;
22084
- }
22085
- });
22086
- module2.exports.warnTo = function(stream) {
22087
- var old = warnStream;
22088
- warnStream = stream;
22089
- return old;
22090
- };
22091
- module2.exports.getFileName = function(rawEnv) {
22092
- var env2 = rawEnv || process.env;
22093
- var file = env2.PGPASSFILE || (isWin ? path4.join(env2.APPDATA || "./", "postgresql", "pgpass.conf") : path4.join(env2.HOME || "./", ".pgpass"));
22094
- return file;
22095
- };
22096
- module2.exports.usePgPass = function(stats, fname) {
22097
- if (Object.prototype.hasOwnProperty.call(process.env, "PGPASSWORD")) {
22098
- return false;
22099
- }
22100
- if (isWin) {
22101
- return true;
22102
- }
22103
- fname = fname || "<unkn>";
22104
- if (!isRegFile(stats.mode)) {
22105
- warn('WARNING: password file "%s" is not a plain file', fname);
22106
- return false;
22107
- }
22108
- if (stats.mode & (S_IRWXG | S_IRWXO)) {
22109
- warn('WARNING: password file "%s" has group or world access; permissions should be u=rw (0600) or less', fname);
22110
- return false;
22111
- }
22112
- return true;
22113
- };
22114
- var matcher = module2.exports.match = function(connInfo, entry) {
22115
- return fieldNames.slice(0, -1).reduce(function(prev, field, idx) {
22116
- if (idx == 1) {
22117
- if (Number(connInfo[field] || defaultPort) === Number(entry[field])) {
22118
- return prev && true;
22119
- }
22120
- }
22121
- return prev && (entry[field] === "*" || entry[field] === connInfo[field]);
22122
- }, true);
22123
- };
22124
- module2.exports.getPassword = function(connInfo, stream, cb) {
22125
- var pass;
22126
- var lineStream = stream.pipe(split());
22127
- function onLine(line) {
22128
- var entry = parseLine(line);
22129
- if (entry && isValidEntry(entry) && matcher(connInfo, entry)) {
22130
- pass = entry[passKey];
22131
- lineStream.end();
22132
- }
22133
- }
22134
- var onEnd = function() {
22135
- stream.destroy();
22136
- cb(pass);
22137
- };
22138
- var onErr = function(err2) {
22139
- stream.destroy();
22140
- warn("WARNING: error on reading file: %s", err2);
22141
- cb(void 0);
22142
- };
22143
- stream.on("error", onErr);
22144
- lineStream.on("data", onLine).on("end", onEnd).on("error", onErr);
22145
- };
22146
- var parseLine = module2.exports.parseLine = function(line) {
22147
- if (line.length < 11 || line.match(/^\s+#/)) {
22148
- return null;
22149
- }
22150
- var curChar = "";
22151
- var prevChar = "";
22152
- var fieldIdx = 0;
22153
- var startIdx = 0;
22154
- var endIdx = 0;
22155
- var obj = {};
22156
- var isLastField = false;
22157
- var addToObj = function(idx, i0, i1) {
22158
- var field = line.substring(i0, i1);
22159
- if (!Object.hasOwnProperty.call(process.env, "PGPASS_NO_DEESCAPE")) {
22160
- field = field.replace(/\\([:\\])/g, "$1");
22161
- }
22162
- obj[fieldNames[idx]] = field;
22163
- };
22164
- for (var i = 0; i < line.length - 1; i += 1) {
22165
- curChar = line.charAt(i + 1);
22166
- prevChar = line.charAt(i);
22167
- isLastField = fieldIdx == nrOfFields - 1;
22168
- if (isLastField) {
22169
- addToObj(fieldIdx, startIdx);
22170
- break;
22171
- }
22172
- if (i >= 0 && curChar == ":" && prevChar !== "\\") {
22173
- addToObj(fieldIdx, startIdx, i + 1);
22174
- startIdx = i + 2;
22175
- fieldIdx += 1;
22176
- }
22177
- }
22178
- obj = Object.keys(obj).length === nrOfFields ? obj : null;
22179
- return obj;
22180
- };
22181
- var isValidEntry = module2.exports.isValidEntry = function(entry) {
22182
- var rules = {
22183
- // host
22184
- 0: function(x) {
22185
- return x.length > 0;
22186
- },
22187
- // port
22188
- 1: function(x) {
22189
- if (x === "*") {
22190
- return true;
22191
- }
22192
- x = Number(x);
22193
- return isFinite(x) && x > 0 && x < 9007199254740992 && Math.floor(x) === x;
22194
- },
22195
- // database
22196
- 2: function(x) {
22197
- return x.length > 0;
22198
- },
22199
- // username
22200
- 3: function(x) {
22201
- return x.length > 0;
22202
- },
22203
- // password
22204
- 4: function(x) {
22205
- return x.length > 0;
22206
- }
22207
- };
22208
- for (var idx = 0; idx < fieldNames.length; idx += 1) {
22209
- var rule = rules[idx];
22210
- var value = entry[fieldNames[idx]] || "";
22211
- var res = rule(value);
22212
- if (!res) {
22213
- return false;
22214
- }
22215
- }
22216
- return true;
22217
- };
22218
- }
22219
- });
22220
-
22221
- // node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js
22222
- var require_lib = __commonJS({
22223
- "node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js"(exports, module2) {
22224
- "use strict";
22225
- var path4 = require("path");
22226
- var fs8 = require("fs");
22227
- var helper = require_helper();
22228
- module2.exports = function(connInfo, cb) {
22229
- var file = helper.getFileName();
22230
- fs8.stat(file, function(err2, stat) {
22231
- if (err2 || !helper.usePgPass(stat, file)) {
22232
- return cb(void 0);
22233
- }
22234
- var st = fs8.createReadStream(file);
22235
- helper.getPassword(connInfo, st, cb);
22236
- });
22237
- };
22238
- module2.exports.warnTo = helper.warnTo;
22239
- }
22240
- });
22241
-
22242
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/type-overrides.js
22056
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/type-overrides.js
22243
22057
  var require_type_overrides = __commonJS({
22244
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/type-overrides.js"(exports, module2) {
22058
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/type-overrides.js"(exports, module2) {
22245
22059
  "use strict";
22246
22060
  var types = require_pg_types();
22247
22061
  function TypeOverrides(userTypes) {
@@ -22359,9 +22173,9 @@ var require_pg_connection_string = __commonJS({
22359
22173
  }
22360
22174
  });
22361
22175
 
22362
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection-parameters.js
22176
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/connection-parameters.js
22363
22177
  var require_connection_parameters = __commonJS({
22364
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection-parameters.js"(exports, module2) {
22178
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/connection-parameters.js"(exports, module2) {
22365
22179
  "use strict";
22366
22180
  var dns = require("dns");
22367
22181
  var defaults3 = require_defaults();
@@ -22498,9 +22312,9 @@ var require_connection_parameters = __commonJS({
22498
22312
  }
22499
22313
  });
22500
22314
 
22501
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/result.js
22315
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/result.js
22502
22316
  var require_result = __commonJS({
22503
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/result.js"(exports, module2) {
22317
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/result.js"(exports, module2) {
22504
22318
  "use strict";
22505
22319
  var types = require_pg_types();
22506
22320
  var matchRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/;
@@ -22518,6 +22332,7 @@ var require_result = __commonJS({
22518
22332
  if (this.rowAsArray) {
22519
22333
  this.parseRow = this._parseRowAsArray;
22520
22334
  }
22335
+ this._prebuiltEmptyResultObject = null;
22521
22336
  }
22522
22337
  // adds a command complete message
22523
22338
  addCommandComplete(msg) {
@@ -22550,14 +22365,12 @@ var require_result = __commonJS({
22550
22365
  return row;
22551
22366
  }
22552
22367
  parseRow(rowData) {
22553
- var row = {};
22368
+ var row = { ...this._prebuiltEmptyResultObject };
22554
22369
  for (var i = 0, len = rowData.length; i < len; i++) {
22555
22370
  var rawValue = rowData[i];
22556
22371
  var field = this.fields[i].name;
22557
22372
  if (rawValue !== null) {
22558
22373
  row[field] = this._parsers[i](rawValue);
22559
- } else {
22560
- row[field] = null;
22561
22374
  }
22562
22375
  }
22563
22376
  return row;
@@ -22578,15 +22391,23 @@ var require_result = __commonJS({
22578
22391
  this._parsers[i] = types.getTypeParser(desc.dataTypeID, desc.format || "text");
22579
22392
  }
22580
22393
  }
22394
+ this._createPrebuiltEmptyResultObject();
22395
+ }
22396
+ _createPrebuiltEmptyResultObject() {
22397
+ var row = {};
22398
+ for (var i = 0; i < this.fields.length; i++) {
22399
+ row[this.fields[i].name] = null;
22400
+ }
22401
+ this._prebuiltEmptyResultObject = { ...row };
22581
22402
  }
22582
22403
  };
22583
22404
  module2.exports = Result;
22584
22405
  }
22585
22406
  });
22586
22407
 
22587
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/query.js
22408
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/query.js
22588
22409
  var require_query = __commonJS({
22589
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/query.js"(exports, module2) {
22410
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/query.js"(exports, module2) {
22590
22411
  "use strict";
22591
22412
  var { EventEmitter } = require("events");
22592
22413
  var Result = require_result();
@@ -23612,13 +23433,50 @@ var require_dist = __commonJS({
23612
23433
  }
23613
23434
  });
23614
23435
 
23615
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection.js
23436
+ // node_modules/.pnpm/pg-cloudflare@1.1.1/node_modules/pg-cloudflare/dist/empty.js
23437
+ var empty_exports = {};
23438
+ __export(empty_exports, {
23439
+ default: () => empty_default
23440
+ });
23441
+ var empty_default;
23442
+ var init_empty = __esm({
23443
+ "node_modules/.pnpm/pg-cloudflare@1.1.1/node_modules/pg-cloudflare/dist/empty.js"() {
23444
+ empty_default = {};
23445
+ }
23446
+ });
23447
+
23448
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/stream.js
23449
+ var require_stream = __commonJS({
23450
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/stream.js"(exports, module2) {
23451
+ module2.exports.getStream = function getStream(ssl) {
23452
+ const net = require("net");
23453
+ if (typeof net.Socket === "function") {
23454
+ return new net.Socket();
23455
+ } else {
23456
+ const { CloudflareSocket } = (init_empty(), __toCommonJS(empty_exports));
23457
+ return new CloudflareSocket(ssl);
23458
+ }
23459
+ };
23460
+ module2.exports.getSecureStream = function getSecureStream(options) {
23461
+ var tls = require("tls");
23462
+ if (tls.connect) {
23463
+ return tls.connect(options);
23464
+ } else {
23465
+ options.socket.startTls(options);
23466
+ return options.socket;
23467
+ }
23468
+ };
23469
+ }
23470
+ });
23471
+
23472
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/connection.js
23616
23473
  var require_connection = __commonJS({
23617
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection.js"(exports, module2) {
23474
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/connection.js"(exports, module2) {
23618
23475
  "use strict";
23619
23476
  var net = require("net");
23620
23477
  var EventEmitter = require("events").EventEmitter;
23621
23478
  var { parse, serialize } = require_dist();
23479
+ var { getStream, getSecureStream } = require_stream();
23622
23480
  var flushBuffer = serialize.flush();
23623
23481
  var syncBuffer = serialize.sync();
23624
23482
  var endBuffer = serialize.end();
@@ -23626,7 +23484,10 @@ var require_connection = __commonJS({
23626
23484
  constructor(config) {
23627
23485
  super();
23628
23486
  config = config || {};
23629
- this.stream = config.stream || new net.Socket();
23487
+ this.stream = config.stream || getStream(config.ssl);
23488
+ if (typeof this.stream === "function") {
23489
+ this.stream = this.stream(config);
23490
+ }
23630
23491
  this._keepAlive = config.keepAlive;
23631
23492
  this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis;
23632
23493
  this.lastBuffer = false;
@@ -23677,7 +23538,6 @@ var require_connection = __commonJS({
23677
23538
  self2.stream.end();
23678
23539
  return self2.emit("error", new Error("There was an error establishing an SSL connection"));
23679
23540
  }
23680
- var tls = require("tls");
23681
23541
  const options = {
23682
23542
  socket: self2.stream
23683
23543
  };
@@ -23687,11 +23547,12 @@ var require_connection = __commonJS({
23687
23547
  options.key = self2.ssl.key;
23688
23548
  }
23689
23549
  }
23690
- if (net.isIP(host) === 0) {
23550
+ var net2 = require("net");
23551
+ if (net2.isIP && net2.isIP(host) === 0) {
23691
23552
  options.servername = host;
23692
23553
  }
23693
23554
  try {
23694
- self2.stream = tls.connect(options);
23555
+ self2.stream = getSecureStream(options);
23695
23556
  } catch (err2) {
23696
23557
  return self2.emit("error", err2);
23697
23558
  }
@@ -23701,9 +23562,6 @@ var require_connection = __commonJS({
23701
23562
  });
23702
23563
  }
23703
23564
  attachListeners(stream) {
23704
- stream.on("end", () => {
23705
- this.emit("end");
23706
- });
23707
23565
  parse(stream, (msg) => {
23708
23566
  var eventName = msg.name === "error" ? "errorMessage" : msg.name;
23709
23567
  if (this._emitMessage) {
@@ -23758,7 +23616,6 @@ var require_connection = __commonJS({
23758
23616
  }
23759
23617
  sync() {
23760
23618
  this._ending = true;
23761
- this._send(flushBuffer);
23762
23619
  this._send(syncBuffer);
23763
23620
  }
23764
23621
  ref() {
@@ -23797,20 +23654,313 @@ var require_connection = __commonJS({
23797
23654
  }
23798
23655
  });
23799
23656
 
23800
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/client.js
23657
+ // node_modules/.pnpm/split2@4.2.0/node_modules/split2/index.js
23658
+ var require_split2 = __commonJS({
23659
+ "node_modules/.pnpm/split2@4.2.0/node_modules/split2/index.js"(exports, module2) {
23660
+ "use strict";
23661
+ var { Transform: Transform2 } = require("stream");
23662
+ var { StringDecoder } = require("string_decoder");
23663
+ var kLast = Symbol("last");
23664
+ var kDecoder = Symbol("decoder");
23665
+ function transform(chunk, enc, cb) {
23666
+ let list;
23667
+ if (this.overflow) {
23668
+ const buf = this[kDecoder].write(chunk);
23669
+ list = buf.split(this.matcher);
23670
+ if (list.length === 1)
23671
+ return cb();
23672
+ list.shift();
23673
+ this.overflow = false;
23674
+ } else {
23675
+ this[kLast] += this[kDecoder].write(chunk);
23676
+ list = this[kLast].split(this.matcher);
23677
+ }
23678
+ this[kLast] = list.pop();
23679
+ for (let i = 0; i < list.length; i++) {
23680
+ try {
23681
+ push(this, this.mapper(list[i]));
23682
+ } catch (error2) {
23683
+ return cb(error2);
23684
+ }
23685
+ }
23686
+ this.overflow = this[kLast].length > this.maxLength;
23687
+ if (this.overflow && !this.skipOverflow) {
23688
+ cb(new Error("maximum buffer reached"));
23689
+ return;
23690
+ }
23691
+ cb();
23692
+ }
23693
+ function flush(cb) {
23694
+ this[kLast] += this[kDecoder].end();
23695
+ if (this[kLast]) {
23696
+ try {
23697
+ push(this, this.mapper(this[kLast]));
23698
+ } catch (error2) {
23699
+ return cb(error2);
23700
+ }
23701
+ }
23702
+ cb();
23703
+ }
23704
+ function push(self2, val) {
23705
+ if (val !== void 0) {
23706
+ self2.push(val);
23707
+ }
23708
+ }
23709
+ function noop2(incoming) {
23710
+ return incoming;
23711
+ }
23712
+ function split(matcher, mapper, options) {
23713
+ matcher = matcher || /\r?\n/;
23714
+ mapper = mapper || noop2;
23715
+ options = options || {};
23716
+ switch (arguments.length) {
23717
+ case 1:
23718
+ if (typeof matcher === "function") {
23719
+ mapper = matcher;
23720
+ matcher = /\r?\n/;
23721
+ } else if (typeof matcher === "object" && !(matcher instanceof RegExp) && !matcher[Symbol.split]) {
23722
+ options = matcher;
23723
+ matcher = /\r?\n/;
23724
+ }
23725
+ break;
23726
+ case 2:
23727
+ if (typeof matcher === "function") {
23728
+ options = mapper;
23729
+ mapper = matcher;
23730
+ matcher = /\r?\n/;
23731
+ } else if (typeof mapper === "object") {
23732
+ options = mapper;
23733
+ mapper = noop2;
23734
+ }
23735
+ }
23736
+ options = Object.assign({}, options);
23737
+ options.autoDestroy = true;
23738
+ options.transform = transform;
23739
+ options.flush = flush;
23740
+ options.readableObjectMode = true;
23741
+ const stream = new Transform2(options);
23742
+ stream[kLast] = "";
23743
+ stream[kDecoder] = new StringDecoder("utf8");
23744
+ stream.matcher = matcher;
23745
+ stream.mapper = mapper;
23746
+ stream.maxLength = options.maxLength;
23747
+ stream.skipOverflow = options.skipOverflow || false;
23748
+ stream.overflow = false;
23749
+ stream._destroy = function(err2, cb) {
23750
+ this._writableState.errorEmitted = false;
23751
+ cb(err2);
23752
+ };
23753
+ return stream;
23754
+ }
23755
+ module2.exports = split;
23756
+ }
23757
+ });
23758
+
23759
+ // node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/helper.js
23760
+ var require_helper = __commonJS({
23761
+ "node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/helper.js"(exports, module2) {
23762
+ "use strict";
23763
+ var path4 = require("path");
23764
+ var Stream = require("stream").Stream;
23765
+ var split = require_split2();
23766
+ var util2 = require("util");
23767
+ var defaultPort = 5432;
23768
+ var isWin = process.platform === "win32";
23769
+ var warnStream = process.stderr;
23770
+ var S_IRWXG = 56;
23771
+ var S_IRWXO = 7;
23772
+ var S_IFMT = 61440;
23773
+ var S_IFREG = 32768;
23774
+ function isRegFile(mode) {
23775
+ return (mode & S_IFMT) == S_IFREG;
23776
+ }
23777
+ var fieldNames = ["host", "port", "database", "user", "password"];
23778
+ var nrOfFields = fieldNames.length;
23779
+ var passKey = fieldNames[nrOfFields - 1];
23780
+ function warn() {
23781
+ var isWritable = warnStream instanceof Stream && true === warnStream.writable;
23782
+ if (isWritable) {
23783
+ var args = Array.prototype.slice.call(arguments).concat("\n");
23784
+ warnStream.write(util2.format.apply(util2, args));
23785
+ }
23786
+ }
23787
+ Object.defineProperty(module2.exports, "isWin", {
23788
+ get: function() {
23789
+ return isWin;
23790
+ },
23791
+ set: function(val) {
23792
+ isWin = val;
23793
+ }
23794
+ });
23795
+ module2.exports.warnTo = function(stream) {
23796
+ var old = warnStream;
23797
+ warnStream = stream;
23798
+ return old;
23799
+ };
23800
+ module2.exports.getFileName = function(rawEnv) {
23801
+ var env2 = rawEnv || process.env;
23802
+ var file = env2.PGPASSFILE || (isWin ? path4.join(env2.APPDATA || "./", "postgresql", "pgpass.conf") : path4.join(env2.HOME || "./", ".pgpass"));
23803
+ return file;
23804
+ };
23805
+ module2.exports.usePgPass = function(stats, fname) {
23806
+ if (Object.prototype.hasOwnProperty.call(process.env, "PGPASSWORD")) {
23807
+ return false;
23808
+ }
23809
+ if (isWin) {
23810
+ return true;
23811
+ }
23812
+ fname = fname || "<unkn>";
23813
+ if (!isRegFile(stats.mode)) {
23814
+ warn('WARNING: password file "%s" is not a plain file', fname);
23815
+ return false;
23816
+ }
23817
+ if (stats.mode & (S_IRWXG | S_IRWXO)) {
23818
+ warn('WARNING: password file "%s" has group or world access; permissions should be u=rw (0600) or less', fname);
23819
+ return false;
23820
+ }
23821
+ return true;
23822
+ };
23823
+ var matcher = module2.exports.match = function(connInfo, entry) {
23824
+ return fieldNames.slice(0, -1).reduce(function(prev, field, idx) {
23825
+ if (idx == 1) {
23826
+ if (Number(connInfo[field] || defaultPort) === Number(entry[field])) {
23827
+ return prev && true;
23828
+ }
23829
+ }
23830
+ return prev && (entry[field] === "*" || entry[field] === connInfo[field]);
23831
+ }, true);
23832
+ };
23833
+ module2.exports.getPassword = function(connInfo, stream, cb) {
23834
+ var pass;
23835
+ var lineStream = stream.pipe(split());
23836
+ function onLine(line) {
23837
+ var entry = parseLine(line);
23838
+ if (entry && isValidEntry(entry) && matcher(connInfo, entry)) {
23839
+ pass = entry[passKey];
23840
+ lineStream.end();
23841
+ }
23842
+ }
23843
+ var onEnd = function() {
23844
+ stream.destroy();
23845
+ cb(pass);
23846
+ };
23847
+ var onErr = function(err2) {
23848
+ stream.destroy();
23849
+ warn("WARNING: error on reading file: %s", err2);
23850
+ cb(void 0);
23851
+ };
23852
+ stream.on("error", onErr);
23853
+ lineStream.on("data", onLine).on("end", onEnd).on("error", onErr);
23854
+ };
23855
+ var parseLine = module2.exports.parseLine = function(line) {
23856
+ if (line.length < 11 || line.match(/^\s+#/)) {
23857
+ return null;
23858
+ }
23859
+ var curChar = "";
23860
+ var prevChar = "";
23861
+ var fieldIdx = 0;
23862
+ var startIdx = 0;
23863
+ var endIdx = 0;
23864
+ var obj = {};
23865
+ var isLastField = false;
23866
+ var addToObj = function(idx, i0, i1) {
23867
+ var field = line.substring(i0, i1);
23868
+ if (!Object.hasOwnProperty.call(process.env, "PGPASS_NO_DEESCAPE")) {
23869
+ field = field.replace(/\\([:\\])/g, "$1");
23870
+ }
23871
+ obj[fieldNames[idx]] = field;
23872
+ };
23873
+ for (var i = 0; i < line.length - 1; i += 1) {
23874
+ curChar = line.charAt(i + 1);
23875
+ prevChar = line.charAt(i);
23876
+ isLastField = fieldIdx == nrOfFields - 1;
23877
+ if (isLastField) {
23878
+ addToObj(fieldIdx, startIdx);
23879
+ break;
23880
+ }
23881
+ if (i >= 0 && curChar == ":" && prevChar !== "\\") {
23882
+ addToObj(fieldIdx, startIdx, i + 1);
23883
+ startIdx = i + 2;
23884
+ fieldIdx += 1;
23885
+ }
23886
+ }
23887
+ obj = Object.keys(obj).length === nrOfFields ? obj : null;
23888
+ return obj;
23889
+ };
23890
+ var isValidEntry = module2.exports.isValidEntry = function(entry) {
23891
+ var rules = {
23892
+ // host
23893
+ 0: function(x) {
23894
+ return x.length > 0;
23895
+ },
23896
+ // port
23897
+ 1: function(x) {
23898
+ if (x === "*") {
23899
+ return true;
23900
+ }
23901
+ x = Number(x);
23902
+ return isFinite(x) && x > 0 && x < 9007199254740992 && Math.floor(x) === x;
23903
+ },
23904
+ // database
23905
+ 2: function(x) {
23906
+ return x.length > 0;
23907
+ },
23908
+ // username
23909
+ 3: function(x) {
23910
+ return x.length > 0;
23911
+ },
23912
+ // password
23913
+ 4: function(x) {
23914
+ return x.length > 0;
23915
+ }
23916
+ };
23917
+ for (var idx = 0; idx < fieldNames.length; idx += 1) {
23918
+ var rule = rules[idx];
23919
+ var value = entry[fieldNames[idx]] || "";
23920
+ var res = rule(value);
23921
+ if (!res) {
23922
+ return false;
23923
+ }
23924
+ }
23925
+ return true;
23926
+ };
23927
+ }
23928
+ });
23929
+
23930
+ // node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js
23931
+ var require_lib = __commonJS({
23932
+ "node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js"(exports, module2) {
23933
+ "use strict";
23934
+ var path4 = require("path");
23935
+ var fs8 = require("fs");
23936
+ var helper = require_helper();
23937
+ module2.exports = function(connInfo, cb) {
23938
+ var file = helper.getFileName();
23939
+ fs8.stat(file, function(err2, stat) {
23940
+ if (err2 || !helper.usePgPass(stat, file)) {
23941
+ return cb(void 0);
23942
+ }
23943
+ var st = fs8.createReadStream(file);
23944
+ helper.getPassword(connInfo, st, cb);
23945
+ });
23946
+ };
23947
+ module2.exports.warnTo = helper.warnTo;
23948
+ }
23949
+ });
23950
+
23951
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/client.js
23801
23952
  var require_client = __commonJS({
23802
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/client.js"(exports, module2) {
23953
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/client.js"(exports, module2) {
23803
23954
  "use strict";
23804
23955
  var EventEmitter = require("events").EventEmitter;
23805
- var util2 = require("util");
23806
23956
  var utils = require_utils2();
23807
23957
  var sasl = require_sasl();
23808
- var pgPass = require_lib();
23809
23958
  var TypeOverrides = require_type_overrides();
23810
23959
  var ConnectionParameters = require_connection_parameters();
23811
23960
  var Query = require_query();
23812
23961
  var defaults3 = require_defaults();
23813
23962
  var Connection2 = require_connection();
23963
+ var crypto = require_utils3();
23814
23964
  var Client2 = class extends EventEmitter {
23815
23965
  constructor(config) {
23816
23966
  super();
@@ -23830,6 +23980,7 @@ var require_client = __commonJS({
23830
23980
  this._Promise = c.Promise || global.Promise;
23831
23981
  this._types = new TypeOverrides(c.types);
23832
23982
  this._ending = false;
23983
+ this._ended = false;
23833
23984
  this._connecting = false;
23834
23985
  this._connected = false;
23835
23986
  this._connectionError = false;
@@ -23905,6 +24056,7 @@ var require_client = __commonJS({
23905
24056
  const error2 = this._ending ? new Error("Connection terminated") : new Error("Connection terminated unexpectedly");
23906
24057
  clearTimeout(this.connectionTimeoutHandle);
23907
24058
  this._errorAllQueries(error2);
24059
+ this._ended = true;
23908
24060
  if (!this._ending) {
23909
24061
  if (this._connecting && !this._connectionError) {
23910
24062
  if (this._connectionCallback) {
@@ -23979,12 +24131,17 @@ var require_client = __commonJS({
23979
24131
  } else if (this.password !== null) {
23980
24132
  cb();
23981
24133
  } else {
23982
- pgPass(this.connectionParameters, (pass) => {
23983
- if (void 0 !== pass) {
23984
- this.connectionParameters.password = this.password = pass;
23985
- }
23986
- cb();
23987
- });
24134
+ try {
24135
+ const pgPass = require_lib();
24136
+ pgPass(this.connectionParameters, (pass) => {
24137
+ if (void 0 !== pass) {
24138
+ this.connectionParameters.password = this.password = pass;
24139
+ }
24140
+ cb();
24141
+ });
24142
+ } catch (e) {
24143
+ this.emit("error", e);
24144
+ }
23988
24145
  }
23989
24146
  }
23990
24147
  _handleAuthCleartextPassword(msg) {
@@ -23993,24 +24150,40 @@ var require_client = __commonJS({
23993
24150
  });
23994
24151
  }
23995
24152
  _handleAuthMD5Password(msg) {
23996
- this._checkPgPass(() => {
23997
- const hashedPassword = utils.postgresMd5PasswordHash(this.user, this.password, msg.salt);
23998
- this.connection.password(hashedPassword);
24153
+ this._checkPgPass(async () => {
24154
+ try {
24155
+ const hashedPassword = await crypto.postgresMd5PasswordHash(this.user, this.password, msg.salt);
24156
+ this.connection.password(hashedPassword);
24157
+ } catch (e) {
24158
+ this.emit("error", e);
24159
+ }
23999
24160
  });
24000
24161
  }
24001
24162
  _handleAuthSASL(msg) {
24002
24163
  this._checkPgPass(() => {
24003
- this.saslSession = sasl.startSession(msg.mechanisms);
24004
- this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
24164
+ try {
24165
+ this.saslSession = sasl.startSession(msg.mechanisms);
24166
+ this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
24167
+ } catch (err2) {
24168
+ this.connection.emit("error", err2);
24169
+ }
24005
24170
  });
24006
24171
  }
24007
- _handleAuthSASLContinue(msg) {
24008
- sasl.continueSession(this.saslSession, this.password, msg.data);
24009
- this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
24172
+ async _handleAuthSASLContinue(msg) {
24173
+ try {
24174
+ await sasl.continueSession(this.saslSession, this.password, msg.data);
24175
+ this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
24176
+ } catch (err2) {
24177
+ this.connection.emit("error", err2);
24178
+ }
24010
24179
  }
24011
24180
  _handleAuthSASLFinal(msg) {
24012
- sasl.finalizeSession(this.saslSession, msg.data);
24013
- this.saslSession = null;
24181
+ try {
24182
+ sasl.finalizeSession(this.saslSession, msg.data);
24183
+ this.saslSession = null;
24184
+ } catch (err2) {
24185
+ this.connection.emit("error", err2);
24186
+ }
24014
24187
  }
24015
24188
  _handleBackendKeyData(msg) {
24016
24189
  this.processID = msg.processID;
@@ -24152,30 +24325,14 @@ var require_client = __commonJS({
24152
24325
  getTypeParser(oid, format) {
24153
24326
  return this._types.getTypeParser(oid, format);
24154
24327
  }
24155
- // Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
24328
+ // escapeIdentifier and escapeLiteral moved to utility functions & exported
24329
+ // on PG
24330
+ // re-exported here for backwards compatibility
24156
24331
  escapeIdentifier(str) {
24157
- return '"' + str.replace(/"/g, '""') + '"';
24332
+ return utils.escapeIdentifier(str);
24158
24333
  }
24159
- // Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
24160
24334
  escapeLiteral(str) {
24161
- var hasBackslash = false;
24162
- var escaped = "'";
24163
- for (var i = 0; i < str.length; i++) {
24164
- var c = str[i];
24165
- if (c === "'") {
24166
- escaped += c + c;
24167
- } else if (c === "\\") {
24168
- escaped += c + c;
24169
- hasBackslash = true;
24170
- } else {
24171
- escaped += c;
24172
- }
24173
- }
24174
- escaped += "'";
24175
- if (hasBackslash === true) {
24176
- escaped = " E" + escaped;
24177
- }
24178
- return escaped;
24335
+ return utils.escapeLiteral(str);
24179
24336
  }
24180
24337
  _pulseQueryQueue() {
24181
24338
  if (this.readyForQuery === true) {
@@ -24217,6 +24374,9 @@ var require_client = __commonJS({
24217
24374
  if (!query.callback) {
24218
24375
  result = new this._Promise((resolve2, reject) => {
24219
24376
  query.callback = (err2, res) => err2 ? reject(err2) : resolve2(res);
24377
+ }).catch((err2) => {
24378
+ Error.captureStackTrace(err2);
24379
+ throw err2;
24220
24380
  });
24221
24381
  }
24222
24382
  }
@@ -24271,7 +24431,7 @@ var require_client = __commonJS({
24271
24431
  }
24272
24432
  end(cb) {
24273
24433
  this._ending = true;
24274
- if (!this.connection._connecting) {
24434
+ if (!this.connection._connecting || this._ended) {
24275
24435
  if (cb) {
24276
24436
  cb();
24277
24437
  } else {
@@ -24297,9 +24457,9 @@ var require_client = __commonJS({
24297
24457
  }
24298
24458
  });
24299
24459
 
24300
- // node_modules/.pnpm/pg-pool@3.6.1_pg@8.8.0/node_modules/pg-pool/index.js
24460
+ // node_modules/.pnpm/pg-pool@3.6.1_pg@8.11.3/node_modules/pg-pool/index.js
24301
24461
  var require_pg_pool = __commonJS({
24302
- "node_modules/.pnpm/pg-pool@3.6.1_pg@8.8.0/node_modules/pg-pool/index.js"(exports, module2) {
24462
+ "node_modules/.pnpm/pg-pool@3.6.1_pg@8.11.3/node_modules/pg-pool/index.js"(exports, module2) {
24303
24463
  "use strict";
24304
24464
  var EventEmitter = require("events").EventEmitter;
24305
24465
  var NOOP = function() {
@@ -24680,72 +24840,9 @@ var require_pg_pool = __commonJS({
24680
24840
  }
24681
24841
  });
24682
24842
 
24683
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/package.json
24684
- var require_package = __commonJS({
24685
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/package.json"(exports, module2) {
24686
- module2.exports = {
24687
- name: "pg",
24688
- version: "8.8.0",
24689
- description: "PostgreSQL client - pure javascript & libpq with the same API",
24690
- keywords: [
24691
- "database",
24692
- "libpq",
24693
- "pg",
24694
- "postgre",
24695
- "postgres",
24696
- "postgresql",
24697
- "rdbms"
24698
- ],
24699
- homepage: "https://github.com/brianc/node-postgres",
24700
- repository: {
24701
- type: "git",
24702
- url: "git://github.com/brianc/node-postgres.git",
24703
- directory: "packages/pg"
24704
- },
24705
- author: "Brian Carlson <brian.m.carlson@gmail.com>",
24706
- main: "./lib",
24707
- dependencies: {
24708
- "buffer-writer": "2.0.0",
24709
- "packet-reader": "1.0.0",
24710
- "pg-connection-string": "^2.5.0",
24711
- "pg-pool": "^3.5.2",
24712
- "pg-protocol": "^1.5.0",
24713
- "pg-types": "^2.1.0",
24714
- pgpass: "1.x"
24715
- },
24716
- devDependencies: {
24717
- async: "2.6.4",
24718
- bluebird: "3.5.2",
24719
- co: "4.6.0",
24720
- "pg-copy-streams": "0.3.0"
24721
- },
24722
- peerDependencies: {
24723
- "pg-native": ">=3.0.1"
24724
- },
24725
- peerDependenciesMeta: {
24726
- "pg-native": {
24727
- optional: true
24728
- }
24729
- },
24730
- scripts: {
24731
- test: "make test-all"
24732
- },
24733
- files: [
24734
- "lib",
24735
- "SPONSORS.md"
24736
- ],
24737
- license: "MIT",
24738
- engines: {
24739
- node: ">= 8.0.0"
24740
- },
24741
- gitHead: "c99fb2c127ddf8d712500db2c7b9a5491a178655"
24742
- };
24743
- }
24744
- });
24745
-
24746
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/query.js
24843
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/native/query.js
24747
24844
  var require_query2 = __commonJS({
24748
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/query.js"(exports, module2) {
24845
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/native/query.js"(exports, module2) {
24749
24846
  "use strict";
24750
24847
  var EventEmitter = require("events").EventEmitter;
24751
24848
  var util2 = require("util");
@@ -24885,13 +24982,17 @@ var require_query2 = __commonJS({
24885
24982
  }
24886
24983
  });
24887
24984
 
24888
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/client.js
24985
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/native/client.js
24889
24986
  var require_client2 = __commonJS({
24890
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/client.js"(exports, module2) {
24987
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/native/client.js"(exports, module2) {
24891
24988
  "use strict";
24892
- var Native = require("pg-native");
24989
+ var Native;
24990
+ try {
24991
+ Native = require("pg-native");
24992
+ } catch (e) {
24993
+ throw e;
24994
+ }
24893
24995
  var TypeOverrides = require_type_overrides();
24894
- var pkg = require_package();
24895
24996
  var EventEmitter = require("events").EventEmitter;
24896
24997
  var util2 = require("util");
24897
24998
  var ConnectionParameters = require_connection_parameters();
@@ -24910,6 +25011,8 @@ var require_client2 = __commonJS({
24910
25011
  this._connected = false;
24911
25012
  this._queryable = true;
24912
25013
  var cp = this.connectionParameters = new ConnectionParameters(config);
25014
+ if (config.nativeConnectionString)
25015
+ cp.nativeConnectionString = config.nativeConnectionString;
24913
25016
  this.user = cp.user;
24914
25017
  Object.defineProperty(this, "password", {
24915
25018
  configurable: true,
@@ -24946,6 +25049,8 @@ var require_client2 = __commonJS({
24946
25049
  }
24947
25050
  this._connecting = true;
24948
25051
  this.connectionParameters.getLibpqConnectionString(function(err2, conString) {
25052
+ if (self2.connectionParameters.nativeConnectionString)
25053
+ conString = self2.connectionParameters.nativeConnectionString;
24949
25054
  if (err2)
24950
25055
  return cb(err2);
24951
25056
  self2.native.connect(conString, function(err3) {
@@ -25008,6 +25113,9 @@ var require_client2 = __commonJS({
25008
25113
  result = new this._Promise((resolve2, reject) => {
25009
25114
  resolveOut = resolve2;
25010
25115
  rejectOut = reject;
25116
+ }).catch((err2) => {
25117
+ Error.captureStackTrace(err2);
25118
+ throw err2;
25011
25119
  });
25012
25120
  query.callback = (err2, res) => err2 ? rejectOut(err2) : resolveOut(res);
25013
25121
  }
@@ -25118,23 +25226,24 @@ var require_client2 = __commonJS({
25118
25226
  }
25119
25227
  });
25120
25228
 
25121
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/index.js
25229
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/native/index.js
25122
25230
  var require_native = __commonJS({
25123
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/index.js"(exports, module2) {
25231
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/native/index.js"(exports, module2) {
25124
25232
  "use strict";
25125
25233
  module2.exports = require_client2();
25126
25234
  }
25127
25235
  });
25128
25236
 
25129
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/index.js
25237
+ // node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/index.js
25130
25238
  var require_lib2 = __commonJS({
25131
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/index.js"(exports, module2) {
25239
+ "node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/index.js"(exports, module2) {
25132
25240
  "use strict";
25133
25241
  var Client2 = require_client();
25134
25242
  var defaults3 = require_defaults();
25135
25243
  var Connection2 = require_connection();
25136
25244
  var Pool = require_pg_pool();
25137
25245
  var { DatabaseError } = require_dist();
25246
+ var { escapeIdentifier, escapeLiteral } = require_utils2();
25138
25247
  var poolFactory = (Client3) => {
25139
25248
  return class BoundPool extends Pool {
25140
25249
  constructor(options) {
@@ -25151,6 +25260,8 @@ var require_lib2 = __commonJS({
25151
25260
  this.Connection = Connection2;
25152
25261
  this.types = require_pg_types();
25153
25262
  this.DatabaseError = DatabaseError;
25263
+ this.escapeIdentifier = escapeIdentifier;
25264
+ this.escapeLiteral = escapeLiteral;
25154
25265
  };
25155
25266
  if (typeof process.env.NODE_PG_FORCE_NATIVE !== "undefined") {
25156
25267
  module2.exports = new PG(require_native());
@@ -25262,9 +25373,10 @@ var init_pgConnect = __esm({
25262
25373
  var pgIntrospect_exports = {};
25263
25374
  __export(pgIntrospect_exports, {
25264
25375
  pgIntrospect: () => pgIntrospect,
25265
- pgPushIntrospect: () => pgPushIntrospect
25376
+ pgPushIntrospect: () => pgPushIntrospect,
25377
+ pgSchemas: () => pgSchemas
25266
25378
  });
25267
- var import_hanji4, pgPushIntrospect, pgIntrospect;
25379
+ var import_hanji4, pgSchemas, pgPushIntrospect, pgIntrospect;
25268
25380
  var init_pgIntrospect = __esm({
25269
25381
  "src/cli/commands/pgIntrospect.ts"() {
25270
25382
  import_hanji4 = __toESM(require_hanji());
@@ -25273,6 +25385,18 @@ var init_pgIntrospect = __esm({
25273
25385
  init_introspect();
25274
25386
  init_global();
25275
25387
  init_mjs();
25388
+ pgSchemas = async (client) => {
25389
+ const res = await client.query(`select s.nspname as table_schema,
25390
+ s.oid as schema_id,
25391
+ u.usename as owner
25392
+ from pg_catalog.pg_namespace s
25393
+ join pg_catalog.pg_user u on u.usesysid = s.nspowner
25394
+ where nspname not in ('information_schema', 'pg_catalog')
25395
+ and nspname not like 'pg_toast%'
25396
+ and nspname not like 'pg_temp_%'
25397
+ order by table_schema;`);
25398
+ return res.map((it) => it["table_schema"]);
25399
+ };
25276
25400
  pgPushIntrospect = async (connection, filters, schemaFilters) => {
25277
25401
  const { client } = connection;
25278
25402
  const matchers = filters.map((it) => {
@@ -25967,6 +26091,55 @@ var init_sqliteIntrospect = __esm({
25967
26091
  }
25968
26092
  });
25969
26093
 
26094
+ // src/cli/utils.ts
26095
+ var assertPackages, requiredApiVersion, assertOrmCoreVersion, ormCoreVersions;
26096
+ var init_utils3 = __esm({
26097
+ "src/cli/utils.ts"() {
26098
+ init_views();
26099
+ assertPackages = async (...pkgs) => {
26100
+ try {
26101
+ for (let i = 0; i < pkgs.length; i++) {
26102
+ const it = pkgs[i];
26103
+ await import(it);
26104
+ }
26105
+ } catch (e) {
26106
+ err(
26107
+ `please install required packages: ${pkgs.map((it) => `'${it}'`).join(" ")}`
26108
+ );
26109
+ process.exit(1);
26110
+ }
26111
+ };
26112
+ requiredApiVersion = 6;
26113
+ assertOrmCoreVersion = async () => {
26114
+ try {
26115
+ const { compatibilityVersion } = await import("drizzle-orm/version");
26116
+ if (compatibilityVersion && compatibilityVersion === requiredApiVersion)
26117
+ return;
26118
+ if (!compatibilityVersion || compatibilityVersion < requiredApiVersion) {
26119
+ console.log(
26120
+ "This version of drizzle-kit requires newer version of drizzle-orm\nPlease update drizzle-orm package to the latest version \u{1F44D}"
26121
+ );
26122
+ } else {
26123
+ console.log(
26124
+ "This version of drizzle-kit is outdated\nPlease update drizzle-kit package to the latest version \u{1F44D}"
26125
+ );
26126
+ }
26127
+ } catch (e) {
26128
+ console.log("Please install latest version of drizzle-orm");
26129
+ }
26130
+ process.exit(1);
26131
+ };
26132
+ ormCoreVersions = async () => {
26133
+ try {
26134
+ const { compatibilityVersion, npmVersion } = await import("drizzle-orm/version");
26135
+ return { compatibilityVersion, npmVersion };
26136
+ } catch (e) {
26137
+ return {};
26138
+ }
26139
+ };
26140
+ }
26141
+ });
26142
+
25970
26143
  // node_modules/.pnpm/sqlstring@2.3.3/node_modules/sqlstring/lib/SqlString.js
25971
26144
  var require_SqlString = __commonJS({
25972
26145
  "node_modules/.pnpm/sqlstring@2.3.3/node_modules/sqlstring/lib/SqlString.js"(exports) {
@@ -41941,7 +42114,7 @@ var require_server = __commonJS({
41941
42114
  var EventEmitter = require("events").EventEmitter;
41942
42115
  var Connection2 = require_connection2();
41943
42116
  var ConnectionConfig = require_connection_config();
41944
- var Server = class extends EventEmitter {
42117
+ var Server2 = class extends EventEmitter {
41945
42118
  constructor() {
41946
42119
  super();
41947
42120
  this.connections = [];
@@ -41964,7 +42137,7 @@ var require_server = __commonJS({
41964
42137
  this._server.close(cb);
41965
42138
  }
41966
42139
  };
41967
- module2.exports = Server;
42140
+ module2.exports = Server2;
41968
42141
  }
41969
42142
  });
41970
42143
 
@@ -41995,8 +42168,8 @@ var require_mysql2 = __commonJS({
41995
42168
  exports.Pool = Pool;
41996
42169
  exports.PoolCluster = PoolCluster;
41997
42170
  exports.createServer = function(handler) {
41998
- const Server = require_server();
41999
- const s = new Server();
42171
+ const Server2 = require_server();
42172
+ const s = new Server2();
42000
42173
  if (handler) {
42001
42174
  s.on("connection", handler);
42002
42175
  }
@@ -42559,9 +42732,12 @@ var init_session = __esm({
42559
42732
  };
42560
42733
  _a = import_drizzle_orm9.entityKind;
42561
42734
  SQLiteWranglerD1Session[_a] = "SQLiteD1Session";
42562
- PreparedQuery = class extends import_sqlite_core3.PreparedQuery {
42735
+ PreparedQuery = class extends import_sqlite_core3.SQLitePreparedQuery {
42563
42736
  constructor(stmt, configPath, dbName, queryString, params, logger, fields, executeMethod, customResultMapper) {
42564
- super("async", executeMethod);
42737
+ super("async", executeMethod, {
42738
+ sql: queryString,
42739
+ params
42740
+ });
42565
42741
  this.stmt = stmt;
42566
42742
  this.configPath = configPath;
42567
42743
  this.dbName = dbName;
@@ -42620,7 +42796,11 @@ var init_session = __esm({
42620
42796
  async values(placeholderValues) {
42621
42797
  const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
42622
42798
  this.logger.logQuery(this.queryString, params);
42623
- const wranglerRes = await this.stmt(this.queryString, this.configPath, this.dbName);
42799
+ const wranglerRes = await this.stmt(
42800
+ this.queryString,
42801
+ this.configPath,
42802
+ this.dbName
42803
+ );
42624
42804
  return this.d1ToRawMapping(wranglerRes.results);
42625
42805
  }
42626
42806
  };
@@ -44733,7 +44913,7 @@ var require_glob_parent = __commonJS({
44733
44913
  });
44734
44914
 
44735
44915
  // node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/utils.js
44736
- var require_utils3 = __commonJS({
44916
+ var require_utils4 = __commonJS({
44737
44917
  "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/utils.js"(exports) {
44738
44918
  "use strict";
44739
44919
  exports.isInteger = (num) => {
@@ -44820,7 +45000,7 @@ var require_utils3 = __commonJS({
44820
45000
  var require_stringify = __commonJS({
44821
45001
  "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/stringify.js"(exports, module2) {
44822
45002
  "use strict";
44823
- var utils = require_utils3();
45003
+ var utils = require_utils4();
44824
45004
  module2.exports = (ast, options = {}) => {
44825
45005
  let stringify = (node, parent = {}) => {
44826
45006
  let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
@@ -45286,7 +45466,7 @@ var require_compile = __commonJS({
45286
45466
  "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/compile.js"(exports, module2) {
45287
45467
  "use strict";
45288
45468
  var fill = require_fill_range();
45289
- var utils = require_utils3();
45469
+ var utils = require_utils4();
45290
45470
  var compile = (ast, options = {}) => {
45291
45471
  let walk = (node, parent = {}) => {
45292
45472
  let invalidBlock = utils.isInvalidBrace(parent);
@@ -45338,7 +45518,7 @@ var require_expand = __commonJS({
45338
45518
  "use strict";
45339
45519
  var fill = require_fill_range();
45340
45520
  var stringify = require_stringify();
45341
- var utils = require_utils3();
45521
+ var utils = require_utils4();
45342
45522
  var append = (queue = "", stash = "", enclose = false) => {
45343
45523
  let result = [];
45344
45524
  queue = [].concat(queue);
@@ -46035,7 +46215,7 @@ var require_constants2 = __commonJS({
46035
46215
  });
46036
46216
 
46037
46217
  // node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/utils.js
46038
- var require_utils4 = __commonJS({
46218
+ var require_utils5 = __commonJS({
46039
46219
  "node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/utils.js"(exports) {
46040
46220
  "use strict";
46041
46221
  var path4 = require("path");
@@ -46101,7 +46281,7 @@ var require_utils4 = __commonJS({
46101
46281
  var require_scan = __commonJS({
46102
46282
  "node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/scan.js"(exports, module2) {
46103
46283
  "use strict";
46104
- var utils = require_utils4();
46284
+ var utils = require_utils5();
46105
46285
  var {
46106
46286
  CHAR_ASTERISK,
46107
46287
  /* * */
@@ -46435,7 +46615,7 @@ var require_parse2 = __commonJS({
46435
46615
  "node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/parse.js"(exports, module2) {
46436
46616
  "use strict";
46437
46617
  var constants = require_constants2();
46438
- var utils = require_utils4();
46618
+ var utils = require_utils5();
46439
46619
  var {
46440
46620
  MAX_LENGTH,
46441
46621
  POSIX_REGEX_SOURCE,
@@ -47218,7 +47398,7 @@ var require_picomatch = __commonJS({
47218
47398
  var path4 = require("path");
47219
47399
  var scan = require_scan();
47220
47400
  var parse = require_parse2();
47221
- var utils = require_utils4();
47401
+ var utils = require_utils5();
47222
47402
  var constants = require_constants2();
47223
47403
  var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
47224
47404
  var picomatch = (glob2, options, returnState = false) => {
@@ -47370,7 +47550,7 @@ var require_micromatch = __commonJS({
47370
47550
  var util2 = require("util");
47371
47551
  var braces = require_braces();
47372
47552
  var picomatch = require_picomatch2();
47373
- var utils = require_utils4();
47553
+ var utils = require_utils5();
47374
47554
  var isEmptyString = (val) => val === "" || val === "./";
47375
47555
  var micromatch = (list, patterns, options) => {
47376
47556
  patterns = [].concat(patterns);
@@ -47674,7 +47854,7 @@ var require_pattern = __commonJS({
47674
47854
  });
47675
47855
 
47676
47856
  // node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/utils/stream.js
47677
- var require_stream = __commonJS({
47857
+ var require_stream2 = __commonJS({
47678
47858
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/utils/stream.js"(exports) {
47679
47859
  "use strict";
47680
47860
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -47714,7 +47894,7 @@ var require_string2 = __commonJS({
47714
47894
  });
47715
47895
 
47716
47896
  // node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/utils/index.js
47717
- var require_utils5 = __commonJS({
47897
+ var require_utils6 = __commonJS({
47718
47898
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/utils/index.js"(exports) {
47719
47899
  "use strict";
47720
47900
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -47729,7 +47909,7 @@ var require_utils5 = __commonJS({
47729
47909
  exports.path = path4;
47730
47910
  var pattern = require_pattern();
47731
47911
  exports.pattern = pattern;
47732
- var stream = require_stream();
47912
+ var stream = require_stream2();
47733
47913
  exports.stream = stream;
47734
47914
  var string = require_string2();
47735
47915
  exports.string = string;
@@ -47742,7 +47922,7 @@ var require_tasks = __commonJS({
47742
47922
  "use strict";
47743
47923
  Object.defineProperty(exports, "__esModule", { value: true });
47744
47924
  exports.convertPatternGroupToTask = exports.convertPatternGroupsToTasks = exports.groupPatternsByBaseDirectory = exports.getNegativePatternsAsPositive = exports.getPositivePatterns = exports.convertPatternsToTasks = exports.generate = void 0;
47745
- var utils = require_utils5();
47925
+ var utils = require_utils6();
47746
47926
  function generate(input, settings) {
47747
47927
  const patterns = processPatterns(input, settings);
47748
47928
  const ignore = processPatterns(settings.ignore, settings);
@@ -48088,7 +48268,7 @@ var require_fs3 = __commonJS({
48088
48268
  });
48089
48269
 
48090
48270
  // node_modules/.pnpm/@nodelib+fs.scandir@2.1.5/node_modules/@nodelib/fs.scandir/out/utils/index.js
48091
- var require_utils6 = __commonJS({
48271
+ var require_utils7 = __commonJS({
48092
48272
  "node_modules/.pnpm/@nodelib+fs.scandir@2.1.5/node_modules/@nodelib/fs.scandir/out/utils/index.js"(exports) {
48093
48273
  "use strict";
48094
48274
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -48123,7 +48303,7 @@ var require_async2 = __commonJS({
48123
48303
  var fsStat = require_out();
48124
48304
  var rpl = require_run_parallel();
48125
48305
  var constants_1 = require_constants3();
48126
- var utils = require_utils6();
48306
+ var utils = require_utils7();
48127
48307
  var common = require_common2();
48128
48308
  function read(directory, settings, callback) {
48129
48309
  if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
@@ -48232,7 +48412,7 @@ var require_sync2 = __commonJS({
48232
48412
  exports.readdir = exports.readdirWithFileTypes = exports.read = void 0;
48233
48413
  var fsStat = require_out();
48234
48414
  var constants_1 = require_constants3();
48235
- var utils = require_utils6();
48415
+ var utils = require_utils7();
48236
48416
  var common = require_common2();
48237
48417
  function read(directory, settings) {
48238
48418
  if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
@@ -48833,7 +49013,7 @@ var require_async4 = __commonJS({
48833
49013
  });
48834
49014
 
48835
49015
  // node_modules/.pnpm/@nodelib+fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/stream.js
48836
- var require_stream2 = __commonJS({
49016
+ var require_stream3 = __commonJS({
48837
49017
  "node_modules/.pnpm/@nodelib+fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/stream.js"(exports) {
48838
49018
  "use strict";
48839
49019
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -48996,7 +49176,7 @@ var require_out3 = __commonJS({
48996
49176
  Object.defineProperty(exports, "__esModule", { value: true });
48997
49177
  exports.Settings = exports.walkStream = exports.walkSync = exports.walk = void 0;
48998
49178
  var async_1 = require_async4();
48999
- var stream_1 = require_stream2();
49179
+ var stream_1 = require_stream3();
49000
49180
  var sync_1 = require_sync4();
49001
49181
  var settings_1 = require_settings3();
49002
49182
  exports.Settings = settings_1.default;
@@ -49036,7 +49216,7 @@ var require_reader2 = __commonJS({
49036
49216
  Object.defineProperty(exports, "__esModule", { value: true });
49037
49217
  var path4 = require("path");
49038
49218
  var fsStat = require_out();
49039
- var utils = require_utils5();
49219
+ var utils = require_utils6();
49040
49220
  var Reader = class {
49041
49221
  constructor(_settings) {
49042
49222
  this._settings = _settings;
@@ -49069,7 +49249,7 @@ var require_reader2 = __commonJS({
49069
49249
  });
49070
49250
 
49071
49251
  // node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/readers/stream.js
49072
- var require_stream3 = __commonJS({
49252
+ var require_stream4 = __commonJS({
49073
49253
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/readers/stream.js"(exports) {
49074
49254
  "use strict";
49075
49255
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -49132,7 +49312,7 @@ var require_async5 = __commonJS({
49132
49312
  Object.defineProperty(exports, "__esModule", { value: true });
49133
49313
  var fsWalk = require_out3();
49134
49314
  var reader_1 = require_reader2();
49135
- var stream_1 = require_stream3();
49315
+ var stream_1 = require_stream4();
49136
49316
  var ReaderAsync = class extends reader_1.default {
49137
49317
  constructor() {
49138
49318
  super(...arguments);
@@ -49169,7 +49349,7 @@ var require_matcher = __commonJS({
49169
49349
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/providers/matchers/matcher.js"(exports) {
49170
49350
  "use strict";
49171
49351
  Object.defineProperty(exports, "__esModule", { value: true });
49172
- var utils = require_utils5();
49352
+ var utils = require_utils6();
49173
49353
  var Matcher = class {
49174
49354
  constructor(_patterns, _settings, _micromatchOptions) {
49175
49355
  this._patterns = _patterns;
@@ -49257,7 +49437,7 @@ var require_deep = __commonJS({
49257
49437
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/providers/filters/deep.js"(exports) {
49258
49438
  "use strict";
49259
49439
  Object.defineProperty(exports, "__esModule", { value: true });
49260
- var utils = require_utils5();
49440
+ var utils = require_utils6();
49261
49441
  var partial_1 = require_partial();
49262
49442
  var DeepFilter = class {
49263
49443
  constructor(_settings, _micromatchOptions) {
@@ -49322,7 +49502,7 @@ var require_entry = __commonJS({
49322
49502
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/providers/filters/entry.js"(exports) {
49323
49503
  "use strict";
49324
49504
  Object.defineProperty(exports, "__esModule", { value: true });
49325
- var utils = require_utils5();
49505
+ var utils = require_utils6();
49326
49506
  var EntryFilter = class {
49327
49507
  constructor(_settings, _micromatchOptions) {
49328
49508
  this._settings = _settings;
@@ -49388,7 +49568,7 @@ var require_error = __commonJS({
49388
49568
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/providers/filters/error.js"(exports) {
49389
49569
  "use strict";
49390
49570
  Object.defineProperty(exports, "__esModule", { value: true });
49391
- var utils = require_utils5();
49571
+ var utils = require_utils6();
49392
49572
  var ErrorFilter = class {
49393
49573
  constructor(_settings) {
49394
49574
  this._settings = _settings;
@@ -49409,7 +49589,7 @@ var require_entry2 = __commonJS({
49409
49589
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/providers/transformers/entry.js"(exports) {
49410
49590
  "use strict";
49411
49591
  Object.defineProperty(exports, "__esModule", { value: true });
49412
- var utils = require_utils5();
49592
+ var utils = require_utils6();
49413
49593
  var EntryTransformer = class {
49414
49594
  constructor(_settings) {
49415
49595
  this._settings = _settings;
@@ -49520,12 +49700,12 @@ var require_async6 = __commonJS({
49520
49700
  });
49521
49701
 
49522
49702
  // node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/providers/stream.js
49523
- var require_stream4 = __commonJS({
49703
+ var require_stream5 = __commonJS({
49524
49704
  "node_modules/.pnpm/fast-glob@3.3.1/node_modules/fast-glob/out/providers/stream.js"(exports) {
49525
49705
  "use strict";
49526
49706
  Object.defineProperty(exports, "__esModule", { value: true });
49527
49707
  var stream_1 = require("stream");
49528
- var stream_2 = require_stream3();
49708
+ var stream_2 = require_stream4();
49529
49709
  var provider_1 = require_provider();
49530
49710
  var ProviderStream = class extends provider_1.default {
49531
49711
  constructor() {
@@ -49696,10 +49876,10 @@ var require_out4 = __commonJS({
49696
49876
  "use strict";
49697
49877
  var taskManager = require_tasks();
49698
49878
  var async_1 = require_async6();
49699
- var stream_1 = require_stream4();
49879
+ var stream_1 = require_stream5();
49700
49880
  var sync_1 = require_sync6();
49701
49881
  var settings_1 = require_settings4();
49702
- var utils = require_utils5();
49882
+ var utils = require_utils6();
49703
49883
  async function FastGlob(source, options) {
49704
49884
  assertPatternsInput2(source);
49705
49885
  const works = getWorks(source, async_1.default, options);
@@ -57932,7 +58112,7 @@ var require_dist2 = __commonJS({
57932
58112
  });
57933
58113
 
57934
58114
  // node_modules/.pnpm/webpod@0.0.2/node_modules/webpod/dist/utils.js
57935
- var init_utils3 = __esm({
58115
+ var init_utils4 = __esm({
57936
58116
  "node_modules/.pnpm/webpod@0.0.2/node_modules/webpod/dist/utils.js"() {
57937
58117
  }
57938
58118
  });
@@ -57940,7 +58120,7 @@ var init_utils3 = __esm({
57940
58120
  // node_modules/.pnpm/webpod@0.0.2/node_modules/webpod/dist/ssh.js
57941
58121
  var init_ssh = __esm({
57942
58122
  "node_modules/.pnpm/webpod@0.0.2/node_modules/webpod/dist/ssh.js"() {
57943
- init_utils3();
58123
+ init_utils4();
57944
58124
  }
57945
58125
  });
57946
58126
 
@@ -57986,8 +58166,17 @@ __export(wrangler_client_exports, {
57986
58166
  execute: () => execute
57987
58167
  });
57988
58168
  async function execute(query, configPath, dbName) {
57989
- const response = await $`NO_D1_WARNING=true wrangler d1 execute ${dbName} --config=${configPath} --command=${query} --json`;
57990
- return { results: JSON.parse(response.stdout)[0].results };
58169
+ try {
58170
+ const response = await $`NO_D1_WARNING=true wrangler d1 execute ${dbName} --config=${configPath} --command=${query} --json`;
58171
+ return { results: JSON.parse(response.stdout)[0].results };
58172
+ } catch (e) {
58173
+ try {
58174
+ await $`NO_D1_WARNING=true wrangler d1 execute ${dbName} --config=${configPath} --command=${query}`;
58175
+ } catch (e1) {
58176
+ throw new Error(e1.stdout);
58177
+ }
58178
+ throw e;
58179
+ }
57991
58180
  }
57992
58181
  var init_wrangler_client = __esm({
57993
58182
  "src/orm-extenstions/d1-driver/wrangler-client.ts"() {
@@ -58000,9 +58189,15 @@ var init_wrangler_client = __esm({
58000
58189
  var studioUtils_exports = {};
58001
58190
  __export(studioUtils_exports, {
58002
58191
  drizzleDb: () => drizzleDb,
58003
- prepareModels: () => prepareModels
58004
- });
58005
- var import_drizzle_orm14, import_mysql_core4, import_pg_core4, import_sqlite_core5, prepareModels, drizzleDb;
58192
+ drizzleForMySQL: () => drizzleForMySQL,
58193
+ drizzleForPostgres: () => drizzleForPostgres,
58194
+ drizzleForSQLite: () => drizzleForSQLite,
58195
+ prepareModels: () => prepareModels,
58196
+ prepareMySqlSchema: () => prepareMySqlSchema,
58197
+ preparePgSchema: () => preparePgSchema,
58198
+ prepareSQLiteSchema: () => prepareSQLiteSchema
58199
+ });
58200
+ var import_drizzle_orm14, import_mysql_core4, import_pg_core4, import_sqlite_core5, preparePgSchema, prepareMySqlSchema, prepareSQLiteSchema, prepareModels, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, drizzleDb;
58006
58201
  var init_studioUtils = __esm({
58007
58202
  "src/serializer/studioUtils.ts"() {
58008
58203
  import_drizzle_orm14 = require("drizzle-orm");
@@ -58010,11 +58205,80 @@ var init_studioUtils = __esm({
58010
58205
  import_pg_core4 = require("drizzle-orm/pg-core");
58011
58206
  import_sqlite_core5 = require("drizzle-orm/sqlite-core");
58012
58207
  init_utils();
58208
+ init_utils3();
58209
+ init_global();
58013
58210
  init_serializer();
58211
+ preparePgSchema = async (path4) => {
58212
+ const imports = prepareFilenames(path4);
58213
+ const pgSchema4 = {};
58214
+ const relations4 = {};
58215
+ const { unregister } = await safeRegister();
58216
+ for (let i = 0; i < imports.length; i++) {
58217
+ const it = imports[i];
58218
+ const i0 = require(`${it}`);
58219
+ const i0values = Object.entries(i0);
58220
+ i0values.forEach(([k, t]) => {
58221
+ if ((0, import_drizzle_orm14.is)(t, import_pg_core4.PgTable)) {
58222
+ const schema4 = (0, import_pg_core4.getTableConfig)(t).schema || "public";
58223
+ pgSchema4[schema4] = pgSchema4[schema4] || {};
58224
+ pgSchema4[schema4][k] = t;
58225
+ }
58226
+ if ((0, import_drizzle_orm14.is)(t, import_drizzle_orm14.Relations)) {
58227
+ relations4[k] = t;
58228
+ }
58229
+ });
58230
+ }
58231
+ unregister();
58232
+ return { schema: pgSchema4, relations: relations4 };
58233
+ };
58234
+ prepareMySqlSchema = async (path4) => {
58235
+ const imports = prepareFilenames(path4);
58236
+ const mysqlSchema4 = {};
58237
+ const relations4 = {};
58238
+ const { unregister } = await safeRegister();
58239
+ for (let i = 0; i < imports.length; i++) {
58240
+ const it = imports[i];
58241
+ const i0 = require(`${it}`);
58242
+ const i0values = Object.entries(i0);
58243
+ i0values.forEach(([k, t]) => {
58244
+ if ((0, import_drizzle_orm14.is)(t, import_mysql_core4.MySqlTable)) {
58245
+ const schema4 = (0, import_mysql_core4.getTableConfig)(t).schema || "public";
58246
+ mysqlSchema4[schema4][k] = t;
58247
+ }
58248
+ if ((0, import_drizzle_orm14.is)(t, import_drizzle_orm14.Relations)) {
58249
+ relations4[k] = t;
58250
+ }
58251
+ });
58252
+ }
58253
+ unregister();
58254
+ return { schema: mysqlSchema4, relations: relations4 };
58255
+ };
58256
+ prepareSQLiteSchema = async (path4) => {
58257
+ const imports = prepareFilenames(path4);
58258
+ const sqliteSchema2 = {};
58259
+ const relations4 = {};
58260
+ const { unregister } = await safeRegister();
58261
+ for (let i = 0; i < imports.length; i++) {
58262
+ const it = imports[i];
58263
+ const i0 = require(`${it}`);
58264
+ const i0values = Object.entries(i0);
58265
+ i0values.forEach(([k, t]) => {
58266
+ if ((0, import_drizzle_orm14.is)(t, import_sqlite_core5.SQLiteTable)) {
58267
+ const schema4 = "public";
58268
+ sqliteSchema2[schema4][k] = t;
58269
+ }
58270
+ if ((0, import_drizzle_orm14.is)(t, import_drizzle_orm14.Relations)) {
58271
+ relations4[k] = t;
58272
+ }
58273
+ });
58274
+ }
58275
+ unregister();
58276
+ return { schema: sqliteSchema2, relations: relations4 };
58277
+ };
58014
58278
  prepareModels = async (path4) => {
58015
58279
  const imports = prepareFilenames(path4);
58016
58280
  const sqliteSchema2 = {};
58017
- const pgSchema3 = {};
58281
+ const pgSchema4 = {};
58018
58282
  const mysqlSchema4 = {};
58019
58283
  const { unregister } = await safeRegister();
58020
58284
  for (let i = 0; i < imports.length; i++) {
@@ -58023,7 +58287,7 @@ var init_studioUtils = __esm({
58023
58287
  const i0values = Object.entries(i0);
58024
58288
  i0values.forEach(([k, t]) => {
58025
58289
  if ((0, import_drizzle_orm14.is)(t, import_pg_core4.PgTable)) {
58026
- pgSchema3[k] = t;
58290
+ pgSchema4[k] = t;
58027
58291
  }
58028
58292
  if ((0, import_drizzle_orm14.is)(t, import_mysql_core4.MySqlTable)) {
58029
58293
  mysqlSchema4[k] = t;
@@ -58033,22 +58297,96 @@ var init_studioUtils = __esm({
58033
58297
  }
58034
58298
  if ((0, import_drizzle_orm14.is)(t, import_drizzle_orm14.Relations)) {
58035
58299
  sqliteSchema2[k] = t;
58036
- pgSchema3[k] = t;
58300
+ pgSchema4[k] = t;
58037
58301
  mysqlSchema4[k] = t;
58038
58302
  }
58039
58303
  });
58040
58304
  }
58041
58305
  unregister();
58042
- return { pgSchema: pgSchema3, mysqlSchema: mysqlSchema4, sqliteSchema: sqliteSchema2 };
58306
+ return { pgSchema: pgSchema4, mysqlSchema: mysqlSchema4, sqliteSchema: sqliteSchema2 };
58307
+ };
58308
+ drizzleForPostgres = async (connectionConfig, pgSchema4, relations4, verbose) => {
58309
+ assertPackages("pg");
58310
+ const { drizzle: drizzle2 } = await import("drizzle-orm/node-postgres");
58311
+ const pg = await Promise.resolve().then(() => __toESM(require_lib2()));
58312
+ const db = drizzle2(new pg.default.Pool(connectionConfig.dbCredentials), {
58313
+ logger: verbose
58314
+ });
58315
+ return {
58316
+ type: "pg",
58317
+ db,
58318
+ schema: pgSchema4,
58319
+ relations: relations4
58320
+ };
58321
+ };
58322
+ drizzleForMySQL = async (config, mysqlSchema4, relations4, verbose) => {
58323
+ assertPackages("mysql2");
58324
+ const { drizzle: drizzle2 } = await import("drizzle-orm/mysql2");
58325
+ const { createPool } = await Promise.resolve().then(() => __toESM(require_promise()));
58326
+ const client = createPool({ ...config.dbCredentials, connectionLimit: 1 });
58327
+ const db = drizzle2(client, { logger: verbose });
58328
+ return {
58329
+ type: "mysql",
58330
+ db,
58331
+ schema: mysqlSchema4,
58332
+ relations: relations4
58333
+ };
58334
+ };
58335
+ drizzleForSQLite = async (config, sqliteSchema2, relations4, verbose) => {
58336
+ const { driver, dbCredentials: creds } = config;
58337
+ if (driver === "d1") {
58338
+ const { drizzle: drizzle2 } = await Promise.resolve().then(() => (init_driver(), driver_exports));
58339
+ const { execute: execute2 } = await Promise.resolve().then(() => (init_wrangler_client(), wrangler_client_exports));
58340
+ const db = drizzle2(execute2, creds.wranglerConfigPath, creds.dbName, {
58341
+ logger: verbose
58342
+ });
58343
+ return {
58344
+ type: "sqlite",
58345
+ db,
58346
+ schema: sqliteSchema2,
58347
+ relations: relations4
58348
+ };
58349
+ }
58350
+ if (driver === "better-sqlite") {
58351
+ assertPackages("better-sqlite3");
58352
+ const { drizzle: drizzle2 } = await import("drizzle-orm/better-sqlite3");
58353
+ const Database = await import("better-sqlite3");
58354
+ const client = new Database.default(creds.url);
58355
+ const db = drizzle2(client, { logger: verbose });
58356
+ return {
58357
+ type: "sqlite",
58358
+ db,
58359
+ schema: sqliteSchema2,
58360
+ relations: relations4
58361
+ };
58362
+ }
58363
+ if (driver === "libsql" || driver === "turso") {
58364
+ assertPackages("@libsql/client");
58365
+ const { drizzle: drizzle2 } = await import("drizzle-orm/libsql");
58366
+ const { createClient } = await import("@libsql/client");
58367
+ const client = createClient(creds);
58368
+ const db = drizzle2(
58369
+ client,
58370
+ { logger: verbose }
58371
+ );
58372
+ return {
58373
+ type: "sqlite",
58374
+ db,
58375
+ schema: sqliteSchema2,
58376
+ relations: relations4
58377
+ };
58378
+ }
58379
+ assertUnreachable(driver);
58043
58380
  };
58044
58381
  drizzleDb = async (drizzleConfig, models, logger) => {
58045
58382
  if (drizzleConfig.driver === "pg") {
58046
58383
  const { drizzle: drizzle2 } = await import("drizzle-orm/node-postgres");
58047
- const { Pool, types } = await Promise.resolve().then(() => __toESM(require_lib2()));
58048
- const client = new Pool({ ...drizzleConfig.dbCredentials, max: 1 });
58049
- types.setTypeParser(types.builtins.INTERVAL, (val) => val);
58384
+ const pg = await Promise.resolve().then(() => __toESM(require_lib2()));
58385
+ const db = drizzle2(new pg.default.Pool(drizzleConfig.dbCredentials), {
58386
+ logger
58387
+ });
58050
58388
  return {
58051
- db: drizzle2(client, { logger }),
58389
+ db,
58052
58390
  type: "pg",
58053
58391
  schema: models.pgSchema
58054
58392
  };
@@ -58056,12 +58394,7 @@ var init_studioUtils = __esm({
58056
58394
  const { drizzle: drizzle2 } = await import("drizzle-orm/mysql2");
58057
58395
  const { createPool } = await Promise.resolve().then(() => __toESM(require_promise()));
58058
58396
  const client = createPool({
58059
- uri: drizzleConfig.dbCredentials.type === "url" ? drizzleConfig.dbCredentials.connectionString : void 0,
58060
- host: drizzleConfig.dbCredentials.type === "params" ? drizzleConfig.dbCredentials.host : void 0,
58061
- port: drizzleConfig.dbCredentials.type === "params" ? drizzleConfig.dbCredentials.port : void 0,
58062
- user: drizzleConfig.dbCredentials.type === "params" ? drizzleConfig.dbCredentials.user : void 0,
58063
- database: drizzleConfig.dbCredentials.type === "params" ? drizzleConfig.dbCredentials.database : void 0,
58064
- password: drizzleConfig.dbCredentials.type === "params" ? drizzleConfig.dbCredentials.password : void 0,
58397
+ ...drizzleConfig.dbCredentials,
58065
58398
  connectionLimit: 1
58066
58399
  });
58067
58400
  return {
@@ -58109,7 +58442,7 @@ var init_studioUtils = __esm({
58109
58442
 
58110
58443
  // src/utils.ts
58111
58444
  var import_fs8, import_path5, assertV1OutFolder, dryJournal, snapshotsPriorV4, prepareOutFolder2, mapValues, validatorForDialect, validateWithReport, prepareMigrationFolder, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
58112
- var init_utils4 = __esm({
58445
+ var init_utils5 = __esm({
58113
58446
  "src/utils.ts"() {
58114
58447
  import_fs8 = require("fs");
58115
58448
  init_views();
@@ -58701,7 +59034,7 @@ var init_pg = __esm({
58701
59034
  });
58702
59035
 
58703
59036
  // src/cli/validations/mysql.ts
58704
- var mysqlConnectionCli, mysqlConnectionConfig, mysqlConfigIntrospectSchema, mysqlCliIntrospectParams, mysqlCliPushParams, mysqlConfigPushParams, printCliConnectionIssues3, printConfigConnectionIssues3, validateMySqlIntrospect, validateMySqlPush;
59037
+ var mysqlConnectionCli, mysql2credentials, mysqlConnectionConfig, mysqlConfigIntrospectSchema, mysqlCliIntrospectParams, mysqlCliPushParams, mysqlConfigPushParams, printCliConnectionIssues3, printConfigConnectionIssues3, validateMySqlIntrospect, validateMySqlPush;
58705
59038
  var init_mysql = __esm({
58706
59039
  "src/cli/validations/mysql.ts"() {
58707
59040
  init_lib();
@@ -58715,35 +59048,31 @@ var init_mysql = __esm({
58715
59048
  port: coerce.number().optional(),
58716
59049
  user: stringType().default("mysql"),
58717
59050
  password: stringType().optional(),
58718
- database: stringType(),
58719
- type: literalType("params").default("params")
59051
+ database: stringType()
58720
59052
  }),
58721
59053
  objectType({
58722
59054
  driver: literalType("mysql2"),
58723
- connectionString: stringType(),
58724
- type: literalType("url").default("url")
59055
+ uri: stringType()
59056
+ // TODO: change docs
58725
59057
  })
58726
59058
  ]);
58727
- mysqlConnectionConfig = unionType([
59059
+ mysql2credentials = unionType([
58728
59060
  objectType({
58729
- driver: literalType("mysql2"),
58730
- dbCredentials: objectType({
58731
- host: stringType(),
58732
- port: coerce.number().optional(),
58733
- user: stringType().default("mysql"),
58734
- password: stringType().optional(),
58735
- database: stringType(),
58736
- type: literalType("params").default("params")
58737
- })
59061
+ host: stringType(),
59062
+ port: coerce.number().optional(),
59063
+ user: stringType().default("mysql"),
59064
+ password: stringType().optional(),
59065
+ database: stringType()
58738
59066
  }),
58739
59067
  objectType({
58740
- driver: literalType("mysql2"),
58741
- dbCredentials: objectType({
58742
- connectionString: stringType(),
58743
- type: literalType("url").default("url")
58744
- })
59068
+ uri: stringType()
59069
+ // TODO: change docs
58745
59070
  })
58746
59071
  ]);
59072
+ mysqlConnectionConfig = objectType({
59073
+ driver: literalType("mysql2"),
59074
+ dbCredentials: mysql2credentials
59075
+ });
58747
59076
  mysqlConfigIntrospectSchema = intersectionType(
58748
59077
  configIntrospectSchema,
58749
59078
  mysqlConnectionConfig
@@ -58761,22 +59090,22 @@ var init_mysql = __esm({
58761
59090
  mysqlConnectionConfig
58762
59091
  );
58763
59092
  printCliConnectionIssues3 = (options) => {
58764
- if (options.driver === "mysql2") {
58765
- if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
58766
- console.log(outputs.mysql.connection.required());
58767
- }
58768
- } else {
59093
+ const { driver, uri, host, database } = options || {};
59094
+ if (driver !== "mysql2") {
58769
59095
  console.log(outputs.mysql.connection.driver());
58770
59096
  }
59097
+ if (!uri && (!host || !database)) {
59098
+ console.log(outputs.mysql.connection.required());
59099
+ }
58771
59100
  };
58772
59101
  printConfigConnectionIssues3 = (options) => {
58773
- if (options.driver === "mysql2") {
58774
- if (typeof options.dbCredentials.connectionString === "undefined" && (typeof options.dbCredentials.host === "undefined" || typeof options.dbCredentials.database === "undefined")) {
58775
- console.log(outputs.mysql.connection.required());
58776
- }
58777
- } else {
59102
+ if (options.driver !== "mysql2") {
58778
59103
  console.log(outputs.mysql.connection.driver());
58779
59104
  }
59105
+ const { uri, host, database } = options.dbCredentials || {};
59106
+ if (!uri && (!host || !database)) {
59107
+ console.log(outputs.mysql.connection.required());
59108
+ }
58780
59109
  };
58781
59110
  validateMySqlIntrospect = async (options) => {
58782
59111
  const collisionRes = checkCollisions(options, "introspect:mysql");
@@ -58798,28 +59127,25 @@ var init_mysql = __esm({
58798
59127
  printCliConnectionIssues3(options);
58799
59128
  process.exit(1);
58800
59129
  }
58801
- if (cliRes.data.type === "url") {
58802
- const { connectionString, introspectCasing: introspectCasing3, type: type2, ...rest2 } = cliRes.data;
58803
- return {
58804
- ...rest2,
58805
- dbCredentials: { connectionString, type: type2 },
58806
- introspect: { casing: introspectCasing3 }
58807
- };
58808
- }
58809
59130
  const {
58810
- host,
58811
- password,
58812
- port,
58813
- database,
58814
- user,
58815
- type,
59131
+ out,
59132
+ schema: schema4,
59133
+ driver,
59134
+ schemaFilter,
59135
+ tablesFilter,
59136
+ breakpoints,
58816
59137
  introspectCasing: introspectCasing2,
58817
59138
  ...rest
58818
59139
  } = cliRes.data;
58819
59140
  return {
58820
- ...rest,
58821
- dbCredentials: { host, password, port, database, user, type },
58822
- introspect: { casing: introspectCasing2 }
59141
+ out,
59142
+ schema: schema4,
59143
+ driver,
59144
+ schemaFilter,
59145
+ tablesFilter,
59146
+ breakpoints,
59147
+ introspect: { casing: introspectCasing2 },
59148
+ dbCredentials: rest
58823
59149
  };
58824
59150
  };
58825
59151
  validateMySqlPush = async (options) => {
@@ -58846,24 +59172,30 @@ var init_mysql = __esm({
58846
59172
  printCliConnectionIssues3(options);
58847
59173
  process.exit(1);
58848
59174
  }
58849
- if (cliRes.data.type === "url") {
58850
- const { connectionString, type: type2, ...rest2 } = cliRes.data;
58851
- return {
58852
- ...rest2,
58853
- dbCredentials: { connectionString, type: type2 }
58854
- };
58855
- }
58856
- const { host, password, port, database, user, type, ...rest } = cliRes.data;
59175
+ const {
59176
+ strict,
59177
+ verbose,
59178
+ schema: schema4,
59179
+ driver,
59180
+ schemaFilter,
59181
+ tablesFilter,
59182
+ ...rest
59183
+ } = cliRes.data;
58857
59184
  return {
58858
- ...rest,
58859
- dbCredentials: { host, password, port, database, user, type }
59185
+ driver,
59186
+ schema: schema4,
59187
+ strict,
59188
+ verbose,
59189
+ tablesFilter,
59190
+ schemaFilter,
59191
+ dbCredentials: rest
58860
59192
  };
58861
59193
  };
58862
59194
  }
58863
59195
  });
58864
59196
 
58865
59197
  // node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json
58866
- var require_package2 = __commonJS({
59198
+ var require_package = __commonJS({
58867
59199
  "node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json"(exports, module2) {
58868
59200
  module2.exports = {
58869
59201
  name: "dotenv",
@@ -58934,7 +59266,7 @@ var require_main = __commonJS({
58934
59266
  var fs8 = require("fs");
58935
59267
  var path4 = require("path");
58936
59268
  var os2 = require("os");
58937
- var packageJson = require_package2();
59269
+ var packageJson = require_package();
58938
59270
  var version = packageJson.version;
58939
59271
  var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
58940
59272
  function parse(src) {
@@ -59610,12 +59942,10 @@ var init_mysqlIntrospect = __esm({
59610
59942
  init_global();
59611
59943
  init_mjs();
59612
59944
  connectToMySQL = async (config) => {
59613
- let client;
59945
+ const client = await (0, import_promise.createConnection)(config.dbCredentials);
59614
59946
  let databaseName;
59615
- if (config.dbCredentials.type === "url") {
59616
- const connection = config.dbCredentials.connectionString;
59617
- client = await (0, import_promise.createConnection)(connection);
59618
- const connectionUrl = new URL(connection);
59947
+ if ("uri" in config.dbCredentials) {
59948
+ const connectionUrl = new URL(config.dbCredentials.uri);
59619
59949
  const pathname = connectionUrl.pathname;
59620
59950
  databaseName = pathname.split("/")[pathname.split("/").length - 1];
59621
59951
  if (!databaseName || databaseName === "") {
@@ -59623,10 +59953,8 @@ var init_mysqlIntrospect = __esm({
59623
59953
  "You should specify a database name in connection string (mysql://USER:PASSWORD@HOST:PORT/DATABASE)"
59624
59954
  );
59625
59955
  }
59626
- } else if (config.dbCredentials.type === "params") {
59627
- const { type, ...creds } = config.dbCredentials;
59628
- client = await (0, import_promise.createConnection)(creds);
59629
- databaseName = creds.database;
59956
+ } else if ("database" in config.dbCredentials) {
59957
+ databaseName = config.dbCredentials.database;
59630
59958
  } else {
59631
59959
  throw Error(
59632
59960
  "Either `connectionString` or `host, port, etc.` params be provided in config file"
@@ -59691,9 +60019,10 @@ __export(studio_exports, {
59691
60019
  studioConfidConnections: () => studioConfidConnections,
59692
60020
  studioConfigSchema: () => studioConfigSchema,
59693
60021
  studioSpecificConnections: () => studioSpecificConnections,
60022
+ stuioSqliteConnectionConfig: () => stuioSqliteConnectionConfig,
59694
60023
  validateStudio: () => validateStudio
59695
60024
  });
59696
- var studioSpecificConnections, studioConfidConnections, studioConfigSchema, printDriverIssues, validateStudio;
60025
+ var studioSpecificConnections, stuioSqliteConnectionConfig, studioConfidConnections, studioConfigSchema, printDriverIssues, validateStudio;
59697
60026
  var init_studio = __esm({
59698
60027
  "src/cli/validations/studio.ts"() {
59699
60028
  init_lib();
@@ -59712,6 +60041,7 @@ var init_studio = __esm({
59712
60041
  dbName: stringType()
59713
60042
  })
59714
60043
  });
60044
+ stuioSqliteConnectionConfig = unionType([sqliteConnectionSchema, studioSpecificConnections]);
59715
60045
  studioConfidConnections = unionType([mysqlConnectionConfig, pgConnectionConfig, sqliteConnectionSchema, studioSpecificConnections]);
59716
60046
  studioConfigSchema = intersectionType(
59717
60047
  objectType({
@@ -59767,7 +60097,7 @@ var import_fs11 = require("fs");
59767
60097
  init_lib();
59768
60098
 
59769
60099
  // src/cli/commands/check.ts
59770
- init_utils4();
60100
+ init_utils5();
59771
60101
  var checkHandler = (out, dialect6) => {
59772
60102
  const { snapshots } = prepareOutFolder2(out, dialect6);
59773
60103
  const report = validateWithReport(snapshots, dialect6);
@@ -59806,54 +60136,7 @@ var checkHandler = (out, dialect6) => {
59806
60136
  // src/cli/index.ts
59807
60137
  var import_hanji11 = __toESM(require_hanji());
59808
60138
  var import_path7 = __toESM(require("path"));
59809
-
59810
- // src/cli/utils.ts
59811
- init_views();
59812
- var assertPackages = async (...pkgs) => {
59813
- try {
59814
- for (let i = 0; i < pkgs.length; i++) {
59815
- const it = pkgs[i];
59816
- await import(it);
59817
- }
59818
- } catch (e) {
59819
- err(
59820
- `please install required packages: ${pkgs.map((it) => `'${it}'`).join(" ")}`
59821
- );
59822
- process.exit(1);
59823
- }
59824
- };
59825
- var requiredApiVersion = 5;
59826
- var assertOrmCoreVersion = async () => {
59827
- try {
59828
- const { compatibilityVersion } = await import("drizzle-orm/version");
59829
- if (compatibilityVersion && compatibilityVersion === requiredApiVersion)
59830
- return;
59831
- if (!compatibilityVersion || compatibilityVersion < requiredApiVersion) {
59832
- console.log(
59833
- "This version of drizzle-kit requires newer version of drizzle-orm\nPlease update drizzle-orm package to the latest version \u{1F44D}"
59834
- );
59835
- } else {
59836
- console.log(
59837
- "This version of drizzle-kit is outdated\nPlease update drizzle-kit package to the latest version \u{1F44D}"
59838
- );
59839
- }
59840
- } catch (e) {
59841
- console.log(
59842
- "Please install latest version of drizzle-orm"
59843
- );
59844
- }
59845
- process.exit(1);
59846
- };
59847
- var ormCoreVersions = async () => {
59848
- try {
59849
- const { compatibilityVersion, npmVersion } = await import("drizzle-orm/version");
59850
- return { compatibilityVersion, npmVersion };
59851
- } catch (e) {
59852
- return {};
59853
- }
59854
- };
59855
-
59856
- // src/cli/index.ts
60139
+ init_utils3();
59857
60140
  init_source();
59858
60141
 
59859
60142
  // package.json
@@ -59899,7 +60182,8 @@ var package_default = {
59899
60182
  packit: "pnpm build && cp package.json dist/ && cd dist && pnpm pack",
59900
60183
  tsc: "tsc -p tsconfig.build.json",
59901
60184
  pub: "cp package.json readme.md dist/ && cd dist && npm publish",
59902
- studio: "./dist/index.cjs studio --verbose"
60185
+ studio: "./dist/index.cjs studio --verbose",
60186
+ "studio:dev": "tsx ./src/cli/index.ts studio --verbose"
59903
60187
  },
59904
60188
  ava: {
59905
60189
  files: [
@@ -59913,7 +60197,7 @@ var package_default = {
59913
60197
  ]
59914
60198
  },
59915
60199
  dependencies: {
59916
- "@drizzle-team/studio": "^0.0.9",
60200
+ "@drizzle-team/studio": "^0.0.27",
59917
60201
  "@esbuild-kit/esm-loader": "^2.5.5",
59918
60202
  camelcase: "^7.0.1",
59919
60203
  chalk: "^5.2.0",
@@ -59935,20 +60219,20 @@ var package_default = {
59935
60219
  "@types/glob": "^8.1.0",
59936
60220
  "@types/minimatch": "^5.1.2",
59937
60221
  "@types/node": "^18.11.15",
59938
- "@types/pg": "^8.6.5",
60222
+ "@types/pg": "^8.10.7",
59939
60223
  "@typescript-eslint/eslint-plugin": "^5.46.1",
59940
60224
  "@typescript-eslint/parser": "^5.46.1",
59941
60225
  ava: "^5.1.0",
59942
60226
  "better-sqlite3": "^8.4.0",
59943
60227
  dockerode: "^3.3.4",
59944
60228
  dotenv: "^16.0.3",
59945
- "drizzle-orm": "0.28.7-4e094f0",
60229
+ "drizzle-orm": "0.29.0-d3b1c58",
59946
60230
  eslint: "^8.29.0",
59947
60231
  "eslint-config-prettier": "^8.5.0",
59948
60232
  "eslint-plugin-prettier": "^4.2.1",
59949
60233
  "get-port": "^6.1.2",
59950
60234
  mysql2: "2.3.3",
59951
- pg: "^8.8.0",
60235
+ pg: "^8.11.3",
59952
60236
  postgres: "^3.3.5",
59953
60237
  prettier: "^2.8.1",
59954
60238
  tsx: "^3.12.1",
@@ -59962,14 +60246,14 @@ var package_default = {
59962
60246
  init_migrate();
59963
60247
  init_utils2();
59964
60248
  init_pgSchema();
59965
- init_utils4();
60249
+ init_utils5();
59966
60250
  init_pgUp();
59967
60251
 
59968
60252
  // src/cli/commands/sqliteUp.ts
59969
60253
  init_source();
59970
60254
  var import_fs9 = __toESM(require("fs"));
59971
60255
  init_sqliteSchema();
59972
- init_utils4();
60256
+ init_utils5();
59973
60257
  var upSqliteHandler = (out) => {
59974
60258
  };
59975
60259
  var upSqliteHandlerV4 = (out) => {
@@ -60560,7 +60844,7 @@ init_common();
60560
60844
  init_mysql();
60561
60845
  init_pgPushUtils();
60562
60846
  init_outputs();
60563
- var import_studio = require("@drizzle-team/studio");
60847
+ var import_server = require("@drizzle-team/studio/server");
60564
60848
  init_sqlgenerator();
60565
60849
 
60566
60850
  // node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/config.js
@@ -60576,6 +60860,7 @@ init_sqlgenerator();
60576
60860
 
60577
60861
  // src/cli/index.ts
60578
60862
  init_selector_ui();
60863
+ init_global();
60579
60864
  var printVersions = async () => {
60580
60865
  const v = await versions();
60581
60866
  console.log(`${source_default.gray(v)}
@@ -61266,14 +61551,44 @@ var dropCommand = new import_commander.Command("drop").option("--out <out>", `Ou
61266
61551
  var studioCommand = new import_commander.Command("studio").option("--port <port>", "Custom port for drizzle studio [default=4983]").option("--host <host>", "Custom host for drizzle studio [default=0.0.0.0]").option("--verbose", "Print all stataments that are executed by Studio").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
61267
61552
  const { validateStudio: validateStudio2 } = await Promise.resolve().then(() => (init_studio(), studio_exports));
61268
61553
  const drizzleConfig = await validateStudio2(options);
61269
- const { prepareModels: prepareModels2, drizzleDb: drizzleDb2 } = await Promise.resolve().then(() => (init_studioUtils(), studioUtils_exports));
61270
- const models = await prepareModels2(drizzleConfig.schema);
61271
- const setup = await drizzleDb2(
61272
- drizzleConfig,
61273
- models,
61274
- options.verbose
61275
- );
61276
- const server = await (0, import_studio.prepareServer)(setup);
61554
+ const {
61555
+ drizzleForPostgres: drizzleForPostgres2,
61556
+ preparePgSchema: preparePgSchema2,
61557
+ prepareMySqlSchema: prepareMySqlSchema2,
61558
+ drizzleForMySQL: drizzleForMySQL2,
61559
+ prepareSQLiteSchema: prepareSQLiteSchema2,
61560
+ drizzleForSQLite: drizzleForSQLite2
61561
+ } = await Promise.resolve().then(() => (init_studioUtils(), studioUtils_exports));
61562
+ const { driver, schema: schemaPath } = drizzleConfig;
61563
+ let setup;
61564
+ if (driver === "pg") {
61565
+ const { schema: schema4, relations: relations4 } = await preparePgSchema2(schemaPath);
61566
+ setup = await drizzleForPostgres2(
61567
+ drizzleConfig,
61568
+ schema4,
61569
+ relations4,
61570
+ Boolean(options.verbose)
61571
+ );
61572
+ } else if (driver === "mysql2") {
61573
+ const { schema: schema4, relations: relations4 } = await prepareMySqlSchema2(schemaPath);
61574
+ setup = await drizzleForMySQL2(
61575
+ drizzleConfig,
61576
+ schema4,
61577
+ relations4,
61578
+ Boolean(options.verbose)
61579
+ );
61580
+ } else if (driver === "better-sqlite" || driver === "d1" || driver === "libsql" || driver === "turso") {
61581
+ const { schema: schema4, relations: relations4 } = await prepareSQLiteSchema2(schemaPath);
61582
+ setup = await drizzleForSQLite2(
61583
+ drizzleConfig,
61584
+ schema4,
61585
+ relations4,
61586
+ Boolean(options.verbose)
61587
+ );
61588
+ } else {
61589
+ assertUnreachable(driver);
61590
+ }
61591
+ const server = await (0, import_server.prepareServer)(setup);
61277
61592
  const port = options.port ?? 4983;
61278
61593
  const host = options.host ?? "127.0.0.1";
61279
61594
  console.log();
@@ -61282,6 +61597,13 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
61282
61597
  "Drizzle Studio is currently in Beta. If you find anything that is not working as expected or should be improved, feel free to create an issue on GitHub: https://github.com/drizzle-team/drizzle-kit-mirror/issues/new or write to us on Discord: https://discord.gg/WcRKz2FFxN"
61283
61598
  )
61284
61599
  );
61600
+ if (driver === "d1") {
61601
+ console.log(
61602
+ withStyle.fullWarning(
61603
+ "It seems like you are trying to access your D1 Database. Please make sure to run 'wrangler login' before using Drizzle Studio to ensure it has your token for making requests to the D1 Database. If you encounter an error related to CLOUDFLARE_TOKEN, please run 'wrangler login' and restart the studio"
61604
+ )
61605
+ );
61606
+ }
61285
61607
  server.start({
61286
61608
  host,
61287
61609
  port,