@mastra/dsql 1.5.3 → 1.5.4

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/index.js CHANGED
@@ -934,7 +934,8 @@ var DsqlDB = class extends MastraBase {
934
934
  const uniqueStr = unique ? "UNIQUE " : "";
935
935
  const methodStr = method !== "btree" ? `USING ${method} ` : "";
936
936
  const columnsStr = columns.map((col) => {
937
- const quotedCol = `"${parseSqlIdentifier(col.replace(/\s+(DESC|ASC)$/i, "").trim(), "column name")}"`;
937
+ const colName = col.replace(/\s+(DESC|ASC)$/i, "").trim();
938
+ const quotedCol = `"${parseSqlIdentifier(colName, "column name")}"`;
938
939
  return opclass ? `${quotedCol} ${opclass}` : quotedCol;
939
940
  }).join(", ");
940
941
  const whereStr = where ? ` WHERE ${where}` : "";
@@ -1850,10 +1851,11 @@ function isRetriableRunFenceWrite(error) {
1850
1851
  */
1851
1852
  async function assertRunFence(t, claimsTable, fence, operation) {
1852
1853
  const row = await t.oneOrNone(`SELECT generation, "ownerId" FROM ${claimsTable} WHERE "runId" = $1 FOR UPDATE`, [fence.runId]);
1853
- if (!matchesRunFence(row && {
1854
+ const current = row && {
1854
1855
  generation: Number(row.generation),
1855
1856
  ownerId: row.ownerId
1856
- }, fence)) throw new RunFenceConflictError(fence, operation);
1857
+ };
1858
+ if (!matchesRunFence(current, fence)) throw new RunFenceConflictError(fence, operation);
1857
1859
  }
1858
1860
  /**
1859
1861
  * Runs `write` directly when it carries no fence, or in a transaction behind
@@ -1984,13 +1986,14 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
1984
1986
  }
1985
1987
  }
1986
1988
  async prune(policies, options) {
1989
+ const targets = resolveRetentionTargets({
1990
+ policies,
1991
+ descriptor: MemoryDSQL.retentionTables,
1992
+ order: ["runFences"]
1993
+ });
1987
1994
  return executeRetentionPrune({
1988
1995
  domain: "memory",
1989
- targets: resolveRetentionTargets({
1990
- policies,
1991
- descriptor: MemoryDSQL.retentionTables,
1992
- order: ["runFences"]
1993
- }),
1996
+ targets,
1994
1997
  options,
1995
1998
  cutoffFor: (target, now) => retentionCutoffMs(target.policy, now),
1996
1999
  deleteBatch: (target, cutoff, limit) => this.#db.pruneBatch({
@@ -2970,13 +2973,14 @@ var ObservabilityDSQL = class ObservabilityDSQL extends ObservabilityStorage {
2970
2973
  this.#indexes = indexes?.filter((idx) => ObservabilityDSQL.MANAGED_TABLES.includes(idx.table));
2971
2974
  }
2972
2975
  async prune(policies, options) {
2976
+ const targets = resolveRetentionTargets({
2977
+ policies,
2978
+ descriptor: ObservabilityDSQL.retentionTables,
2979
+ order: ["spans"]
2980
+ });
2973
2981
  return executeRetentionPrune({
2974
2982
  domain: "observability",
2975
- targets: resolveRetentionTargets({
2976
- policies,
2977
- descriptor: ObservabilityDSQL.retentionTables,
2978
- order: ["spans"]
2979
- }),
2983
+ targets,
2980
2984
  options,
2981
2985
  cutoffFor: (target, now) => new Date(retentionCutoffMs(target.policy, now)),
2982
2986
  deleteBatch: (target, cutoff, limit) => this.#db.pruneBatch({
@@ -3351,18 +3355,18 @@ var ObservabilityDSQL = class ObservabilityDSQL extends ObservabilityStorage {
3351
3355
  case TraceStatus.RUNNING:
3352
3356
  conditions.push(`r."endedAtZ" IS NULL AND r."error" IS NULL`);
3353
3357
  break;
3354
- case TraceStatus.SUCCESS:
3355
- conditions.push(`r."endedAtZ" IS NOT NULL AND r."error" IS NULL`);
3356
- break;
3358
+ case TraceStatus.SUCCESS: conditions.push(`r."endedAtZ" IS NOT NULL AND r."error" IS NULL`);
3357
3359
  }
3358
- if (filters.hasChildError !== void 0) if (filters.hasChildError) conditions.push(`EXISTS (
3360
+ if (filters.hasChildError !== void 0) {
3361
+ if (filters.hasChildError) conditions.push(`EXISTS (
3359
3362
  SELECT 1 FROM ${tableName} c
3360
3363
  WHERE c."traceId" = r."traceId" AND c."error" IS NOT NULL
3361
3364
  )`);
3362
- else conditions.push(`NOT EXISTS (
3365
+ else conditions.push(`NOT EXISTS (
3363
3366
  SELECT 1 FROM ${tableName} c
3364
3367
  WHERE c."traceId" = r."traceId" AND c."error" IS NOT NULL
3365
3368
  )`);
3369
+ }
3366
3370
  }
3367
3371
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
3368
3372
  const orderClause = `ORDER BY r."${`${orderBy?.field ?? "startedAt"}Z`}" ${orderBy?.direction ?? "DESC"}`;
@@ -3981,13 +3985,14 @@ var WorkflowsDSQL = class WorkflowsDSQL extends WorkflowsStorage {
3981
3985
  }
3982
3986
  }
3983
3987
  async prune(policies, options) {
3988
+ const targets = resolveRetentionTargets({
3989
+ policies,
3990
+ descriptor: WorkflowsDSQL.retentionTables,
3991
+ order: ["runOwnership"]
3992
+ });
3984
3993
  return executeRetentionPrune({
3985
3994
  domain: "workflows",
3986
- targets: resolveRetentionTargets({
3987
- policies,
3988
- descriptor: WorkflowsDSQL.retentionTables,
3989
- order: ["runOwnership"]
3990
- }),
3995
+ targets,
3991
3996
  options,
3992
3997
  cutoffFor: (target, now) => retentionCutoffMs(target.policy, now),
3993
3998
  deleteBatch: (target, cutoff, limit) => this.#db.pruneBatch({
@@ -4353,11 +4358,13 @@ var WorkflowsDSQL = class WorkflowsDSQL extends WorkflowsStorage {
4353
4358
  values.push(status);
4354
4359
  paramIndex++;
4355
4360
  }
4356
- if (resourceId) if (await this.#db.hasColumn(TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
4357
- conditions.push(`"resourceId" = $${paramIndex}`);
4358
- values.push(resourceId);
4359
- paramIndex++;
4360
- } else console.warn(`[${TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
4361
+ if (resourceId) {
4362
+ if (await this.#db.hasColumn(TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
4363
+ conditions.push(`"resourceId" = $${paramIndex}`);
4364
+ values.push(resourceId);
4365
+ paramIndex++;
4366
+ } else console.warn(`[${TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
4367
+ }
4361
4368
  if (fromDate) {
4362
4369
  conditions.push(`"createdAt" >= $${paramIndex}`);
4363
4370
  values.push(fromDate instanceof Date ? fromDate.toISOString() : fromDate);
@@ -4465,7 +4472,7 @@ var DSQLStore = class extends MastraStorage {
4465
4472
  createPool(config) {
4466
4473
  if (!isHostConfig(config)) throw new Error("DSQLStore: Invalid configuration for creating pool.");
4467
4474
  const region = getEffectiveRegion(config);
4468
- return new Pool({
4475
+ const poolConfig = {
4469
4476
  host: config.host,
4470
4477
  user: config.user ?? "admin",
4471
4478
  database: config.database ?? "postgres",
@@ -4478,7 +4485,8 @@ var DSQLStore = class extends MastraStorage {
4478
4485
  maxLifetimeSeconds: config.maxLifetimeSeconds ?? DSQL_POOL_DEFAULTS.maxLifetimeSeconds,
4479
4486
  connectionTimeoutMillis: config.connectionTimeoutMillis ?? DSQL_POOL_DEFAULTS.connectionTimeoutMillis,
4480
4487
  allowExitOnIdle: config.allowExitOnIdle ?? DSQL_POOL_DEFAULTS.allowExitOnIdle
4481
- });
4488
+ };
4489
+ return new Pool(poolConfig);
4482
4490
  }
4483
4491
  async init() {
4484
4492
  if (this.isInitialized) return;