@warlock.js/cascade 5.23.1 → 5.24.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 CHANGED
@@ -4589,6 +4589,7 @@ var DatabaseWriter = class {
4589
4589
  else {
4590
4590
  const validated = result.data;
4591
4591
  for (const column of Object.keys(dataToValidate)) if (column in validated) this.model.set(column, validated[column]);
4592
+ else if (dataToValidate[column] === null && column in validationSchema.schema) this.model.set(column, null);
4592
4593
  else this.unvalidatedColumns.add(column);
4593
4594
  }
4594
4595
  if (!options.skipEvents) await this.model.emitEvent("validated", { result });
@@ -19814,14 +19815,22 @@ var PostgresDriver = class {
19814
19815
  * @returns Transaction contract with commit/rollback methods
19815
19816
  */
19816
19817
  async beginTransaction(options) {
19818
+ const settings = Object.entries(options?.settings ?? {});
19819
+ for (const [name] of settings) if (!/^[A-Za-z_][A-Za-z0-9_.]*$/.test(name)) throw new Error(`Invalid PostgreSQL transaction setting name: "${name}"`);
19817
19820
  const client = await this.pool.connect();
19821
+ let transactionStarted = false;
19818
19822
  try {
19819
19823
  let beginSql = "BEGIN";
19820
19824
  if (options?.isolationLevel) beginSql += ` ISOLATION LEVEL ${options.isolationLevel.toUpperCase()}`;
19821
19825
  if (options?.readOnly) beginSql += " READ ONLY";
19822
19826
  if (options?.deferrable) beginSql += " DEFERRABLE";
19823
19827
  await client.query(beginSql);
19828
+ transactionStarted = true;
19829
+ for (const [name, value] of settings) await client.query("SELECT set_config($1, $2, true)", [name, String(value)]);
19824
19830
  } catch (error) {
19831
+ if (transactionStarted) try {
19832
+ await client.query("ROLLBACK");
19833
+ } catch {}
19825
19834
  client.release(error instanceof Error ? error : new Error(String(error)));
19826
19835
  throw error;
19827
19836
  }