@getstrata/core 2.2.58 → 2.2.59

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @getstrata/core changelog
2
2
 
3
+ ## 2.2.59
4
+
5
+ - Reject unsupported SQLite column-level uniqueness during ADD COLUMN compilation, before any statement in a Schema.run plan executes. Use the existing nullable column plus table.unique() API; populated rows, duplicate rejection, CREATE behavior and PostgreSQL/MySQL SQL are preserved. #371
6
+ - Retain defineModel's declared record/key as repository() generic defaults, preserving explicit generics, inherited/custom-key models and legacy overrides. Runtime upsert and Model.repository behavior are unchanged. #372
7
+ - Initialize the default mailer on first successful access so custom MailDriver instances can load without configuring unused SMTP. Actual SMTP use still validates configuration; successful singleton identity, failure propagation and cancellation remain intact. #373
8
+ - Read existing migration history without DDL from getMigrationStatus(). Missing or inaccessible history now reports the native database error; explicit migration operations still initialize history. #374
9
+
3
10
  ## 2.2.58
4
11
 
5
12
  PostgreSQL runtime privilege fix: Replace broad table/sequence grants with explicit CRUD and sequence usage/read permissions. Repair legacy helper-managed grants that allowed TRUNCATE across RLS tenant boundaries. Preserve provisioning locks and transactional rollback. Resolves #364 through #370.
@@ -14,8 +14,12 @@ interface ModelConstructor<TEntity extends object, PrimaryKey extends keyof TEnt
14
14
  new (attributes: TEntity, repository: BaseRepository<TEntity, PrimaryKey>, exists?: boolean): TModel;
15
15
  }
16
16
  type RelatedRef<TRelated extends object, RelatedKey extends keyof TRelated & string> = RelatedModelClass<TRelated, RelatedKey> | string | (() => RelatedModelClass<TRelated, RelatedKey>);
17
+ /** Retain the declared table as repository() defaults without narrowing legacy explicit calls. */
18
+ type DefinedModel<TEntity extends object, PrimaryKey extends keyof TEntity & string> = {
19
+ repository<TRecord extends object = TEntity, TKey extends keyof TRecord & string = PrimaryKey & keyof TRecord & string>(this: object): BaseRepository<TRecord, TKey>;
20
+ } & typeof Model<TEntity, PrimaryKey>;
17
21
  /** Typed model base with a lazily created framework repository and active connection. */
18
- declare function defineModel<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>): typeof Model<TEntity, PrimaryKey>;
22
+ declare function defineModel<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>): DefinedModel<TEntity, PrimaryKey>;
19
23
  /** Register all relationship names before initializing any model's boot hooks. */
20
24
  declare function bootModels(models: readonly object[]): void;
