@warlock.js/cascade 5.7.0 → 5.8.0
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/cjs/index.cjs +59 -15
- package/cjs/index.cjs.map +1 -1
- package/esm/drivers/postgres/index.d.mts +1 -1
- package/esm/drivers/postgres/index.mjs +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts +18 -1
- package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-driver.mjs +35 -16
- package/esm/drivers/postgres/postgres-driver.mjs.map +1 -1
- package/esm/index.d.mts +2 -2
- package/esm/index.mjs +2 -2
- package/esm/migration/migration.d.mts +27 -0
- package/esm/migration/migration.d.mts.map +1 -1
- package/esm/migration/migration.mjs +24 -0
- package/esm/migration/migration.mjs.map +1 -1
- package/package.json +4 -4
package/cjs/index.cjs
CHANGED
|
@@ -17448,6 +17448,38 @@ var PostgresSyncAdapter = class {
|
|
|
17448
17448
|
* @module cascade/drivers/postgres
|
|
17449
17449
|
*/
|
|
17450
17450
|
/**
|
|
17451
|
+
* Build pg's `PoolConfig` from cascade's `PostgresPoolConfig`, coercing the
|
|
17452
|
+
* string-typed connection fields.
|
|
17453
|
+
*
|
|
17454
|
+
* `env()` (@mongez/dotenv) coerces a numeric-looking value to a number, so a
|
|
17455
|
+
* `DB_NAME` / `DB_USERNAME` / `DB_PASSWORD` like "12345" arrives here as a
|
|
17456
|
+
* number. pg's connection fields must be strings — a number reaches deep into
|
|
17457
|
+
* the driver and crashes with an inscrutable Buffer error rather than a
|
|
17458
|
+
* legible "database does not exist" (finding 51639bf8). So `host`, `database`,
|
|
17459
|
+
* `user` and `password` are coerced to strings; `port` is a real number and
|
|
17460
|
+
* `undefined` is left untouched so pg's own defaults still apply.
|
|
17461
|
+
*
|
|
17462
|
+
* Exported (not inlined into `connect()`) so the coercion is unit-testable
|
|
17463
|
+
* without a live database.
|
|
17464
|
+
*/
|
|
17465
|
+
function buildPostgresPoolConfig(config) {
|
|
17466
|
+
const asString = (value) => typeof value === "number" ? String(value) : value;
|
|
17467
|
+
return {
|
|
17468
|
+
host: asString(config.host) ?? "localhost",
|
|
17469
|
+
port: config.port ?? 5432,
|
|
17470
|
+
database: asString(config.database),
|
|
17471
|
+
user: asString(config.user),
|
|
17472
|
+
password: asString(config.password),
|
|
17473
|
+
connectionString: config.connectionString,
|
|
17474
|
+
max: config.max ?? 10,
|
|
17475
|
+
min: config.min ?? 0,
|
|
17476
|
+
idleTimeoutMillis: config.idleTimeoutMillis ?? 3e4,
|
|
17477
|
+
connectionTimeoutMillis: config.connectionTimeoutMillis ?? 2e3,
|
|
17478
|
+
application_name: config.application_name ?? "cascade",
|
|
17479
|
+
ssl: config.ssl
|
|
17480
|
+
};
|
|
17481
|
+
}
|
|
17482
|
+
/**
|
|
17451
17483
|
* Cached pg module reference.
|
|
17452
17484
|
*/
|
|
17453
17485
|
let pgModule;
|
|
@@ -17611,21 +17643,8 @@ var PostgresDriver = class {
|
|
|
17611
17643
|
if (this._isConnected) return;
|
|
17612
17644
|
const pg = await loadPg();
|
|
17613
17645
|
try {
|
|
17614
|
-
const poolConfig =
|
|
17615
|
-
|
|
17616
|
-
port: this.config.port ?? 5432,
|
|
17617
|
-
database: this.config.database,
|
|
17618
|
-
user: this.config.user,
|
|
17619
|
-
password: this.config.password,
|
|
17620
|
-
connectionString: this.config.connectionString,
|
|
17621
|
-
max: this.config.max ?? 10,
|
|
17622
|
-
min: this.config.min ?? 0,
|
|
17623
|
-
idleTimeoutMillis: this.config.idleTimeoutMillis ?? 3e4,
|
|
17624
|
-
connectionTimeoutMillis: this.config.connectionTimeoutMillis ?? 2e3,
|
|
17625
|
-
application_name: this.config.application_name ?? "cascade",
|
|
17626
|
-
ssl: this.config.ssl
|
|
17627
|
-
};
|
|
17628
|
-
_warlock_js_logger.log.info("database.postgres", "connection", `Connecting to database ${_mongez_copper.colors.bold(_mongez_copper.colors.yellowBright(this.config.database))}`);
|
|
17646
|
+
const poolConfig = buildPostgresPoolConfig(this.config);
|
|
17647
|
+
_warlock_js_logger.log.info("database.postgres", "connection", `Connecting to database ${_mongez_copper.colors.bold(_mongez_copper.colors.yellowBright(poolConfig.database ?? ""))}`);
|
|
17629
17648
|
this._pool = new pg.Pool(poolConfig);
|
|
17630
17649
|
(await this._pool.connect()).release();
|
|
17631
17650
|
_warlock_js_logger.log.success("database.postgres", "connection", `Connected to database ${_mongez_copper.colors.bold(_mongez_copper.colors.yellowBright(this.config.database))}`);
|
|
@@ -21239,6 +21258,30 @@ var Migration = class {
|
|
|
21239
21258
|
return builder;
|
|
21240
21259
|
}
|
|
21241
21260
|
/**
|
|
21261
|
+
* Add a foreign-key id column whose TYPE matches the DataSource's default
|
|
21262
|
+
* primary key (`migrationDefaults.primaryKey`), resolved EXACTLY as the auto
|
|
21263
|
+
* primary key resolves it: `migrationDefaults.primaryKey` → `"int"`.
|
|
21264
|
+
*
|
|
21265
|
+
* This is the column to use for a plain FK id — notably a polymorphic
|
|
21266
|
+
* `user_id` paired with a `user_type` — because hardcoding a single type
|
|
21267
|
+
* silently breaks every app whose models use another: an integer id written
|
|
21268
|
+
* into a `uuid` column throws at insert time, and the failure surfaces as an
|
|
21269
|
+
* opaque 500 (finding 5e47bdb3). Deriving the column type from the same
|
|
21270
|
+
* config the model's PK derives from keeps the two in lockstep for every app.
|
|
21271
|
+
*
|
|
21272
|
+
* `false` (no auto PK) is treated as `"int"` here: a referencing column still
|
|
21273
|
+
* needs a concrete type, and integer is the framework default.
|
|
21274
|
+
*
|
|
21275
|
+
* @param name - Column name
|
|
21276
|
+
* @returns Column builder for chaining modifiers (`.index()`, `.nullable()`, …)
|
|
21277
|
+
*/
|
|
21278
|
+
foreignId(name) {
|
|
21279
|
+
const pkType = this._migrationDefaults?.primaryKey ?? "int";
|
|
21280
|
+
if (pkType === "uuid") return this.uuid(name);
|
|
21281
|
+
if (pkType === "bigInt") return this.bigInteger(name);
|
|
21282
|
+
return this.integer(name);
|
|
21283
|
+
}
|
|
21284
|
+
/**
|
|
21242
21285
|
* Add createdAt and updatedAt timestamp columns.
|
|
21243
21286
|
*
|
|
21244
21287
|
* Behavior varies by database driver:
|
|
@@ -23074,6 +23117,7 @@ exports.binary = binary;
|
|
|
23074
23117
|
exports.blobCol = blobCol;
|
|
23075
23118
|
exports.bool = boolCol;
|
|
23076
23119
|
exports.boolCol = boolCol;
|
|
23120
|
+
exports.buildPostgresPoolConfig = buildPostgresPoolConfig;
|
|
23077
23121
|
exports.char = char;
|
|
23078
23122
|
exports.cleanupModelsRegistery = cleanupModelsRegistery;
|
|
23079
23123
|
exports.connectToDatabase = connectToDatabase;
|