@absolutejs/auth 0.57.6 → 0.57.7

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/dist/server.js CHANGED
@@ -36948,30 +36948,40 @@ var JOURNAL_DDL = `CREATE TABLE IF NOT EXISTS "auth_migrations" (
36948
36948
  var isJournalRow = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "id") === "string";
36949
36949
  var isBlockName = (value) => Object.hasOwn(blockMigrations, value);
36950
36950
  var allBlockNames = () => Object.keys(blockMigrations).filter(isBlockName);
36951
- var applyOne = async (pool, id, sql2, log) => {
36952
- await pool.query(sql2);
36953
- await pool.query(`INSERT INTO "auth_migrations" ("id", "applied_at_ms") VALUES ($1, $2)`, [id, Date.now()]);
36951
+ var applyOne = async (client, id, sql2, log) => {
36952
+ await client.query(sql2);
36953
+ await client.query(`INSERT INTO "auth_migrations" ("id", "applied_at_ms") VALUES ($1, $2)`, [id, Date.now()]);
36954
36954
  log(`apply ${id}`);
36955
36955
  };
36956
- var runOne = async (pool, id, sql2, applied, result, log) => {
36956
+ var runOne = async (client, id, sql2, applied, result, log) => {
36957
36957
  if (applied.has(id)) {
36958
36958
  result.skipped.push(id);
36959
36959
  log(`skip ${id}`);
36960
36960
  return;
36961
36961
  }
36962
- await applyOne(pool, id, sql2, log);
36962
+ await applyOne(client, id, sql2, log);
36963
36963
  result.applied.push(id);
36964
36964
  };
36965
36965
  var runMigrations = async ({
36966
36966
  blocks,
36967
+ client,
36967
36968
  databaseUrl,
36968
36969
  log = console.log
36969
36970
  }) => {
36970
- const pool = new Ln({ connectionString: databaseUrl });
36971
+ let ownedPool;
36972
+ let migrationClient;
36973
+ if (client !== undefined) {
36974
+ migrationClient = client;
36975
+ } else {
36976
+ if (databaseUrl === undefined)
36977
+ throw new Error("runMigrations requires databaseUrl or client");
36978
+ ownedPool = new Ln({ connectionString: databaseUrl });
36979
+ migrationClient = ownedPool;
36980
+ }
36971
36981
  const result = { applied: [], skipped: [] };
36972
36982
  try {
36973
- await pool.query(JOURNAL_DDL);
36974
- const journal = await pool.query(`SELECT "id" FROM "auth_migrations"`);
36983
+ await migrationClient.query(JOURNAL_DDL);
36984
+ const journal = await migrationClient.query(`SELECT "id" FROM "auth_migrations"`);
36975
36985
  const applied = new Set(journal.rows.filter(isJournalRow).map((row) => row.id));
36976
36986
  const selected = blocks ?? allBlockNames();
36977
36987
  const flat = selected.flatMap((block) => blockMigrations[block].migrations.map((migration) => ({
@@ -36980,10 +36990,10 @@ var runMigrations = async ({
36980
36990
  })));
36981
36991
  await flat.reduce(async (prior, item) => {
36982
36992
  await prior;
36983
- return runOne(pool, item.id, item.sql, applied, result, log);
36993
+ return runOne(migrationClient, item.id, item.sql, applied, result, log);
36984
36994
  }, Promise.resolve());
36985
36995
  } finally {
36986
- await pool.end();
36996
+ await ownedPool?.end();
36987
36997
  }
36988
36998
  return result;
36989
36999
  };
@@ -38042,5 +38052,5 @@ export {
38042
38052
  auth2 as auth
38043
38053
  };
38044
38054
 
38045
- //# debugId=56D8E62C3DDCAF8364756E2164756E21
38055
+ //# debugId=365532246DA9FA0C64756E2164756E21
38046
38056
  //# sourceMappingURL=server.js.map