@mastra/pg 1.27.2-alpha.1 → 1.28.0-alpha.3
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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +39 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -20
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +2 -4
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/dist/vector/sql-builder.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -458,14 +458,8 @@ function buildDeleteFilterQuery(filter) {
|
|
|
458
458
|
const joined = value.map((f) => {
|
|
459
459
|
const entries = Object.entries(f || {});
|
|
460
460
|
if (entries.length === 0) return "";
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
"$and",
|
|
464
|
-
"$or",
|
|
465
|
-
"$not",
|
|
466
|
-
"$nor"
|
|
467
|
-
].includes(firstKey)) return buildCondition(firstKey, firstValue, parentPath);
|
|
468
|
-
return entries.map(([k, v]) => buildCondition(k, v, parentPath)).join(` ${joinOperator} `);
|
|
461
|
+
const branchConditions = entries.map(([k, v]) => buildCondition(k, v, parentPath));
|
|
462
|
+
return branchConditions.length === 1 ? branchConditions[0] : `(${branchConditions.join(" AND ")})`;
|
|
469
463
|
}).join(` ${joinOperator} `);
|
|
470
464
|
const operatorFn = FILTER_OPERATORS[key];
|
|
471
465
|
return operatorFn(joined, 0, value).sql;
|
|
@@ -549,14 +543,8 @@ function buildFilterQuery(filter, minScore, topK) {
|
|
|
549
543
|
const joined = value.map((f) => {
|
|
550
544
|
const entries = Object.entries(f || {});
|
|
551
545
|
if (entries.length === 0) return "";
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
"$and",
|
|
555
|
-
"$or",
|
|
556
|
-
"$not",
|
|
557
|
-
"$nor"
|
|
558
|
-
].includes(firstKey)) return buildCondition(firstKey, firstValue, parentPath);
|
|
559
|
-
return entries.map(([k, v]) => buildCondition(k, v, parentPath)).join(` ${joinOperator} `);
|
|
546
|
+
const branchConditions = entries.map(([k, v]) => buildCondition(k, v, parentPath));
|
|
547
|
+
return branchConditions.length === 1 ? branchConditions[0] : `(${branchConditions.join(" AND ")})`;
|
|
560
548
|
}).join(` ${joinOperator} `);
|
|
561
549
|
const operatorFn = FILTER_OPERATORS[key];
|
|
562
550
|
return operatorFn(joined, 0, value).sql;
|
|
@@ -5024,6 +5012,7 @@ function rowToTask(row) {
|
|
|
5024
5012
|
const startedAt = row.startedAtZ || row.startedAt;
|
|
5025
5013
|
const suspendedAt = row.suspendedAtZ || row.suspendedAt;
|
|
5026
5014
|
const completedAt = row.completedAtZ || row.completedAt;
|
|
5015
|
+
const leaseExpiresAt = row.leaseExpiresAtZ || row.leaseExpiresAt;
|
|
5027
5016
|
return {
|
|
5028
5017
|
id: row.id,
|
|
5029
5018
|
status: row.status,
|
|
@@ -5043,7 +5032,9 @@ function rowToTask(row) {
|
|
|
5043
5032
|
createdAt: createdAt instanceof Date ? createdAt : new Date(createdAt),
|
|
5044
5033
|
startedAt: startedAt ? startedAt instanceof Date ? startedAt : new Date(startedAt) : void 0,
|
|
5045
5034
|
suspendedAt: suspendedAt ? suspendedAt instanceof Date ? suspendedAt : new Date(suspendedAt) : void 0,
|
|
5046
|
-
completedAt: completedAt ? completedAt instanceof Date ? completedAt : new Date(completedAt) : void 0
|
|
5035
|
+
completedAt: completedAt ? completedAt instanceof Date ? completedAt : new Date(completedAt) : void 0,
|
|
5036
|
+
ownerId: row.ownerId ?? void 0,
|
|
5037
|
+
leaseExpiresAt: leaseExpiresAt ? leaseExpiresAt instanceof Date ? leaseExpiresAt : new Date(leaseExpiresAt) : void 0
|
|
5047
5038
|
};
|
|
5048
5039
|
}
|
|
5049
5040
|
var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
@@ -5083,7 +5074,12 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
|
5083
5074
|
await this.#db.alterTable({
|
|
5084
5075
|
tableName: TABLE_BACKGROUND_TASKS,
|
|
5085
5076
|
schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
|
|
5086
|
-
ifNotExists: [
|
|
5077
|
+
ifNotExists: [
|
|
5078
|
+
"suspend_payload",
|
|
5079
|
+
"suspendedAt",
|
|
5080
|
+
"ownerId",
|
|
5081
|
+
"leaseExpiresAt"
|
|
5082
|
+
]
|
|
5087
5083
|
});
|
|
5088
5084
|
await this.createDefaultIndexes();
|
|
5089
5085
|
await this.createCustomIndexes();
|
|
@@ -5213,7 +5209,10 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
|
5213
5209
|
suspendedAt: task.suspendedAt?.toISOString() ?? null,
|
|
5214
5210
|
suspendedAtZ: task.suspendedAt?.toISOString() ?? null,
|
|
5215
5211
|
completedAt: task.completedAt?.toISOString() ?? null,
|
|
5216
|
-
completedAtZ: task.completedAt?.toISOString() ?? null
|
|
5212
|
+
completedAtZ: task.completedAt?.toISOString() ?? null,
|
|
5213
|
+
ownerId: task.ownerId ?? null,
|
|
5214
|
+
leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null,
|
|
5215
|
+
leaseExpiresAtZ: task.leaseExpiresAt?.toISOString() ?? null
|
|
5217
5216
|
}
|
|
5218
5217
|
});
|
|
5219
5218
|
}
|
|
@@ -5259,14 +5258,34 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
|
5259
5258
|
const val = update.completedAt?.toISOString() ?? null;
|
|
5260
5259
|
params.push(val, val);
|
|
5261
5260
|
}
|
|
5261
|
+
if ("ownerId" in update) {
|
|
5262
|
+
setClauses.push(`"ownerId" = $${paramIdx++}`);
|
|
5263
|
+
params.push(update.ownerId ?? null);
|
|
5264
|
+
}
|
|
5265
|
+
if ("leaseExpiresAt" in update) {
|
|
5266
|
+
setClauses.push(`"leaseExpiresAt" = $${paramIdx++}`);
|
|
5267
|
+
setClauses.push(`"leaseExpiresAtZ" = $${paramIdx++}`);
|
|
5268
|
+
const val = update.leaseExpiresAt?.toISOString() ?? null;
|
|
5269
|
+
params.push(val, val);
|
|
5270
|
+
}
|
|
5262
5271
|
if (setClauses.length === 0) return false;
|
|
5263
5272
|
const table = getTableName$4(getSchemaName$4(this.#schema));
|
|
5264
5273
|
params.push(taskId);
|
|
5265
5274
|
let where = `"id" = $${paramIdx++}`;
|
|
5266
5275
|
if (options?.expectedStatus) {
|
|
5267
|
-
where += ` AND "status" = $${paramIdx}`;
|
|
5276
|
+
where += ` AND "status" = $${paramIdx++}`;
|
|
5268
5277
|
params.push(options.expectedStatus);
|
|
5269
5278
|
}
|
|
5279
|
+
if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) where += ` AND "ownerId" IS NULL`;
|
|
5280
|
+
else {
|
|
5281
|
+
where += ` AND "ownerId" = $${paramIdx++}`;
|
|
5282
|
+
params.push(options.expectedOwnerId);
|
|
5283
|
+
}
|
|
5284
|
+
if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) where += ` AND "leaseExpiresAtZ" IS NULL`;
|
|
5285
|
+
else {
|
|
5286
|
+
where += ` AND "leaseExpiresAtZ" = $${paramIdx++}`;
|
|
5287
|
+
params.push(options.expectedLeaseExpiresAt.toISOString());
|
|
5288
|
+
}
|
|
5270
5289
|
return ((await this.#db.client.query(`UPDATE ${table} SET ${setClauses.join(", ")} WHERE ${where}`, params)).rowCount ?? 0) > 0;
|
|
5271
5290
|
}
|
|
5272
5291
|
async getTask(taskId) {
|