21
25
  declare class Model<TEntity extends object, PrimaryKey extends keyof TEntity & string> {
@@ -706,6 +706,9 @@ function compileDropTable(driver, tableName) {
706
706
  return [`DROP TABLE IF EXISTS ${quoteIdentifier(tableName)}${cascade}`];
707
707
  }
708
708
  function compileColumn(driver, column, mode) {
709
+ if (driver === "sqlite" && mode === "alter" && column.isUnique) {
710
+ throw new UnsupportedSchemaFeatureError("column-level unique() in ADD COLUMN (add the column without unique() and use table.unique(columnName) in the same schema.table callback instead)", driver);
711
+ }
709
712
  const quoteIdentifier = dialectFor(driver).quoteIdentifier;
710
713
  const parts = [quoteIdentifier(column.name), compileColumnType(driver, column)];
711
714
  if (column.autoIncrement && driver === "mysql") {
@@ -330,6 +330,9 @@ async function recordAppliedMigration(db, name, batch) {
330
330
  }
331
331
  async function getAppliedMigrations(db) {
332
332
  await ensureMigrationsTable(db);
333
+ return readAppliedMigrations(db);
334
+ }
335
+ async function readAppliedMigrations(db) {
333
336
  return await db.unsafe(`
334
337
  SELECT name, batch
335
338
  FROM ${MIGRATIONS_TABLE}
@@ -349,7 +352,7 @@ async function loadMigrationsFromDirectory(directory) {
349
352
  }
350
353
  async function getMigrationStatus(db, migrations) {
351
354
  validateMigrations(migrations);
352
- const applied = await getAppliedMigrations(db);
355
+ const applied = await readAppliedMigrations(db);
353
356
  const appliedByName = new Map(applied.map(({ name, batch }) => [name, Number(batch)]));
354
357
  return migrations.map(({ name }) => ({
355
358
  name,
@@ -698,6 +698,9 @@ function compileDropTable(driver, tableName) {
698
698
  return [`DROP TABLE IF EXISTS ${quoteIdentifier(tableName)}${cascade}`];
699
699
  }
700
700
  function compileColumn(driver, column, mode) {
701
+ if (driver === "sqlite" && mode === "alter" && column.isUnique) {
702
+ throw new UnsupportedSchemaFeatureError("column-level unique() in ADD COLUMN (add the column without unique() and use table.unique(columnName) in the same schema.table callback instead)", driver);
703
+ }
701
704
  const quoteIdentifier = dialectFor(driver).quoteIdentifier;
702
705
  const parts = [quoteIdentifier(column.name), compileColumnType(driver, column)];
703
706
  if (column.autoIncrement && driver === "mysql") {
@@ -500,8 +500,10 @@ function createMailDriver() {
500
500
  }
501
501
  return new LogMailDriver;
502
502
  }
503
- var appMailer = new Mailer(createMailDriver());
503
+ var appMailer;
504
504
  function mailer() {
505
+ if (!appMailer)
506
+ appMailer = new Mailer(createMailDriver());
505
507
  return appMailer;
506
508
  }
507
509
 
@@ -488,8 +488,10 @@ function createMailDriver() {
488
488
  }
489
489
  return new LogMailDriver;
490
490
  }
491
- var appMailer = new Mailer(createMailDriver());
491
+ var appMailer;
492
492
  function mailer() {
493
+ if (!appMailer)
494
+ appMailer = new Mailer(createMailDriver());
493
495
  return appMailer;
494
496
  }
495
497
  export {
package/dist/index.js CHANGED
@@ -7331,6 +7331,9 @@ function compileDropTable(driver, tableName) {
7331
7331
  return [`DROP TABLE IF EXISTS ${quoteIdentifier(tableName)}${cascade}`];
7332
7332
  }
7333
7333
  function compileColumn(driver, column, mode) {
7334
+ if (driver === "sqlite" && mode === "alter" && column.isUnique) {
7335
+ throw new UnsupportedSchemaFeatureError("column-level unique() in ADD COLUMN (add the column without unique() and use table.unique(columnName) in the same schema.table callback instead)", driver);
7336
+ }
7334
7337
  const quoteIdentifier = dialectFor(driver).quoteIdentifier;
7335
7338
  const parts = [quoteIdentifier(column.name), compileColumnType(driver, column)];
7336
7339
  if (column.autoIncrement && driver === "mysql") {
@@ -8080,6 +8083,9 @@ async function recordAppliedMigration(db, name, batch) {
8080
8083
  }
8081
8084
  async function getAppliedMigrations(db) {
8082
8085
  await ensureMigrationsTable(db);
8086
+ return readAppliedMigrations(db);
8087
+ }
8088
+ async function readAppliedMigrations(db) {
8083
8089
  return await db.unsafe(`
8084
8090
  SELECT name, batch
8085
8091
  FROM ${MIGRATIONS_TABLE}
@@ -8099,7 +8105,7 @@ async function loadMigrationsFromDirectory(directory) {
8099
8105
  }
8100
8106
  async function getMigrationStatus(db, migrations) {
8101
8107
  validateMigrations(migrations);
8102
- const applied = await getAppliedMigrations(db);
8108
+ const applied = await readAppliedMigrations(db);
8103
8109
  const appliedByName = new Map(applied.map(({ name, batch }) => [name, Number(batch)]));
8104
8110
  return migrations.map(({ name }) => ({
8105
8111
  name,
@@ -11610,8 +11616,10 @@ function createMailDriver() {
11610
11616
  }
11611
11617
  return new LogMailDriver;
11612
11618
  }
11613
- var appMailer = new Mailer(createMailDriver());
11619
+ var appMailer;
11614
11620
  function mailer() {
11621
+ if (!appMailer)
11622
+ appMailer = new Mailer(createMailDriver());
11615
11623
  return appMailer;
11616
11624
  }
11617
11625
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/core",
3
- "version": "2.2.58",
3
+ "version": "2.2.59",
4
4
  "description": "Strata Bun framework public API",
5
5
  "type": "module",
6
6
  "license": "MIT",