drizzle-kit 0.20.17-84934d2 → 0.20.17-90c7298
Sign up to get free protection for your applications and to get access to all the features.
- package/@types/utils.d.ts +1 -0
- package/bin.cjs +101 -179
- package/cli/validations/cli.d.ts +1 -1
- package/cli/views.d.ts +1 -0
- package/package.json +1 -1
- package/payload.js +4 -1
- package/payload.mjs +4 -1
- package/utils-studio.js +3 -0
- package/utils-studio.mjs +3 -0
package/@types/utils.d.ts
CHANGED
package/bin.cjs
CHANGED
@@ -1076,7 +1076,7 @@ var require_hanji = __commonJS({
|
|
1076
1076
|
});
|
1077
1077
|
|
1078
1078
|
// src/cli/views.ts
|
1079
|
-
var import_hanji, err, info, error, schema, isRenamePromptItem, ResolveColumnSelect, tableKey, ResolveSelect, ResolveSchemasSelect, Spinner, IntrospectProgress, DropMigrationView, trimmedRange;
|
1079
|
+
var import_hanji, err, info, grey, error, schema, isRenamePromptItem, ResolveColumnSelect, tableKey, ResolveSelect, ResolveSchemasSelect, Spinner, IntrospectProgress, DropMigrationView, trimmedRange;
|
1080
1080
|
var init_views = __esm({
|
1081
1081
|
"src/cli/views.ts"() {
|
1082
1082
|
"use strict";
|
@@ -1089,6 +1089,9 @@ var init_views = __esm({
|
|
1089
1089
|
info = (msg, greyMsg = "") => {
|
1090
1090
|
return `${source_default.blue.bold("Info:")} ${msg} ${greyMsg ? source_default.grey(greyMsg) : ""}`.trim();
|
1091
1091
|
};
|
1092
|
+
grey = (msg) => {
|
1093
|
+
return source_default.grey(msg);
|
1094
|
+
};
|
1092
1095
|
error = (error2, greyMsg = "") => {
|
1093
1096
|
return `${source_default.red.bold("Err:")} ${error2} ${greyMsg ? source_default.grey(greyMsg) : ""}`.trim();
|
1094
1097
|
};
|
@@ -1339,14 +1342,14 @@ Is ${source_default.bold.blue(
|
|
1339
1342
|
this.requestLayout();
|
1340
1343
|
}
|
1341
1344
|
render() {
|
1342
|
-
let
|
1345
|
+
let info4 = "";
|
1343
1346
|
const spin = this.spinner.value();
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
return
|
1347
|
+
info4 += this.statusText(spin, this.state.tables);
|
1348
|
+
info4 += this.statusText(spin, this.state.columns);
|
1349
|
+
info4 += this.statusText(spin, this.state.enums);
|
1350
|
+
info4 += this.statusText(spin, this.state.indexes);
|
1351
|
+
info4 += this.statusText(spin, this.state.fks);
|
1352
|
+
return info4;
|
1350
1353
|
}
|
1351
1354
|
};
|
1352
1355
|
DropMigrationView = class extends import_hanji.Prompt {
|
@@ -8320,6 +8323,9 @@ var init_utils3 = __esm({
|
|
8320
8323
|
String.prototype.camelCase = function() {
|
8321
8324
|
return camelCase(String(this));
|
8322
8325
|
};
|
8326
|
+
String.prototype.capitalise = function() {
|
8327
|
+
return this && this.length > 0 ? `${this[0].toUpperCase()}${this.slice(1)}` : String(this);
|
8328
|
+
};
|
8323
8329
|
String.prototype.concatIf = function(it, condition) {
|
8324
8330
|
return condition ? `${this}${it}` : String(this);
|
8325
8331
|
};
|
@@ -8700,7 +8706,7 @@ var init_cli = __esm({
|
|
8700
8706
|
authToken: stringType().optional(),
|
8701
8707
|
introspectCasing: casing,
|
8702
8708
|
breakpoints: booleanType().optional().default(true)
|
8703
|
-
});
|
8709
|
+
}).passthrough();
|
8704
8710
|
configCheck = objectType({
|
8705
8711
|
dialect: dialect3.optional(),
|
8706
8712
|
out: stringType().optional()
|
@@ -11743,13 +11749,13 @@ var require_node2 = __commonJS({
|
|
11743
11749
|
}
|
11744
11750
|
function asyncGeneratorStep(gen, resolve2, reject, _next, _throw, key, arg) {
|
11745
11751
|
try {
|
11746
|
-
var
|
11747
|
-
var value =
|
11752
|
+
var info4 = gen[key](arg);
|
11753
|
+
var value = info4.value;
|
11748
11754
|
} catch (error2) {
|
11749
11755
|
reject(error2);
|
11750
11756
|
return;
|
11751
11757
|
}
|
11752
|
-
if (
|
11758
|
+
if (info4.done) {
|
11753
11759
|
resolve2(value);
|
11754
11760
|
} else {
|
11755
11761
|
Promise.resolve(value).then(_next, _throw);
|
@@ -28299,7 +28305,7 @@ var require_partial = __commonJS({
|
|
28299
28305
|
match(filepath) {
|
28300
28306
|
const parts = filepath.split("/");
|
28301
28307
|
const levels = parts.length;
|
28302
|
-
const patterns = this._storage.filter((
|
28308
|
+
const patterns = this._storage.filter((info4) => !info4.complete || info4.segments.length > levels);
|
28303
28309
|
for (const pattern of patterns) {
|
28304
28310
|
const section = pattern.sections[0];
|
28305
28311
|
if (!pattern.complete && levels > section.length) {
|
@@ -36952,14 +36958,14 @@ var init_dist = __esm({
|
|
36952
36958
|
if (typeof global.crypto === "undefined") {
|
36953
36959
|
global.crypto = import_crypto2.default;
|
36954
36960
|
}
|
36955
|
-
global.fetch = (
|
36961
|
+
global.fetch = (info4, init2) => {
|
36956
36962
|
init2 = {
|
36957
36963
|
// Disable compression handling so people can return the result of a fetch
|
36958
36964
|
// directly in the loader without messing with the Content-Encoding header.
|
36959
36965
|
compress: false,
|
36960
36966
|
...init2
|
36961
36967
|
};
|
36962
|
-
return webFetch(
|
36968
|
+
return webFetch(info4, init2);
|
36963
36969
|
};
|
36964
36970
|
regBuffer = /^no$/i;
|
36965
36971
|
regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
@@ -43609,13 +43615,13 @@ var require_websocket_server = __commonJS({
|
|
43609
43615
|
}
|
43610
43616
|
}
|
43611
43617
|
if (this.options.verifyClient) {
|
43612
|
-
const
|
43618
|
+
const info4 = {
|
43613
43619
|
origin: req.headers[`${version2 === 8 ? "sec-websocket-origin" : "origin"}`],
|
43614
43620
|
secure: !!(req.socket.authorized || req.socket.encrypted),
|
43615
43621
|
req
|
43616
43622
|
};
|
43617
43623
|
if (this.options.verifyClient.length === 2) {
|
43618
|
-
this.options.verifyClient(
|
43624
|
+
this.options.verifyClient(info4, (verified, code, message, headers) => {
|
43619
43625
|
if (!verified) {
|
43620
43626
|
return abortHandshake(socket, code || 401, message, headers);
|
43621
43627
|
}
|
@@ -43631,7 +43637,7 @@ var require_websocket_server = __commonJS({
|
|
43631
43637
|
});
|
43632
43638
|
return;
|
43633
43639
|
}
|
43634
|
-
if (!this.options.verifyClient(
|
43640
|
+
if (!this.options.verifyClient(info4))
|
43635
43641
|
return abortHandshake(socket, 401);
|
43636
43642
|
}
|
43637
43643
|
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
@@ -54993,7 +54999,7 @@ var require_dist_cjs42 = __commonJS({
|
|
54993
54999
|
calculateBodyLength: () => calculateBodyLength
|
54994
55000
|
});
|
54995
55001
|
module2.exports = __toCommonJS2(src_exports2);
|
54996
|
-
var
|
55002
|
+
var import_fs13 = require("fs");
|
54997
55003
|
var calculateBodyLength = /* @__PURE__ */ __name((body) => {
|
54998
55004
|
if (!body) {
|
54999
55005
|
return 0;
|
@@ -55007,9 +55013,9 @@ var require_dist_cjs42 = __commonJS({
|
|
55007
55013
|
} else if (typeof body.start === "number" && typeof body.end === "number") {
|
55008
55014
|
return body.end + 1 - body.start;
|
55009
55015
|
} else if (typeof body.path === "string" || Buffer.isBuffer(body.path)) {
|
55010
|
-
return (0,
|
55016
|
+
return (0, import_fs13.lstatSync)(body.path).size;
|
55011
55017
|
} else if (typeof body.fd === "number") {
|
55012
|
-
return (0,
|
55018
|
+
return (0, import_fs13.fstatSync)(body.fd).size;
|
55013
55019
|
}
|
55014
55020
|
throw new Error(`Body Length computation failed for ${body}`);
|
55015
55021
|
}, "calculateBodyLength");
|
@@ -57316,8 +57322,8 @@ var require_dist_cjs47 = __commonJS({
|
|
57316
57322
|
}
|
57317
57323
|
}, "validateTokenKey");
|
57318
57324
|
var import_shared_ini_file_loader = require_dist_cjs13();
|
57319
|
-
var
|
57320
|
-
var { writeFile } =
|
57325
|
+
var import_fs13 = require("fs");
|
57326
|
+
var { writeFile } = import_fs13.promises;
|
57321
57327
|
var writeSSOTokenToFile = /* @__PURE__ */ __name((id, ssoToken) => {
|
57322
57328
|
const tokenFilepath = (0, import_shared_ini_file_loader.getSSOTokenFilepath)(id);
|
57323
57329
|
const tokenString = JSON.stringify(ssoToken, null, 2);
|
@@ -83234,13 +83240,13 @@ var require_websocket_server2 = __commonJS({
|
|
83234
83240
|
}
|
83235
83241
|
}
|
83236
83242
|
if (this.options.verifyClient) {
|
83237
|
-
const
|
83243
|
+
const info4 = {
|
83238
83244
|
origin: req.headers[`${version2 === 8 ? "sec-websocket-origin" : "origin"}`],
|
83239
83245
|
secure: !!(req.socket.authorized || req.socket.encrypted),
|
83240
83246
|
req
|
83241
83247
|
};
|
83242
83248
|
if (this.options.verifyClient.length === 2) {
|
83243
|
-
this.options.verifyClient(
|
83249
|
+
this.options.verifyClient(info4, (verified, code, message, headers) => {
|
83244
83250
|
if (!verified) {
|
83245
83251
|
return abortHandshake(socket, code || 401, message, headers);
|
83246
83252
|
}
|
@@ -83256,7 +83262,7 @@ var require_websocket_server2 = __commonJS({
|
|
83256
83262
|
});
|
83257
83263
|
return;
|
83258
83264
|
}
|
83259
|
-
if (!this.options.verifyClient(
|
83265
|
+
if (!this.options.verifyClient(info4))
|
83260
83266
|
return abortHandshake(socket, 401);
|
83261
83267
|
}
|
83262
83268
|
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
@@ -99674,7 +99680,7 @@ __export(connections_exports, {
|
|
99674
99680
|
connectToSQLite: () => connectToSQLite,
|
99675
99681
|
preparePostgresDB: () => preparePostgresDB
|
99676
99682
|
});
|
99677
|
-
var preparePostgresDB, parseMysqlCredentials, connectToMySQL, prepareSqliteParams, connectToSQLite;
|
99683
|
+
var import_pg_core4, preparePostgresDB, parseMysqlCredentials, connectToMySQL, prepareSqliteParams, connectToSQLite;
|
99678
99684
|
var init_connections = __esm({
|
99679
99685
|
"src/cli/connections.ts"() {
|
99680
99686
|
"use strict";
|
@@ -99682,143 +99688,37 @@ var init_connections = __esm({
|
|
99682
99688
|
init_utils2();
|
99683
99689
|
init_global();
|
99684
99690
|
init_outputs();
|
99691
|
+
import_pg_core4 = require("drizzle-orm/pg-core");
|
99685
99692
|
preparePostgresDB = async (credentials2) => {
|
99686
99693
|
if ("driver" in credentials2) {
|
99687
99694
|
if (credentials2.driver === "aws-data-api") {
|
99688
|
-
let getValueFromDataApi2 = function(field) {
|
99689
|
-
if (field.stringValue !== void 0) {
|
99690
|
-
return field.stringValue;
|
99691
|
-
} else if (field.booleanValue !== void 0) {
|
99692
|
-
return field.booleanValue;
|
99693
|
-
} else if (field.doubleValue !== void 0) {
|
99694
|
-
return field.doubleValue;
|
99695
|
-
} else if (field.isNull !== void 0) {
|
99696
|
-
return null;
|
99697
|
-
} else if (field.longValue !== void 0) {
|
99698
|
-
return field.longValue;
|
99699
|
-
} else if (field.blobValue !== void 0) {
|
99700
|
-
return field.blobValue;
|
99701
|
-
} else if (field.arrayValue !== void 0) {
|
99702
|
-
if (field.arrayValue.stringValues !== void 0) {
|
99703
|
-
return field.arrayValue.stringValues;
|
99704
|
-
}
|
99705
|
-
if (field.arrayValue.longValues !== void 0) {
|
99706
|
-
return field.arrayValue.longValues;
|
99707
|
-
}
|
99708
|
-
if (field.arrayValue.doubleValues !== void 0) {
|
99709
|
-
return field.arrayValue.doubleValues;
|
99710
|
-
}
|
99711
|
-
if (field.arrayValue.booleanValues !== void 0) {
|
99712
|
-
return field.arrayValue.booleanValues;
|
99713
|
-
}
|
99714
|
-
if (field.arrayValue.arrayValues !== void 0) {
|
99715
|
-
return field.arrayValue.arrayValues;
|
99716
|
-
}
|
99717
|
-
throw new Error("Unknown array type");
|
99718
|
-
} else {
|
99719
|
-
throw new Error("Unknown type");
|
99720
|
-
}
|
99721
|
-
}, typingsToAwsTypeHint2 = function(typings) {
|
99722
|
-
if (typings === "date") {
|
99723
|
-
return TypeHint.DATE;
|
99724
|
-
} else if (typings === "decimal") {
|
99725
|
-
return TypeHint.DECIMAL;
|
99726
|
-
} else if (typings === "json") {
|
99727
|
-
return TypeHint.JSON;
|
99728
|
-
} else if (typings === "time") {
|
99729
|
-
return TypeHint.TIME;
|
99730
|
-
} else if (typings === "timestamp") {
|
99731
|
-
return TypeHint.TIMESTAMP;
|
99732
|
-
} else if (typings === "uuid") {
|
99733
|
-
return TypeHint.UUID;
|
99734
|
-
} else {
|
99735
|
-
return void 0;
|
99736
|
-
}
|
99737
|
-
}, toValueParam2 = function(value, typings) {
|
99738
|
-
const response = {
|
99739
|
-
value: {},
|
99740
|
-
typeHint: typingsToAwsTypeHint2(typings)
|
99741
|
-
};
|
99742
|
-
if (value === null) {
|
99743
|
-
response.value = { isNull: true };
|
99744
|
-
} else if (typeof value === "string") {
|
99745
|
-
switch (response.typeHint) {
|
99746
|
-
case TypeHint.DATE: {
|
99747
|
-
response.value = { stringValue: value.split("T")[0] };
|
99748
|
-
break;
|
99749
|
-
}
|
99750
|
-
case TypeHint.TIMESTAMP: {
|
99751
|
-
response.value = {
|
99752
|
-
stringValue: value.replace("T", " ").replace("Z", "")
|
99753
|
-
};
|
99754
|
-
break;
|
99755
|
-
}
|
99756
|
-
default: {
|
99757
|
-
response.value = { stringValue: value };
|
99758
|
-
break;
|
99759
|
-
}
|
99760
|
-
}
|
99761
|
-
} else if (typeof value === "number" && Number.isInteger(value)) {
|
99762
|
-
response.value = { longValue: value };
|
99763
|
-
} else if (typeof value === "number" && !Number.isInteger(value)) {
|
99764
|
-
response.value = { doubleValue: value };
|
99765
|
-
} else if (typeof value === "boolean") {
|
99766
|
-
response.value = { booleanValue: value };
|
99767
|
-
} else if (value instanceof Date) {
|
99768
|
-
response.value = {
|
99769
|
-
stringValue: value.toISOString().replace("T", " ").replace("Z", "")
|
99770
|
-
};
|
99771
|
-
} else {
|
99772
|
-
throw new Error(`Unknown type for ${value}`);
|
99773
|
-
}
|
99774
|
-
return response;
|
99775
|
-
};
|
99776
|
-
var getValueFromDataApi = getValueFromDataApi2, typingsToAwsTypeHint = typingsToAwsTypeHint2, toValueParam = toValueParam2;
|
99777
99695
|
assertPackages("@aws-sdk/client-rds-data");
|
99778
99696
|
const { RDSDataClient, ExecuteStatementCommand, TypeHint } = await Promise.resolve().then(() => __toESM(require_dist_cjs54()));
|
99697
|
+
const { AwsDataApiSession } = await import("drizzle-orm/aws-data-api/pg");
|
99779
99698
|
const rdsClient = new RDSDataClient();
|
99780
|
-
const
|
99781
|
-
|
99782
|
-
|
99783
|
-
|
99784
|
-
|
99785
|
-
|
99786
|
-
|
99787
|
-
|
99788
|
-
|
99789
|
-
|
99790
|
-
|
99791
|
-
|
99792
|
-
|
99793
|
-
|
99794
|
-
|
99795
|
-
return
|
99796
|
-
}
|
99797
|
-
|
99798
|
-
|
99799
|
-
|
99800
|
-
|
99801
|
-
const result = await rdsClient.send(
|
99802
|
-
new ExecuteStatementCommand({
|
99803
|
-
sql: params.sql,
|
99804
|
-
parameters: params.params.map((param, index4) => ({
|
99805
|
-
name: `${index4 + 1}`,
|
99806
|
-
...toValueParam2(param, void 0)
|
99807
|
-
})),
|
99808
|
-
secretArn: credentials2.secretArn,
|
99809
|
-
resourceArn: credentials2.resourceArn,
|
99810
|
-
database: credentials2.database
|
99811
|
-
})
|
99812
|
-
);
|
99813
|
-
if (params.mode === "array") {
|
99814
|
-
const rows = ((_a = result.records) == null ? void 0 : _a.map((row) => {
|
99815
|
-
return row.map((field) => getValueFromDataApi2(field));
|
99816
|
-
})) ?? [];
|
99817
|
-
return rows;
|
99699
|
+
const session = new AwsDataApiSession(
|
99700
|
+
rdsClient,
|
99701
|
+
new import_pg_core4.PgDialect(),
|
99702
|
+
void 0,
|
99703
|
+
{
|
99704
|
+
database: credentials2.database,
|
99705
|
+
resourceArn: credentials2.resourceArn,
|
99706
|
+
secretArn: credentials2.secretArn
|
99707
|
+
},
|
99708
|
+
void 0
|
99709
|
+
);
|
99710
|
+
return {
|
99711
|
+
async query(sql2, params) {
|
99712
|
+
const prepared = session.prepareQuery({ sql: sql2, params: params ?? [] }, void 0, void 0, false);
|
99713
|
+
const result = await prepared.execute();
|
99714
|
+
return result;
|
99715
|
+
},
|
99716
|
+
async proxy(params) {
|
99717
|
+
const prepared = session.prepareQuery({ sql: params.sql, params: params.params ?? [] }, void 0, void 0, params.mode === "array");
|
99718
|
+
const result = await prepared.execute();
|
99719
|
+
return result;
|
99818
99720
|
}
|
99819
|
-
return result.records;
|
99820
99721
|
};
|
99821
|
-
return { query, proxy };
|
99822
99722
|
}
|
99823
99723
|
assertUnreachable(credentials2.driver);
|
99824
99724
|
}
|
@@ -100100,7 +100000,7 @@ __export(studio_exports, {
|
|
100100
100000
|
prepareSQLiteSchema: () => prepareSQLiteSchema,
|
100101
100001
|
prepareServer: () => prepareServer
|
100102
100002
|
});
|
100103
|
-
var import_node_https,
|
100003
|
+
var import_node_https, import_pg_core5, import_drizzle_orm8, import_mysql_core4, import_sqlite_core3, preparePgSchema, prepareMySqlSchema, prepareSQLiteSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, drizzleForSQLite, init, proxySchema, defaultsSchema, schema4, jsonStringify, prepareServer;
|
100104
100004
|
var init_studio = __esm({
|
100105
100005
|
"src/serializer/studio.ts"() {
|
100106
100006
|
"use strict";
|
@@ -100112,7 +100012,7 @@ var init_studio = __esm({
|
|
100112
100012
|
init_dist5();
|
100113
100013
|
init_lib();
|
100114
100014
|
init_serializer();
|
100115
|
-
|
100015
|
+
import_pg_core5 = require("drizzle-orm/pg-core");
|
100116
100016
|
import_drizzle_orm8 = require("drizzle-orm");
|
100117
100017
|
init_utils4();
|
100118
100018
|
import_mysql_core4 = require("drizzle-orm/mysql-core");
|
@@ -100127,8 +100027,8 @@ var init_studio = __esm({
|
|
100127
100027
|
const i0 = require(`${it}`);
|
100128
100028
|
const i0values = Object.entries(i0);
|
100129
100029
|
i0values.forEach(([k2, t]) => {
|
100130
|
-
if ((0, import_drizzle_orm8.is)(t,
|
100131
|
-
const schema5 = (0,
|
100030
|
+
if ((0, import_drizzle_orm8.is)(t, import_pg_core5.PgTable)) {
|
100031
|
+
const schema5 = (0, import_pg_core5.getTableConfig)(t).schema || "public";
|
100132
100032
|
pgSchema2[schema5] = pgSchema2[schema5] || {};
|
100133
100033
|
pgSchema2[schema5][k2] = t;
|
100134
100034
|
}
|
@@ -100193,8 +100093,8 @@ var init_studio = __esm({
|
|
100193
100093
|
Object.entries(schema5).map(([schema6, tables]) => {
|
100194
100094
|
Object.entries(tables).map(([, table4]) => {
|
100195
100095
|
let tableConfig;
|
100196
|
-
if ((0, import_drizzle_orm8.is)(table4,
|
100197
|
-
tableConfig = (0,
|
100096
|
+
if ((0, import_drizzle_orm8.is)(table4, import_pg_core5.PgTable)) {
|
100097
|
+
tableConfig = (0, import_pg_core5.getTableConfig)(table4);
|
100198
100098
|
} else if ((0, import_drizzle_orm8.is)(table4, import_mysql_core4.MySqlTable)) {
|
100199
100099
|
tableConfig = (0, import_mysql_core4.getTableConfig)(table4);
|
100200
100100
|
} else {
|
@@ -100295,6 +100195,10 @@ var init_studio = __esm({
|
|
100295
100195
|
prepareServer = async ({ dialect: dialect7, proxy, customDefaults }, app) => {
|
100296
100196
|
app = app !== void 0 ? app : new Hono2();
|
100297
100197
|
app.use(cors());
|
100198
|
+
app.use(async (ctx, next) => {
|
100199
|
+
await next();
|
100200
|
+
ctx.header("Access-Control-Allow-Private-Network", "true");
|
100201
|
+
});
|
100298
100202
|
app.onError((err2, ctx) => {
|
100299
100203
|
console.error(err2);
|
100300
100204
|
return ctx.json({
|
@@ -103749,7 +103653,7 @@ import { sql } from "drizzle-orm"
|
|
103749
103653
|
});
|
103750
103654
|
|
103751
103655
|
// src/introspect-pg.ts
|
103752
|
-
var import_drizzle_orm9, import_relations, pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing2, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
103656
|
+
var import_drizzle_orm9, import_relations, pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing2, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
103753
103657
|
var init_introspect_pg = __esm({
|
103754
103658
|
"src/introspect-pg.ts"() {
|
103755
103659
|
"use strict";
|
@@ -103874,6 +103778,10 @@ var init_introspect_pg = __esm({
|
|
103874
103778
|
}
|
103875
103779
|
assertUnreachable(casing2);
|
103876
103780
|
};
|
103781
|
+
paramNameFor = (name, schema5) => {
|
103782
|
+
const schemaSuffix = schema5 && schema5 !== "public" ? `In${schema5.capitalise()}` : "";
|
103783
|
+
return `${name}${schemaSuffix}`;
|
103784
|
+
};
|
103877
103785
|
schemaToTypeScript3 = (schema5, casing2) => {
|
103878
103786
|
Object.values(schema5.tables).forEach((table4) => {
|
103879
103787
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
@@ -103930,7 +103838,7 @@ var init_introspect_pg = __esm({
|
|
103930
103838
|
);
|
103931
103839
|
const enumStatements = Object.values(schema5.enums).map((it) => {
|
103932
103840
|
const enumSchema3 = schemas[it.schema];
|
103933
|
-
const paramName =
|
103841
|
+
const paramName = paramNameFor(it.name, enumSchema3);
|
103934
103842
|
const func = enumSchema3 ? `${enumSchema3}.enum` : "pgEnum";
|
103935
103843
|
const values2 = Object.values(it.values).map((it2) => `'${it2}'`).join(", ");
|
103936
103844
|
return `export const ${withCasing2(paramName, casing2)} = ${func}("${it.name}", [${values2}])
|
@@ -103942,7 +103850,7 @@ var init_introspect_pg = __esm({
|
|
103942
103850
|
}).join("");
|
103943
103851
|
const tableStatements = Object.values(schema5.tables).map((table4) => {
|
103944
103852
|
const tableSchema = schemas[table4.schema];
|
103945
|
-
const paramName =
|
103853
|
+
const paramName = paramNameFor(table4.name, tableSchema);
|
103946
103854
|
const func = tableSchema ? `${tableSchema}.table` : "pgTable";
|
103947
103855
|
let statement = `export const ${withCasing2(paramName, casing2)} = ${func}("${table4.name}", {
|
103948
103856
|
`;
|
@@ -103951,6 +103859,7 @@ var init_introspect_pg = __esm({
|
|
103951
103859
|
Object.values(table4.columns),
|
103952
103860
|
Object.values(table4.foreignKeys),
|
103953
103861
|
enumTypes,
|
103862
|
+
schemas,
|
103954
103863
|
casing2,
|
103955
103864
|
schema5.internal
|
103956
103865
|
);
|
@@ -103967,7 +103876,7 @@ var init_introspect_pg = __esm({
|
|
103967
103876
|
Object.values(table4.indexes),
|
103968
103877
|
casing2
|
103969
103878
|
);
|
103970
|
-
statement += createTableFKs3(Object.values(filteredFKs), casing2);
|
103879
|
+
statement += createTableFKs3(Object.values(filteredFKs), schemas, casing2);
|
103971
103880
|
statement += createTablePKs3(
|
103972
103881
|
Object.values(table4.compositePrimaryKeys),
|
103973
103882
|
casing2
|
@@ -104217,7 +104126,7 @@ var init_introspect_pg = __esm({
|
|
104217
104126
|
}
|
104218
104127
|
return res;
|
104219
104128
|
};
|
104220
|
-
createTableColumns3 = (tableName, columns, fks, enumTypes, casing2, internals) => {
|
104129
|
+
createTableColumns3 = (tableName, columns, fks, enumTypes, schemas, casing2, internals) => {
|
104221
104130
|
let statement = "";
|
104222
104131
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
104223
104132
|
return !isSelf3(it);
|
@@ -104256,14 +104165,16 @@ var init_introspect_pg = __esm({
|
|
104256
104165
|
const params = { onDelete, onUpdate };
|
104257
104166
|
const typeSuffix = isCyclic3(it2) ? ": AnyPgColumn" : "";
|
104258
104167
|
const paramsStr = objToStatement23(params);
|
104168
|
+
const tableSchema = schemas[it2.schemaTo || ""];
|
104169
|
+
const paramName = paramNameFor(it2.tableTo, tableSchema);
|
104259
104170
|
if (paramsStr) {
|
104260
104171
|
return `.references(()${typeSuffix} => ${withCasing2(
|
104261
|
-
|
104172
|
+
paramName,
|
104262
104173
|
casing2
|
104263
104174
|
)}.${withCasing2(it2.columnsTo[0], casing2)}, ${paramsStr} )`;
|
104264
104175
|
}
|
104265
104176
|
return `.references(()${typeSuffix} => ${withCasing2(
|
104266
|
-
|
104177
|
+
paramName,
|
104267
104178
|
casing2
|
104268
104179
|
)}.${withCasing2(it2.columnsTo[0], casing2)})`;
|
104269
104180
|
}).join("");
|
@@ -104319,11 +104230,13 @@ var init_introspect_pg = __esm({
|
|
104319
104230
|
});
|
104320
104231
|
return statement;
|
104321
104232
|
};
|
104322
|
-
createTableFKs3 = (fks, casing2) => {
|
104233
|
+
createTableFKs3 = (fks, schemas, casing2) => {
|
104323
104234
|
let statement = "";
|
104324
104235
|
fks.forEach((it) => {
|
104236
|
+
const tableSchema = schemas[it.schemaTo || ""];
|
104237
|
+
const paramName = paramNameFor(it.tableTo, tableSchema);
|
104325
104238
|
const isSelf4 = it.tableTo === it.tableFrom;
|
104326
|
-
const tableTo = isSelf4 ? "table" : `${withCasing2(
|
104239
|
+
const tableTo = isSelf4 ? "table" : `${withCasing2(paramName, casing2)}`;
|
104327
104240
|
statement += ` ${withCasing2(it.name, casing2)}: foreignKey({
|
104328
104241
|
`;
|
104329
104242
|
statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing2(i, casing2)}`).join(", ")}],
|
@@ -104760,7 +104673,6 @@ var init_introspect = __esm({
|
|
104760
104673
|
const relationsTs = relationsToTypeScript(schema5, casing2);
|
104761
104674
|
const { internal, ...schemaWithoutInternals } = schema5;
|
104762
104675
|
const schemaFile = (0, import_path7.join)(out, "schema.ts");
|
104763
|
-
(0, import_fs11.mkdirSync)(out, { recursive: true });
|
104764
104676
|
(0, import_fs11.writeFileSync)(schemaFile, ts2.file);
|
104765
104677
|
const relationsFile = (0, import_path7.join)(out, "relations.ts");
|
104766
104678
|
(0, import_fs11.writeFileSync)(relationsFile, relationsTs.file);
|
@@ -104962,8 +104874,10 @@ var init_introspect = __esm({
|
|
104962
104874
|
const tableRelations = {};
|
104963
104875
|
Object.values(schema5.tables).forEach((table4) => {
|
104964
104876
|
Object.values(table4.foreignKeys).forEach((fk4) => {
|
104965
|
-
const
|
104966
|
-
const
|
104877
|
+
const tableNameFrom = paramNameFor(fk4.tableFrom, table4.schema);
|
104878
|
+
const tableNameTo = paramNameFor(fk4.tableTo, fk4.schemaTo);
|
104879
|
+
const tableFrom = withCasing3(tableNameFrom, casing2);
|
104880
|
+
const tableTo = withCasing3(tableNameTo, casing2);
|
104967
104881
|
const columnFrom = withCasing3(fk4.columnsFrom[0], casing2);
|
104968
104882
|
const columnTo = withCasing3(fk4.columnsTo[0], casing2);
|
104969
104883
|
imports.push(tableTo, tableFrom);
|
@@ -105005,17 +104919,17 @@ import { ${uniqueImports.join(
|
|
105005
104919
|
const hasOne = relations4.some((it) => it.type === "one");
|
105006
104920
|
const hasMany = relations4.some((it) => it.type === "many");
|
105007
104921
|
const preparedRelations = relations4.map(
|
105008
|
-
(relation,
|
104922
|
+
(relation, relationIndex, originArray) => {
|
105009
104923
|
let name = relation.name;
|
105010
104924
|
let relationName;
|
105011
|
-
const hasMultipleRelations =
|
105012
|
-
(it) =>
|
104925
|
+
const hasMultipleRelations = originArray.some(
|
104926
|
+
(it, originIndex) => relationIndex !== originIndex && it.tableTo === relation.tableTo
|
105013
104927
|
);
|
105014
104928
|
if (hasMultipleRelations) {
|
105015
104929
|
relationName = relation.type === "one" ? `${relation.tableFrom}_${relation.columnFrom}_${relation.tableTo}_${relation.columnTo}` : `${relation.tableTo}_${relation.columnTo}_${relation.tableFrom}_${relation.columnFrom}`;
|
105016
104930
|
}
|
105017
104931
|
const hasDuplicatedRelation = originArray.some(
|
105018
|
-
(it, originIndex) => it.name === relation.name
|
104932
|
+
(it, originIndex) => relationIndex !== originIndex && it.name === relation.name
|
105019
104933
|
);
|
105020
104934
|
if (hasDuplicatedRelation) {
|
105021
104935
|
name = `${relation.name}_${relation.type === "one" ? relation.columnFrom : relation.columnTo}`;
|
@@ -106373,6 +106287,7 @@ certs();
|
|
106373
106287
|
init_cli();
|
106374
106288
|
init_studio();
|
106375
106289
|
init_views();
|
106290
|
+
var import_fs12 = require("fs");
|
106376
106291
|
var printVersions = async () => {
|
106377
106292
|
const v6 = await versions();
|
106378
106293
|
console.log(`${source_default.gray(v6)}
|
@@ -106505,6 +106420,13 @@ var pullCommand = new import_commander.Command("introspect").option("--config <c
|
|
106505
106420
|
tablesFilter,
|
106506
106421
|
schemasFilter
|
106507
106422
|
} = await preparePullConfig(options);
|
106423
|
+
(0, import_fs12.mkdirSync)(out, { recursive: true });
|
106424
|
+
console.log(
|
106425
|
+
grey(
|
106426
|
+
`Pulling from [${schemasFilter.map((it) => `'${it}'`).join(", ")}] list of schemas`
|
106427
|
+
)
|
106428
|
+
);
|
106429
|
+
console.log();
|
106508
106430
|
try {
|
106509
106431
|
if (dialect7 === "postgresql") {
|
106510
106432
|
const { introspectPostgres: introspectPostgres2 } = await Promise.resolve().then(() => (init_introspect(), introspect_exports));
|
@@ -106633,8 +106555,8 @@ Drizzle Studio is up and running on ${source_default.blue(
|
|
106633
106555
|
});
|
106634
106556
|
} catch (e) {
|
106635
106557
|
console.error(e);
|
106558
|
+
process.exit(0);
|
106636
106559
|
}
|
106637
|
-
process.exit(0);
|
106638
106560
|
});
|
106639
106561
|
var main = async () => {
|
106640
106562
|
const version2 = await versions();
|
package/cli/validations/cli.d.ts
CHANGED
@@ -100,7 +100,7 @@ export declare const pullParams: import("zod").ZodObject<{
|
|
100
100
|
authToken: import("zod").ZodOptional<import("zod").ZodString>;
|
101
101
|
introspectCasing: import("zod").ZodDefault<import("zod").ZodUnion<[import("zod").ZodLiteral<"camel">, import("zod").ZodLiteral<"preserve">]>>;
|
102
102
|
breakpoints: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
103
|
-
}, "
|
103
|
+
}, "passthrough", import("zod").ZodTypeAny, {
|
104
104
|
dialect?: "mysql" | "postgresql" | "sqlite" | undefined;
|
105
105
|
url?: string | undefined;
|
106
106
|
host?: string | undefined;
|
package/cli/views.d.ts
CHANGED
@@ -4,6 +4,7 @@ import type { Named, NamedWithSchema } from "./commands/migrate";
|
|
4
4
|
export declare const warning: (msg: string) => void;
|
5
5
|
export declare const err: (msg: string) => void;
|
6
6
|
export declare const info: (msg: string, greyMsg?: string) => string;
|
7
|
+
export declare const grey: (msg: string) => string;
|
7
8
|
export declare const error: (error: string, greyMsg?: string) => string;
|
8
9
|
export declare const schema: (schema: CommonSchema) => string;
|
9
10
|
export interface RenamePropmtItem<T> {
|
package/package.json
CHANGED
package/payload.js
CHANGED
@@ -5550,7 +5550,7 @@ var init_cli = __esm({
|
|
5550
5550
|
authToken: stringType().optional(),
|
5551
5551
|
introspectCasing: casing,
|
5552
5552
|
breakpoints: booleanType().optional().default(true)
|
5553
|
-
});
|
5553
|
+
}).passthrough();
|
5554
5554
|
configCheck = objectType({
|
5555
5555
|
dialect: dialect3.optional(),
|
5556
5556
|
out: stringType().optional()
|
@@ -19064,6 +19064,9 @@ String.prototype.squashSpaces = function() {
|
|
19064
19064
|
String.prototype.camelCase = function() {
|
19065
19065
|
return camelCase(String(this));
|
19066
19066
|
};
|
19067
|
+
String.prototype.capitalise = function() {
|
19068
|
+
return this && this.length > 0 ? `${this[0].toUpperCase()}${this.slice(1)}` : String(this);
|
19069
|
+
};
|
19067
19070
|
String.prototype.concatIf = function(it, condition) {
|
19068
19071
|
return condition ? `${this}${it}` : String(this);
|
19069
19072
|
};
|
package/payload.mjs
CHANGED
@@ -5556,7 +5556,7 @@ var init_cli = __esm({
|
|
5556
5556
|
authToken: stringType().optional(),
|
5557
5557
|
introspectCasing: casing,
|
5558
5558
|
breakpoints: booleanType().optional().default(true)
|
5559
|
-
});
|
5559
|
+
}).passthrough();
|
5560
5560
|
configCheck = objectType({
|
5561
5561
|
dialect: dialect3.optional(),
|
5562
5562
|
out: stringType().optional()
|
@@ -19073,6 +19073,9 @@ String.prototype.squashSpaces = function() {
|
|
19073
19073
|
String.prototype.camelCase = function() {
|
19074
19074
|
return camelCase(String(this));
|
19075
19075
|
};
|
19076
|
+
String.prototype.capitalise = function() {
|
19077
|
+
return this && this.length > 0 ? `${this[0].toUpperCase()}${this.slice(1)}` : String(this);
|
19078
|
+
};
|
19076
19079
|
String.prototype.concatIf = function(it, condition) {
|
19077
19080
|
return condition ? `${this}${it}` : String(this);
|
19078
19081
|
};
|
package/utils-studio.js
CHANGED
@@ -5933,6 +5933,9 @@ String.prototype.squashSpaces = function() {
|
|
5933
5933
|
String.prototype.camelCase = function() {
|
5934
5934
|
return camelCase(String(this));
|
5935
5935
|
};
|
5936
|
+
String.prototype.capitalise = function() {
|
5937
|
+
return this && this.length > 0 ? `${this[0].toUpperCase()}${this.slice(1)}` : String(this);
|
5938
|
+
};
|
5936
5939
|
String.prototype.concatIf = function(it, condition) {
|
5937
5940
|
return condition ? `${this}${it}` : String(this);
|
5938
5941
|
};
|
package/utils-studio.mjs
CHANGED
@@ -5969,6 +5969,9 @@ String.prototype.squashSpaces = function() {
|
|
5969
5969
|
String.prototype.camelCase = function() {
|
5970
5970
|
return camelCase(String(this));
|
5971
5971
|
};
|
5972
|
+
String.prototype.capitalise = function() {
|
5973
|
+
return this && this.length > 0 ? `${this[0].toUpperCase()}${this.slice(1)}` : String(this);
|
5974
|
+
};
|
5972
5975
|
String.prototype.concatIf = function(it, condition) {
|
5973
5976
|
return condition ? `${this}${it}` : String(this);
|
5974
5977
|
};
|