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