@mastra/mysql 0.13.3-alpha.0 → 0.14.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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +70 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -52
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +8 -9
package/dist/index.js
CHANGED
|
@@ -85,13 +85,14 @@ function prepareWhereClause(filters) {
|
|
|
85
85
|
if (value === true) conditions.push(`${quoteIdentifier(fieldName, "column name")} IS NULL`);
|
|
86
86
|
else if (value === false) conditions.push(`${quoteIdentifier(fieldName, "column name")} IS NOT NULL`);
|
|
87
87
|
} else if (value === null) conditions.push(`${quoteIdentifier(key, "column name")} IS NULL`);
|
|
88
|
-
else if (Array.isArray(value))
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
else if (Array.isArray(value)) {
|
|
89
|
+
if (value.length === 0) conditions.push("FALSE");
|
|
90
|
+
else {
|
|
91
|
+
const placeholders = value.map(() => "?").join(", ");
|
|
92
|
+
conditions.push(`${quoteIdentifier(key, "column name")} IN (${placeholders})`);
|
|
93
|
+
args.push(...value.map(transformToSqlValue));
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
95
96
|
conditions.push(`${quoteIdentifier(key, "column name")} = ?`);
|
|
96
97
|
args.push(transformToSqlValue(value));
|
|
97
98
|
}
|
|
@@ -156,13 +157,14 @@ function transformFromSqlRow({ tableName, sqlRow }) {
|
|
|
156
157
|
const result = {};
|
|
157
158
|
Object.entries(sqlRow).forEach(([key, value]) => {
|
|
158
159
|
const columnSchema = schema?.[key];
|
|
159
|
-
if (columnSchema?.type === "jsonb")
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
if (columnSchema?.type === "jsonb") {
|
|
161
|
+
if (typeof value === "string") try {
|
|
162
|
+
result[key] = JSON.parse(value);
|
|
163
|
+
} catch {
|
|
164
|
+
result[key] = value;
|
|
165
|
+
}
|
|
166
|
+
else result[key] = value;
|
|
167
|
+
} else if (columnSchema?.type === "timestamp") result[key] = value === null ? null : parseDateTime(value);
|
|
166
168
|
else if (columnSchema?.type === "boolean") result[key] = value === true || value === 1 || value === "1";
|
|
167
169
|
else result[key] = value;
|
|
168
170
|
});
|
|
@@ -1564,15 +1566,19 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
|
|
|
1564
1566
|
predicates.push(`${quoteIdentifier("status", "column name")} = ?`);
|
|
1565
1567
|
params.push(options.expectedStatus);
|
|
1566
1568
|
}
|
|
1567
|
-
if (options?.expectedOwnerId !== void 0)
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1569
|
+
if (options?.expectedOwnerId !== void 0) {
|
|
1570
|
+
if (options.expectedOwnerId === null) predicates.push(`${quoteIdentifier("ownerId", "column name")} IS NULL`);
|
|
1571
|
+
else {
|
|
1572
|
+
predicates.push(`${quoteIdentifier("ownerId", "column name")} = ?`);
|
|
1573
|
+
params.push(options.expectedOwnerId);
|
|
1574
|
+
}
|
|
1571
1575
|
}
|
|
1572
|
-
if (options?.expectedLeaseExpiresAt !== void 0)
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
+
if (options?.expectedLeaseExpiresAt !== void 0) {
|
|
1577
|
+
if (options.expectedLeaseExpiresAt === null) predicates.push(`${quoteIdentifier("leaseExpiresAt", "column name")} IS NULL`);
|
|
1578
|
+
else {
|
|
1579
|
+
predicates.push(`${quoteIdentifier("leaseExpiresAt", "column name")} = ?`);
|
|
1580
|
+
params.push(transformToSqlValue(options.expectedLeaseExpiresAt));
|
|
1581
|
+
}
|
|
1576
1582
|
}
|
|
1577
1583
|
const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
|
|
1578
1584
|
const [result] = await this.pool.execute(`UPDATE ${formatTableName(TABLE_BACKGROUND_TASKS)} SET ${setClauses.join(", ")} WHERE ${quoteIdentifier("id", "column name")} = ?${predicateSql}`, params);
|
|
@@ -2339,6 +2345,10 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2339
2345
|
const { page, perPage: perPageInput } = args.pagination;
|
|
2340
2346
|
const filterParts = [];
|
|
2341
2347
|
const filterArgs = [];
|
|
2348
|
+
if (args.filters?.datasetIds !== void 0) {
|
|
2349
|
+
filterParts.push(args.filters.datasetIds.length > 0 ? `\`id\` IN (${args.filters.datasetIds.map(() => "?").join(",")})` : "1 = 0");
|
|
2350
|
+
filterArgs.push(...args.filters.datasetIds);
|
|
2351
|
+
}
|
|
2342
2352
|
if (args.filters?.organizationId !== void 0) {
|
|
2343
2353
|
filterParts.push(`${quoteIdentifier("organizationId", "column name")} = ?`);
|
|
2344
2354
|
filterArgs.push(args.filters.organizationId);
|
|
@@ -6129,10 +6139,11 @@ async function assertRunFence(q, claimsTable, fence, operation) {
|
|
|
6129
6139
|
const [rows] = await q.execute(`SELECT generation, ${quoteIdentifier("ownerId", "column name")} AS ownerId FROM ${claimsTable}
|
|
6130
6140
|
WHERE ${quoteIdentifier("runId", "column name")} = ? LOCK IN SHARE MODE`, [fence.runId]);
|
|
6131
6141
|
const row = rows[0];
|
|
6132
|
-
|
|
6142
|
+
const current = row ? {
|
|
6133
6143
|
generation: Number(row.generation),
|
|
6134
6144
|
ownerId: String(row.ownerId)
|
|
6135
|
-
} : null
|
|
6145
|
+
} : null;
|
|
6146
|
+
if (!matchesRunFence(current, fence)) throw new RunFenceConflictError(fence, operation);
|
|
6136
6147
|
}
|
|
6137
6148
|
/** Runs `fn` in a transaction on its own pooled connection. */
|
|
6138
6149
|
async function inTransaction(pool, fn) {
|
|
@@ -6466,13 +6477,14 @@ var MemoryMySQL = class MemoryMySQL extends MemoryStorage {
|
|
|
6466
6477
|
for (const indexDef of this.#indexes) await this.operations.createIndex(indexDef);
|
|
6467
6478
|
}
|
|
6468
6479
|
async prune(policies, options) {
|
|
6480
|
+
const targets = resolveRetentionTargets({
|
|
6481
|
+
policies,
|
|
6482
|
+
descriptor: MemoryMySQL.retentionTables,
|
|
6483
|
+
order: ["runFences"]
|
|
6484
|
+
});
|
|
6469
6485
|
return executeRetentionPrune({
|
|
6470
6486
|
domain: "memory",
|
|
6471
|
-
targets
|
|
6472
|
-
policies,
|
|
6473
|
-
descriptor: MemoryMySQL.retentionTables,
|
|
6474
|
-
order: ["runFences"]
|
|
6475
|
-
}),
|
|
6487
|
+
targets,
|
|
6476
6488
|
options,
|
|
6477
6489
|
cutoffFor: (target, now) => retentionCutoffMs(target.policy, now),
|
|
6478
6490
|
deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({
|
|
@@ -8400,13 +8412,14 @@ var ObservabilityMySQL = class ObservabilityMySQL extends ObservabilityStorage {
|
|
|
8400
8412
|
this.#indexes = indexes?.filter((idx) => ObservabilityMySQL.MANAGED_TABLES.includes(idx.table));
|
|
8401
8413
|
}
|
|
8402
8414
|
async prune(policies, options) {
|
|
8415
|
+
const targets = resolveRetentionTargets({
|
|
8416
|
+
policies,
|
|
8417
|
+
descriptor: ObservabilityMySQL.retentionTables,
|
|
8418
|
+
order: ["spans"]
|
|
8419
|
+
});
|
|
8403
8420
|
return executeRetentionPrune({
|
|
8404
8421
|
domain: "observability",
|
|
8405
|
-
targets
|
|
8406
|
-
policies,
|
|
8407
|
-
descriptor: ObservabilityMySQL.retentionTables,
|
|
8408
|
-
order: ["spans"]
|
|
8409
|
-
}),
|
|
8422
|
+
targets,
|
|
8410
8423
|
options,
|
|
8411
8424
|
cutoffFor: (target, now) => new Date(retentionCutoffMs(target.policy, now)),
|
|
8412
8425
|
deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({
|
|
@@ -8773,22 +8786,22 @@ var ObservabilityMySQL = class ObservabilityMySQL extends ObservabilityStorage {
|
|
|
8773
8786
|
case TraceStatus.RUNNING:
|
|
8774
8787
|
conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
|
|
8775
8788
|
break;
|
|
8776
|
-
case TraceStatus.SUCCESS:
|
|
8777
|
-
conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NOT NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
|
|
8778
|
-
break;
|
|
8789
|
+
case TraceStatus.SUCCESS: conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NOT NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
|
|
8779
8790
|
}
|
|
8780
|
-
if (filters.hasChildError !== void 0)
|
|
8791
|
+
if (filters.hasChildError !== void 0) {
|
|
8792
|
+
if (filters.hasChildError) conditions.push(`EXISTS (
|
|
8781
8793
|
SELECT 1 FROM ${tbl} c
|
|
8782
8794
|
WHERE c.${quoteIdentifier("traceId", "column name")} = ${tbl}.${quoteIdentifier("traceId", "column name")}
|
|
8783
8795
|
AND c.${quoteIdentifier("parentSpanId", "column name")} IS NOT NULL
|
|
8784
8796
|
AND c.${quoteIdentifier("error", "column name")} IS NOT NULL
|
|
8785
8797
|
)`);
|
|
8786
|
-
|
|
8798
|
+
else conditions.push(`NOT EXISTS (
|
|
8787
8799
|
SELECT 1 FROM ${tbl} c
|
|
8788
8800
|
WHERE c.${quoteIdentifier("traceId", "column name")} = ${tbl}.${quoteIdentifier("traceId", "column name")}
|
|
8789
8801
|
AND c.${quoteIdentifier("parentSpanId", "column name")} IS NOT NULL
|
|
8790
8802
|
AND c.${quoteIdentifier("error", "column name")} IS NOT NULL
|
|
8791
8803
|
)`);
|
|
8804
|
+
}
|
|
8792
8805
|
}
|
|
8793
8806
|
const whereClause = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "";
|
|
8794
8807
|
const sortField = quoteIdentifier(orderBy.field, "column name");
|
|
@@ -9524,15 +9537,19 @@ var SchedulesMySQL = class SchedulesMySQL extends SchedulesStorage {
|
|
|
9524
9537
|
conditions.push(`JSON_EXTRACT(${quoteIdentifier("target", "column name")}, '$.workflowId') = ?`);
|
|
9525
9538
|
params.push(filter.workflowId);
|
|
9526
9539
|
}
|
|
9527
|
-
if (filter?.ownerType !== void 0)
|
|
9528
|
-
|
|
9529
|
-
|
|
9530
|
-
|
|
9540
|
+
if (filter?.ownerType !== void 0) {
|
|
9541
|
+
if (filter.ownerType === null) conditions.push(`${quoteIdentifier("owner_type", "column name")} IS NULL`);
|
|
9542
|
+
else {
|
|
9543
|
+
conditions.push(`${quoteIdentifier("owner_type", "column name")} = ?`);
|
|
9544
|
+
params.push(filter.ownerType);
|
|
9545
|
+
}
|
|
9531
9546
|
}
|
|
9532
|
-
if (filter?.ownerId !== void 0)
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
|
|
9547
|
+
if (filter?.ownerId !== void 0) {
|
|
9548
|
+
if (filter.ownerId === null) conditions.push(`${quoteIdentifier("owner_id", "column name")} IS NULL`);
|
|
9549
|
+
else {
|
|
9550
|
+
conditions.push(`${quoteIdentifier("owner_id", "column name")} = ?`);
|
|
9551
|
+
params.push(filter.ownerId);
|
|
9552
|
+
}
|
|
9536
9553
|
}
|
|
9537
9554
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
9538
9555
|
const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(TABLE_SCHEDULES)} ${where} ORDER BY ${quoteIdentifier("created_at", "column name")} ASC`, params);
|
|
@@ -11467,13 +11484,14 @@ var WorkflowsMySQL = class WorkflowsMySQL extends WorkflowsStorage {
|
|
|
11467
11484
|
await this.createCustomIndexes();
|
|
11468
11485
|
}
|
|
11469
11486
|
async prune(policies, options) {
|
|
11487
|
+
const targets = resolveRetentionTargets({
|
|
11488
|
+
policies,
|
|
11489
|
+
descriptor: WorkflowsMySQL.retentionTables,
|
|
11490
|
+
order: ["runOwnership"]
|
|
11491
|
+
});
|
|
11470
11492
|
return executeRetentionPrune({
|
|
11471
11493
|
domain: "workflows",
|
|
11472
|
-
targets
|
|
11473
|
-
policies,
|
|
11474
|
-
descriptor: WorkflowsMySQL.retentionTables,
|
|
11475
|
-
order: ["runOwnership"]
|
|
11476
|
-
}),
|
|
11494
|
+
targets,
|
|
11477
11495
|
options,
|
|
11478
11496
|
cutoffFor: (target, now) => retentionCutoffMs(target.policy, now),
|
|
11479
11497
|
deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({
|