@mastra/libsql 1.23.4-alpha.0 → 1.24.0-alpha.2

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
@@ -423,9 +423,14 @@ function handleLogicalOperator(key, value, parentPath) {
423
423
  }
424
424
  const values = [];
425
425
  const joinOperator = key === "$or" || key === "$nor" ? "OR" : "AND";
426
- const joined = (Array.isArray(value) ? value.map((f) => {
427
- return (!!f ? Object.entries(f) : []).map(([k, v]) => buildCondition$1(k, v, key));
428
- }) : [buildCondition$1(key, value, parentPath)]).flat().map((c) => {
426
+ const joined = (Array.isArray(value) ? value.flatMap((f) => {
427
+ const branch = (!!f ? Object.entries(f) : []).map(([k, v]) => buildCondition$1(k, v, key));
428
+ if (branch.length <= 1) return branch;
429
+ return [{
430
+ sql: `(${branch.map((c) => c.sql).join(" AND ")})`,
431
+ values: branch.flatMap((c) => c.values)
432
+ }];
433
+ }) : [buildCondition$1(key, value, parentPath)]).map((c) => {
429
434
  values.push(...c.values);
430
435
  return c.sql;
431
436
  }).join(` ${joinOperator} `);
@@ -2953,7 +2958,9 @@ function rowToTask(row) {
2953
2958
  createdAt: new Date(String(row.createdAt)),
2954
2959
  startedAt: row.startedAt ? new Date(String(row.startedAt)) : void 0,
2955
2960
  suspendedAt: row.suspendedAt ? new Date(String(row.suspendedAt)) : void 0,
2956
- completedAt: row.completedAt ? new Date(String(row.completedAt)) : void 0
2961
+ completedAt: row.completedAt ? new Date(String(row.completedAt)) : void 0,
2962
+ ownerId: row.ownerId != null ? String(row.ownerId) : void 0,
2963
+ leaseExpiresAt: row.leaseExpiresAt ? new Date(String(row.leaseExpiresAt)) : void 0
2957
2964
  };
2958
2965
  }
2959
2966
  var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends BackgroundTasksStorage {
@@ -2987,7 +2994,12 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends BackgroundTasksS
2987
2994
  await this.#db.alterTable({
2988
2995
  tableName: TABLE_BACKGROUND_TASKS,
2989
2996
  schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
2990
- ifNotExists: ["suspend_payload", "suspendedAt"]
2997
+ ifNotExists: [
2998
+ "suspend_payload",
2999
+ "suspendedAt",
3000
+ "ownerId",
3001
+ "leaseExpiresAt"
3002
+ ]
2991
3003
  });
2992
3004
  }
2993
3005
  async dangerouslyClearAll() {
@@ -3030,7 +3042,9 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends BackgroundTasksS
3030
3042
  createdAt: task.createdAt.toISOString(),
3031
3043
  startedAt: task.startedAt?.toISOString() ?? null,
3032
3044
  suspendedAt: task.suspendedAt?.toISOString() ?? null,
3033
- completedAt: task.completedAt?.toISOString() ?? null
3045
+ completedAt: task.completedAt?.toISOString() ?? null,
3046
+ ownerId: task.ownerId ?? null,
3047
+ leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null
3034
3048
  }
3035
3049
  });
3036
3050
  }
@@ -3069,6 +3083,14 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends BackgroundTasksS
3069
3083
  setClauses.push("completedAt = ?");
3070
3084
  params.push(update.completedAt?.toISOString() ?? null);
3071
3085
  }
3086
+ if ("ownerId" in update) {
3087
+ setClauses.push("ownerId = ?");
3088
+ params.push(update.ownerId ?? null);
3089
+ }
3090
+ if ("leaseExpiresAt" in update) {
3091
+ setClauses.push("leaseExpiresAt = ?");
3092
+ params.push(update.leaseExpiresAt?.toISOString() ?? null);
3093
+ }
3072
3094
  if (setClauses.length === 0) return false;
3073
3095
  params.push(taskId);
3074
3096
  let where = "id = ?";
@@ -3076,6 +3098,16 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends BackgroundTasksS
3076
3098
  where += " AND status = ?";
3077
3099
  params.push(options.expectedStatus);
3078
3100
  }
3101
+ if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) where += " AND ownerId IS NULL";
3102
+ else {
3103
+ where += " AND ownerId = ?";
3104
+ params.push(options.expectedOwnerId);
3105
+ }
3106
+ if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) where += " AND leaseExpiresAt IS NULL";
3107
+ else {
3108
+ where += " AND leaseExpiresAt = ?";
3109
+ params.push(options.expectedLeaseExpiresAt.toISOString());
3110
+ }
3079
3111
  return (await this.#client.execute({
3080
3112
  sql: `UPDATE ${TABLE_BACKGROUND_TASKS} SET ${setClauses.join(", ")} WHERE ${where}`,
3081
3113
  args: params