@getstrata/core 2.2.58 → 2.2.60

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,17 @@
1
1
  # @getstrata/core changelog
2
2
 
3
+ ## 2.2.60
4
+
5
+ - Preserve failed-job payloads as PostgreSQL JSONB objects by letting the native driver encode them once. Retain SQLite/MySQL JSON text mapping and readable legacy JSONB strings; timestamps, projections and replay admission/deletion ordering are unchanged.
6
+ - Add real PostgreSQL restricted-role persistence and replay regression coverage, including an independent stored-type oracle and legacy-string recovery.
7
+
8
+ ## 2.2.59
9
+
10
+ - 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
11
+ - 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
12
+ - 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
13
+ - 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
14
+
3
15
  ## 2.2.58
4
16
 
5
17
  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 {
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  // ../../src/core/queue/failedJobRepository.ts
3
3
  import { BaseRepository } from "@getstrata/core/database/baseRepository";
4
- import { sqlTimestamp } from "@getstrata/core/database/dialect";
4
+ import { currentSqlDialect, sqlTimestamp } from "@getstrata/core/database/dialect";
5
5
 
6
6
  // ../../src/core/queue/failedJobTable.ts
7
7
  import { defineTable } from "@getstrata/core/database/table";
@@ -20,7 +20,9 @@ class FailedJobRepository extends BaseRepository {
20
20
  async create(values) {
21
21
  const stored = {
22
22
  ...values,
23
- ...values.payload === undefined ? {} : { payload: JSON.stringify(values.payload) },
23
+ ...values.payload === undefined ? {} : {
24
+ payload: currentSqlDialect().driver === "pgsql" ? values.payload : JSON.stringify(values.payload)
25
+ },
24
26
  ...values.failed_at === undefined ? {} : { failed_at: sqlTimestamp(values.failed_at) }
25
27
  };
26
28
  return hydrateFailure(await super.create(stored));
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  // ../../src/core/queue/failedJobRepository.ts
3
3
  import { BaseRepository } from "@getstrata/core/database/baseRepository";
4
- import { sqlTimestamp } from "@getstrata/core/database/dialect";
4
+ import { currentSqlDialect, sqlTimestamp } from "@getstrata/core/database/dialect";
5
5
 
6
6
  // ../../src/core/queue/failedJobTable.ts
7
7
  import { defineTable } from "@getstrata/core/database/table";
@@ -20,7 +20,9 @@ class FailedJobRepository extends BaseRepository {
20
20
  async create(values) {
21
21
  const stored = {
22
22
  ...values,
23
- ...values.payload === undefined ? {} : { payload: JSON.stringify(values.payload) },
23
+ ...values.payload === undefined ? {} : {
24
+ payload: currentSqlDialect().driver === "pgsql" ? values.payload : JSON.stringify(values.payload)
25
+ },
24
26
  ...values.failed_at === undefined ? {} : { failed_at: sqlTimestamp(values.failed_at) }
25
27
  };
26
28
  return hydrateFailure(await super.create(stored));
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  // ../../src/core/queue/failedJobRepository.ts
3
3
  import { BaseRepository } from "@getstrata/core/database/baseRepository";
4
- import { sqlTimestamp } from "@getstrata/core/database/dialect";
4
+ import { currentSqlDialect, sqlTimestamp } from "@getstrata/core/database/dialect";
5
5
 
6
6
  // ../../src/core/queue/failedJobTable.ts
7
7
  import { defineTable } from "@getstrata/core/database/table";
@@ -20,7 +20,9 @@ class FailedJobRepository extends BaseRepository {
20
20
  async create(values) {
21
21
  const stored = {
22
22
  ...values,
23
- ...values.payload === undefined ? {} : { payload: JSON.stringify(values.payload) },
23
+ ...values.payload === undefined ? {} : {
24
+ payload: currentSqlDialect().driver === "pgsql" ? values.payload : JSON.stringify(values.payload)
25
+ },
24
26
  ...values.failed_at === undefined ? {} : { failed_at: sqlTimestamp(values.failed_at) }
25
27
  };
26
28
  return hydrateFailure(await super.create(stored));
@@ -80,7 +80,7 @@ function quoteIdentifierFor(dialect, column) {
80
80
  function dialectFor(driver) {
81
81
  return dialects[driver];
82
82
  }
83
- function currentSqlDialect() {
83
+ function currentSqlDialect2() {
84
84
  return dialectContext.getStore() ?? dialectOverride ?? dialectFor(resolveDatabaseDriver());
85
85
  }
86
86
  var postgresDialect, mysqlDialect, sqliteDialect, dialects, dialectContext, dialectOverride = null;
@@ -305,7 +305,7 @@ function resolveRepositoryConnection() {
305
305
  return getActiveDatabaseConnection(getBoundDatabaseConnection() ?? getDefaultDatabaseQuery());
306
306
  }
307
307
  function compileTaggedSql(strings, values) {
308
- const dialect = currentSqlDialect();
308
+ const dialect = currentSqlDialect2();
309
309
  let query = strings[0] ?? "";
310
310
  const params = [];
311
311
  for (let index = 0;index < values.length; index += 1) {
@@ -913,7 +913,7 @@ var {RedisClient: RedisClient3 } = globalThis.Bun;
913
913
 
914
914
  // ../../src/core/queue/failedJobRepository.ts
915
915
  import { BaseRepository } from "@getstrata/core/database/baseRepository";
916
- import { sqlTimestamp } from "@getstrata/core/database/dialect";
916
+ import { currentSqlDialect, sqlTimestamp } from "@getstrata/core/database/dialect";
917
917
 
918
918
  // ../../src/core/queue/failedJobTable.ts
919
919
  import { defineTable } from "@getstrata/core/database/table";
@@ -932,7 +932,9 @@ class FailedJobRepository extends BaseRepository {
932
932
  async create(values) {
933
933
  const stored = {
934
934
  ...values,
935
- ...values.payload === undefined ? {} : { payload: JSON.stringify(values.payload) },
935
+ ...values.payload === undefined ? {} : {
936
+ payload: currentSqlDialect().driver === "pgsql" ? values.payload : JSON.stringify(values.payload)
937
+ },
936
938
  ...values.failed_at === undefined ? {} : { failed_at: sqlTimestamp(values.failed_at) }
937
939
  };
938
940
  return hydrateFailure(await super.create(stored));
@@ -2417,7 +2419,7 @@ function createReadOnlyCollector(name, timeoutMs, collect) {
2417
2419
  throw new Error(`${name} collector is closed.`);
2418
2420
  if (hasActiveTransaction() || hasActiveDatabaseConnection())
2419
2421
  throw new Error(`${name} require an independent transaction.`);
2420
- const driver = currentSqlDialect().driver;
2422
+ const driver = currentSqlDialect2().driver;
2421
2423
  const pool = resolveRepositoryConnection();
2422
2424
  if (driver !== "pgsql" && driver !== "sqlite" && driver !== "mysql")
2423
2425
  throw new Error(`${name} require Postgres or an interruptible SQLite/MySQL adapter.`);
@@ -2508,7 +2510,7 @@ function createFailedJobMetricsCollector(options = {}) {
2508
2510
  throw new TypeError("Failed-job metrics sample limit must be between 1 and 1000.");
2509
2511
  const repository = new failedJobRepository_default;
2510
2512
  return createReadOnlyCollector("Failed-job metrics", options.timeoutMs ?? 1000, async (remaining) => {
2511
- const driver = currentSqlDialect().driver;
2513
+ const driver = currentSqlDialect2().driver;
2512
2514
  const postgres = driver === "pgsql";
2513
2515
  if (postgres)
2514
2516
  await repositoryConnection.unsafe('LOCK TABLE "failed_job" IN ACCESS SHARE MODE');
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
 
@@ -14747,7 +14755,9 @@ class FailedJobRepository extends BaseRepository {
14747
14755
  async create(values) {
14748
14756
  const stored = {
14749
14757
  ...values,
14750
- ...values.payload === undefined ? {} : { payload: JSON.stringify(values.payload) },
14758
+ ...values.payload === undefined ? {} : {
14759
+ payload: currentSqlDialect().driver === "pgsql" ? values.payload : JSON.stringify(values.payload)
14760
+ },
14751
14761
  ...values.failed_at === undefined ? {} : { failed_at: sqlTimestamp(values.failed_at) }
14752
14762
  };
14753
14763
  return hydrateFailure(await super.create(stored));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/core",
3
- "version": "2.2.58",
3
+ "version": "2.2.60",
4
4
  "description": "Strata Bun framework public API",
5
5
  "type": "module",
6
6
  "license": "MIT",