@mastra/pg 1.9.4-alpha.1 → 1.10.0-alpha.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/CHANGELOG.md +24 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +270 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +271 -23
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts +22 -0
- package/dist/storage/domains/schedules/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 1.10.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added the `schedules` storage domain so Postgres-backed Mastra apps can use scheduled workflows. Creates `mastra_schedules` and `mastra_schedule_triggers` tables on init, with default indexes on `(status, next_fire_at)` for due-schedule polling and `(schedule_id, actual_fire_at)` for trigger-history queries. ([#15830](https://github.com/mastra-ai/mastra/pull/15830))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
|
|
12
|
+
- @mastra/core@1.32.0-alpha.1
|
|
13
|
+
|
|
14
|
+
## 1.9.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Fixed workflow snapshot sanitization in `@mastra/pg` for strings containing escaped surrogate patterns like `[^\ud800-\udfff]`. This prevents invalid JSON escape sequences that caused PostgreSQL `jsonb` writes to fail with error `22P02`. ([#15923](https://github.com/mastra-ai/mastra/pull/15923))
|
|
19
|
+
|
|
20
|
+
Fixes #15920
|
|
21
|
+
|
|
22
|
+
- Added platform channels framework with ChannelProvider interface, ChannelsStorage domain, and ChannelConnectResult discriminated union supporting OAuth, deep link, and immediate connection flows. Channels can be registered on the Mastra instance and expose connect/disconnect/list APIs for platform integrations. ([#15876](https://github.com/mastra-ai/mastra/pull/15876))
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`1723e09`](https://github.com/mastra-ai/mastra/commit/1723e099829892419ddbfe49287acfeac2522724), [`629f9e9`](https://github.com/mastra-ai/mastra/commit/629f9e9a7e56aa8f129515a3923c5813298790c7), [`25168fb`](https://github.com/mastra-ai/mastra/commit/25168fb9c1de9db7f8171df4f58ceb842c53aa29), [`ab34b5a`](https://github.com/mastra-ai/mastra/commit/ab34b5a2191b8e4353df1dbf7b9155e7d6628d79), [`5fb6c2a`](https://github.com/mastra-ai/mastra/commit/5fb6c2a95c1843cc231704b91354311fc1f34a71), [`2b0f355`](https://github.com/mastra-ai/mastra/commit/2b0f3553be3e9e5524da539a66e5cf82668440a4), [`394f0cf`](https://github.com/mastra-ai/mastra/commit/394f0cfc31e6b4d801219fdef2e9cc69e5bc8682), [`b2deb29`](https://github.com/mastra-ai/mastra/commit/b2deb29412b300c868655b5840463614fbb7962d), [`66644be`](https://github.com/mastra-ai/mastra/commit/66644beac1aa560f0e417956ff007c89341dc382), [`e109607`](https://github.com/mastra-ai/mastra/commit/e10960749251e34d46b480a20648c490fd30381b), [`310b953`](https://github.com/mastra-ai/mastra/commit/310b95345f302dcd5ba3ed862bdc96f059d44122), [`3d7f709`](https://github.com/mastra-ai/mastra/commit/3d7f709b615e588050bb6283c4ee5cfe2978cbde), [`48a42f1`](https://github.com/mastra-ai/mastra/commit/48a42f114a4006a95e0b7a1b5ad1a24815a175c2), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006), [`2c83efc`](https://github.com/mastra-ai/mastra/commit/2c83efc4482b3efe50830e3b8b4ba9a8d219edff), [`43f0e1d`](https://github.com/mastra-ai/mastra/commit/43f0e1d5d5a74ba6fc746f2ad89ebe0c64777a7d), [`da0b9e2`](https://github.com/mastra-ai/mastra/commit/da0b9e2ba7ecc560213b426d6c097fe63946086e), [`282a10c`](https://github.com/mastra-ai/mastra/commit/282a10c9446e9922afe80e10e3770481c8ac8a28), [`04151c7`](https://github.com/mastra-ai/mastra/commit/04151c7dcea934b4fe9076708a23fac161195414), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006)]:
|
|
25
|
+
- @mastra/core@1.31.0
|
|
26
|
+
|
|
3
27
|
## 1.9.4-alpha.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -11377,6 +11377,252 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
|
|
|
11377
11377
|
};
|
|
11378
11378
|
}
|
|
11379
11379
|
};
|
|
11380
|
+
function getSchemaName5(schema) {
|
|
11381
|
+
return schema ? `"${schema}"` : '"public"';
|
|
11382
|
+
}
|
|
11383
|
+
function getTableName5(table, schema) {
|
|
11384
|
+
const quoted = `"${table}"`;
|
|
11385
|
+
return schema ? `${schema}.${quoted}` : quoted;
|
|
11386
|
+
}
|
|
11387
|
+
function parseJson2(val) {
|
|
11388
|
+
if (val == null) return void 0;
|
|
11389
|
+
if (typeof val === "string") {
|
|
11390
|
+
try {
|
|
11391
|
+
return JSON.parse(val);
|
|
11392
|
+
} catch {
|
|
11393
|
+
return val;
|
|
11394
|
+
}
|
|
11395
|
+
}
|
|
11396
|
+
return val;
|
|
11397
|
+
}
|
|
11398
|
+
function toNumber(val) {
|
|
11399
|
+
if (typeof val === "bigint") return Number(val);
|
|
11400
|
+
return Number(val);
|
|
11401
|
+
}
|
|
11402
|
+
function rowToSchedule(row) {
|
|
11403
|
+
const target = parseJson2(row.target);
|
|
11404
|
+
if (!target) {
|
|
11405
|
+
throw new Error(`Schedule row ${row.id} has invalid target`);
|
|
11406
|
+
}
|
|
11407
|
+
const schedule = {
|
|
11408
|
+
id: String(row.id),
|
|
11409
|
+
target,
|
|
11410
|
+
cron: String(row.cron),
|
|
11411
|
+
status: String(row.status),
|
|
11412
|
+
nextFireAt: toNumber(row.next_fire_at),
|
|
11413
|
+
createdAt: toNumber(row.created_at),
|
|
11414
|
+
updatedAt: toNumber(row.updated_at)
|
|
11415
|
+
};
|
|
11416
|
+
if (row.timezone != null) schedule.timezone = String(row.timezone);
|
|
11417
|
+
if (row.last_fire_at != null) schedule.lastFireAt = toNumber(row.last_fire_at);
|
|
11418
|
+
if (row.last_run_id != null) schedule.lastRunId = String(row.last_run_id);
|
|
11419
|
+
const metadata = parseJson2(row.metadata);
|
|
11420
|
+
if (metadata !== void 0) schedule.metadata = metadata;
|
|
11421
|
+
return schedule;
|
|
11422
|
+
}
|
|
11423
|
+
function rowToTrigger(row) {
|
|
11424
|
+
const trigger = {
|
|
11425
|
+
scheduleId: String(row.schedule_id),
|
|
11426
|
+
runId: String(row.run_id),
|
|
11427
|
+
scheduledFireAt: toNumber(row.scheduled_fire_at),
|
|
11428
|
+
actualFireAt: toNumber(row.actual_fire_at),
|
|
11429
|
+
status: String(row.status)
|
|
11430
|
+
};
|
|
11431
|
+
if (row.error != null) trigger.error = String(row.error);
|
|
11432
|
+
return trigger;
|
|
11433
|
+
}
|
|
11434
|
+
var SchedulesPG = class extends storage.SchedulesStorage {
|
|
11435
|
+
#db;
|
|
11436
|
+
#client;
|
|
11437
|
+
#schema;
|
|
11438
|
+
/** Tables managed by this domain */
|
|
11439
|
+
static MANAGED_TABLES = [storage.TABLE_SCHEDULES, storage.TABLE_SCHEDULE_TRIGGERS];
|
|
11440
|
+
constructor(config) {
|
|
11441
|
+
super();
|
|
11442
|
+
const { client, schemaName, skipDefaultIndexes } = resolvePgConfig(config);
|
|
11443
|
+
this.#client = client;
|
|
11444
|
+
this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
|
|
11445
|
+
this.#schema = schemaName || "public";
|
|
11446
|
+
}
|
|
11447
|
+
async init() {
|
|
11448
|
+
await this.#db.createTable({
|
|
11449
|
+
tableName: storage.TABLE_SCHEDULES,
|
|
11450
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULES]
|
|
11451
|
+
});
|
|
11452
|
+
await this.#db.createTable({
|
|
11453
|
+
tableName: storage.TABLE_SCHEDULE_TRIGGERS,
|
|
11454
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULE_TRIGGERS]
|
|
11455
|
+
});
|
|
11456
|
+
}
|
|
11457
|
+
static getExportDDL(schemaName) {
|
|
11458
|
+
return [
|
|
11459
|
+
generateTableSQL({
|
|
11460
|
+
tableName: storage.TABLE_SCHEDULES,
|
|
11461
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULES],
|
|
11462
|
+
schemaName,
|
|
11463
|
+
includeAllConstraints: true
|
|
11464
|
+
}),
|
|
11465
|
+
generateTableSQL({
|
|
11466
|
+
tableName: storage.TABLE_SCHEDULE_TRIGGERS,
|
|
11467
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULE_TRIGGERS],
|
|
11468
|
+
schemaName,
|
|
11469
|
+
includeAllConstraints: true
|
|
11470
|
+
})
|
|
11471
|
+
];
|
|
11472
|
+
}
|
|
11473
|
+
async dangerouslyClearAll() {
|
|
11474
|
+
await this.#db.clearTable({ tableName: storage.TABLE_SCHEDULE_TRIGGERS });
|
|
11475
|
+
await this.#db.clearTable({ tableName: storage.TABLE_SCHEDULES });
|
|
11476
|
+
}
|
|
11477
|
+
#table(tableName) {
|
|
11478
|
+
const schema = utils.parseSqlIdentifier(this.#schema, "schema name");
|
|
11479
|
+
return getTableName5(tableName, getSchemaName5(schema));
|
|
11480
|
+
}
|
|
11481
|
+
async createSchedule(schedule) {
|
|
11482
|
+
const existing = await this.getSchedule(schedule.id);
|
|
11483
|
+
if (existing) {
|
|
11484
|
+
throw new Error(`Schedule with id "${schedule.id}" already exists`);
|
|
11485
|
+
}
|
|
11486
|
+
await this.#db.insert({
|
|
11487
|
+
tableName: storage.TABLE_SCHEDULES,
|
|
11488
|
+
record: {
|
|
11489
|
+
id: schedule.id,
|
|
11490
|
+
target: schedule.target,
|
|
11491
|
+
cron: schedule.cron,
|
|
11492
|
+
timezone: schedule.timezone ?? null,
|
|
11493
|
+
status: schedule.status,
|
|
11494
|
+
next_fire_at: schedule.nextFireAt,
|
|
11495
|
+
last_fire_at: schedule.lastFireAt ?? null,
|
|
11496
|
+
last_run_id: schedule.lastRunId ?? null,
|
|
11497
|
+
created_at: schedule.createdAt,
|
|
11498
|
+
updated_at: schedule.updatedAt,
|
|
11499
|
+
metadata: schedule.metadata ?? null
|
|
11500
|
+
}
|
|
11501
|
+
});
|
|
11502
|
+
return schedule;
|
|
11503
|
+
}
|
|
11504
|
+
async getSchedule(id) {
|
|
11505
|
+
const row = await this.#client.oneOrNone(
|
|
11506
|
+
`SELECT * FROM ${this.#table(storage.TABLE_SCHEDULES)} WHERE id = $1`,
|
|
11507
|
+
[id]
|
|
11508
|
+
);
|
|
11509
|
+
return row ? rowToSchedule(row) : null;
|
|
11510
|
+
}
|
|
11511
|
+
async listSchedules(filter) {
|
|
11512
|
+
const conditions = [];
|
|
11513
|
+
const params = [];
|
|
11514
|
+
if (filter?.status) {
|
|
11515
|
+
params.push(filter.status);
|
|
11516
|
+
conditions.push(`status = $${params.length}`);
|
|
11517
|
+
}
|
|
11518
|
+
if (filter?.workflowId) {
|
|
11519
|
+
params.push(filter.workflowId);
|
|
11520
|
+
conditions.push(`target->>'workflowId' = $${params.length}`);
|
|
11521
|
+
}
|
|
11522
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
11523
|
+
const rows = await this.#client.manyOrNone(
|
|
11524
|
+
`SELECT * FROM ${this.#table(storage.TABLE_SCHEDULES)} ${where} ORDER BY created_at ASC`,
|
|
11525
|
+
params
|
|
11526
|
+
);
|
|
11527
|
+
return rows.map(rowToSchedule);
|
|
11528
|
+
}
|
|
11529
|
+
async listDueSchedules(now, limit) {
|
|
11530
|
+
const cap = limit ?? 100;
|
|
11531
|
+
const rows = await this.#client.manyOrNone(
|
|
11532
|
+
`SELECT * FROM ${this.#table(storage.TABLE_SCHEDULES)}
|
|
11533
|
+
WHERE status = $1 AND next_fire_at <= $2
|
|
11534
|
+
ORDER BY next_fire_at ASC
|
|
11535
|
+
LIMIT $3`,
|
|
11536
|
+
["active", now, cap]
|
|
11537
|
+
);
|
|
11538
|
+
return rows.map(rowToSchedule);
|
|
11539
|
+
}
|
|
11540
|
+
async updateSchedule(id, patch) {
|
|
11541
|
+
const setClauses = [];
|
|
11542
|
+
const params = [];
|
|
11543
|
+
const push = (frag, value) => {
|
|
11544
|
+
params.push(value);
|
|
11545
|
+
setClauses.push(frag.replace("?", `$${params.length}`));
|
|
11546
|
+
};
|
|
11547
|
+
if ("cron" in patch && patch.cron !== void 0) push("cron = ?", patch.cron);
|
|
11548
|
+
if ("timezone" in patch) push("timezone = ?", patch.timezone ?? null);
|
|
11549
|
+
if ("status" in patch && patch.status !== void 0) push("status = ?", patch.status);
|
|
11550
|
+
if ("nextFireAt" in patch && patch.nextFireAt !== void 0) push("next_fire_at = ?", patch.nextFireAt);
|
|
11551
|
+
if ("target" in patch && patch.target !== void 0) {
|
|
11552
|
+
push("target = ?::jsonb", JSON.stringify(patch.target));
|
|
11553
|
+
}
|
|
11554
|
+
if ("metadata" in patch) {
|
|
11555
|
+
push("metadata = ?::jsonb", patch.metadata != null ? JSON.stringify(patch.metadata) : null);
|
|
11556
|
+
}
|
|
11557
|
+
push("updated_at = ?", Date.now());
|
|
11558
|
+
if (setClauses.length === 1) {
|
|
11559
|
+
const existing = await this.getSchedule(id);
|
|
11560
|
+
if (!existing) throw new Error(`Schedule ${id} not found`);
|
|
11561
|
+
return existing;
|
|
11562
|
+
}
|
|
11563
|
+
params.push(id);
|
|
11564
|
+
await this.#client.none(
|
|
11565
|
+
`UPDATE ${this.#table(storage.TABLE_SCHEDULES)} SET ${setClauses.join(", ")} WHERE id = $${params.length}`,
|
|
11566
|
+
params
|
|
11567
|
+
);
|
|
11568
|
+
const updated = await this.getSchedule(id);
|
|
11569
|
+
if (!updated) throw new Error(`Schedule ${id} not found`);
|
|
11570
|
+
return updated;
|
|
11571
|
+
}
|
|
11572
|
+
async updateScheduleNextFire(id, expectedNextFireAt, newNextFireAt, lastFireAt, lastRunId) {
|
|
11573
|
+
const result = await this.#client.query(
|
|
11574
|
+
`UPDATE ${this.#table(storage.TABLE_SCHEDULES)}
|
|
11575
|
+
SET next_fire_at = $1, last_fire_at = $2, last_run_id = $3, updated_at = $4
|
|
11576
|
+
WHERE id = $5 AND next_fire_at = $6 AND status = $7`,
|
|
11577
|
+
[newNextFireAt, lastFireAt, lastRunId, Date.now(), id, expectedNextFireAt, "active"]
|
|
11578
|
+
);
|
|
11579
|
+
return (result.rowCount ?? 0) > 0;
|
|
11580
|
+
}
|
|
11581
|
+
async deleteSchedule(id) {
|
|
11582
|
+
await this.#client.none(`DELETE FROM ${this.#table(storage.TABLE_SCHEDULE_TRIGGERS)} WHERE schedule_id = $1`, [id]);
|
|
11583
|
+
await this.#client.none(`DELETE FROM ${this.#table(storage.TABLE_SCHEDULES)} WHERE id = $1`, [id]);
|
|
11584
|
+
}
|
|
11585
|
+
async recordTrigger(trigger) {
|
|
11586
|
+
await this.#db.insert({
|
|
11587
|
+
tableName: storage.TABLE_SCHEDULE_TRIGGERS,
|
|
11588
|
+
record: {
|
|
11589
|
+
schedule_id: trigger.scheduleId,
|
|
11590
|
+
run_id: trigger.runId,
|
|
11591
|
+
scheduled_fire_at: trigger.scheduledFireAt,
|
|
11592
|
+
actual_fire_at: trigger.actualFireAt,
|
|
11593
|
+
status: trigger.status,
|
|
11594
|
+
error: trigger.error ?? null
|
|
11595
|
+
}
|
|
11596
|
+
});
|
|
11597
|
+
}
|
|
11598
|
+
async listTriggers(scheduleId, opts) {
|
|
11599
|
+
const conditions = [];
|
|
11600
|
+
const params = [];
|
|
11601
|
+
params.push(scheduleId);
|
|
11602
|
+
conditions.push(`schedule_id = $${params.length}`);
|
|
11603
|
+
if (opts?.fromActualFireAt != null) {
|
|
11604
|
+
params.push(opts.fromActualFireAt);
|
|
11605
|
+
conditions.push(`actual_fire_at >= $${params.length}`);
|
|
11606
|
+
}
|
|
11607
|
+
if (opts?.toActualFireAt != null) {
|
|
11608
|
+
params.push(opts.toActualFireAt);
|
|
11609
|
+
conditions.push(`actual_fire_at < $${params.length}`);
|
|
11610
|
+
}
|
|
11611
|
+
let limitClause = "";
|
|
11612
|
+
if (opts?.limit != null) {
|
|
11613
|
+
params.push(Math.floor(opts.limit));
|
|
11614
|
+
limitClause = `LIMIT $${params.length}`;
|
|
11615
|
+
}
|
|
11616
|
+
const rows = await this.#client.manyOrNone(
|
|
11617
|
+
`SELECT * FROM ${this.#table(storage.TABLE_SCHEDULE_TRIGGERS)}
|
|
11618
|
+
WHERE ${conditions.join(" AND ")}
|
|
11619
|
+
ORDER BY actual_fire_at DESC
|
|
11620
|
+
${limitClause}`,
|
|
11621
|
+
params
|
|
11622
|
+
);
|
|
11623
|
+
return rows.map(rowToTrigger);
|
|
11624
|
+
}
|
|
11625
|
+
};
|
|
11380
11626
|
var SNAPSHOT_FIELDS4 = [
|
|
11381
11627
|
"name",
|
|
11382
11628
|
"description",
|
|
@@ -12044,10 +12290,10 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends storage.ScorerDefin
|
|
|
12044
12290
|
};
|
|
12045
12291
|
}
|
|
12046
12292
|
};
|
|
12047
|
-
function
|
|
12293
|
+
function getSchemaName6(schema) {
|
|
12048
12294
|
return schema ? `"${schema}"` : '"public"';
|
|
12049
12295
|
}
|
|
12050
|
-
function
|
|
12296
|
+
function getTableName6({ indexName, schemaName }) {
|
|
12051
12297
|
const quotedIndexName = `"${indexName}"`;
|
|
12052
12298
|
return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
|
|
12053
12299
|
}
|
|
@@ -12161,7 +12407,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12161
12407
|
async getScoreById({ id }) {
|
|
12162
12408
|
try {
|
|
12163
12409
|
const result = await this.#db.client.oneOrNone(
|
|
12164
|
-
`SELECT * FROM ${
|
|
12410
|
+
`SELECT * FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE id = $1`,
|
|
12165
12411
|
[id]
|
|
12166
12412
|
);
|
|
12167
12413
|
return result ? transformScoreRow(result) : null;
|
|
@@ -12201,7 +12447,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12201
12447
|
}
|
|
12202
12448
|
const whereClause = conditions.join(" AND ");
|
|
12203
12449
|
const total = await this.#db.client.oneOrNone(
|
|
12204
|
-
`SELECT COUNT(*) FROM ${
|
|
12450
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE ${whereClause}`,
|
|
12205
12451
|
queryParams
|
|
12206
12452
|
);
|
|
12207
12453
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12221,7 +12467,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12221
12467
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12222
12468
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12223
12469
|
const result = await this.#db.client.manyOrNone(
|
|
12224
|
-
`SELECT * FROM ${
|
|
12470
|
+
`SELECT * FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
|
|
12225
12471
|
[...queryParams, limitValue, start]
|
|
12226
12472
|
);
|
|
12227
12473
|
return {
|
|
@@ -12316,7 +12562,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12316
12562
|
}) {
|
|
12317
12563
|
try {
|
|
12318
12564
|
const total = await this.#db.client.oneOrNone(
|
|
12319
|
-
`SELECT COUNT(*) FROM ${
|
|
12565
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "runId" = $1`,
|
|
12320
12566
|
[runId]
|
|
12321
12567
|
);
|
|
12322
12568
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12336,7 +12582,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12336
12582
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12337
12583
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12338
12584
|
const result = await this.#db.client.manyOrNone(
|
|
12339
|
-
`SELECT * FROM ${
|
|
12585
|
+
`SELECT * FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
|
|
12340
12586
|
[runId, limitValue, start]
|
|
12341
12587
|
);
|
|
12342
12588
|
return {
|
|
@@ -12366,7 +12612,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12366
12612
|
}) {
|
|
12367
12613
|
try {
|
|
12368
12614
|
const total = await this.#db.client.oneOrNone(
|
|
12369
|
-
`SELECT COUNT(*) FROM ${
|
|
12615
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
|
|
12370
12616
|
[entityId, entityType]
|
|
12371
12617
|
);
|
|
12372
12618
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12386,7 +12632,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12386
12632
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12387
12633
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12388
12634
|
const result = await this.#db.client.manyOrNone(
|
|
12389
|
-
`SELECT * FROM ${
|
|
12635
|
+
`SELECT * FROM ${getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
|
|
12390
12636
|
[entityId, entityType, limitValue, start]
|
|
12391
12637
|
);
|
|
12392
12638
|
return {
|
|
@@ -12415,7 +12661,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
|
|
|
12415
12661
|
pagination
|
|
12416
12662
|
}) {
|
|
12417
12663
|
try {
|
|
12418
|
-
const tableName =
|
|
12664
|
+
const tableName = getTableName6({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) });
|
|
12419
12665
|
const countSQLResult = await this.#db.client.oneOrNone(
|
|
12420
12666
|
`SELECT COUNT(*) as count FROM ${tableName} WHERE "traceId" = $1 AND "spanId" = $2`,
|
|
12421
12667
|
[traceId, spanId]
|
|
@@ -13118,10 +13364,10 @@ var SkillsPG = class _SkillsPG extends storage.SkillsStorage {
|
|
|
13118
13364
|
};
|
|
13119
13365
|
}
|
|
13120
13366
|
};
|
|
13121
|
-
function
|
|
13367
|
+
function getSchemaName7(schema) {
|
|
13122
13368
|
return schema ? `"${schema}"` : '"public"';
|
|
13123
13369
|
}
|
|
13124
|
-
function
|
|
13370
|
+
function getTableName7({ indexName, schemaName }) {
|
|
13125
13371
|
const quotedIndexName = `"${indexName}"`;
|
|
13126
13372
|
return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
|
|
13127
13373
|
}
|
|
@@ -13233,7 +13479,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13233
13479
|
}) {
|
|
13234
13480
|
try {
|
|
13235
13481
|
return await this.#db.client.tx(async (t) => {
|
|
13236
|
-
const tableName =
|
|
13482
|
+
const tableName = getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) });
|
|
13237
13483
|
const existingSnapshotResult = await t.oneOrNone(
|
|
13238
13484
|
`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
|
|
13239
13485
|
[workflowName, runId]
|
|
@@ -13294,7 +13540,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13294
13540
|
}) {
|
|
13295
13541
|
try {
|
|
13296
13542
|
return await this.#db.client.tx(async (t) => {
|
|
13297
|
-
const tableName =
|
|
13543
|
+
const tableName = getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) });
|
|
13298
13544
|
const existingSnapshotResult = await t.oneOrNone(
|
|
13299
13545
|
`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
|
|
13300
13546
|
[workflowName, runId]
|
|
@@ -13344,7 +13590,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13344
13590
|
const updatedAtValue = updatedAt ? updatedAt : now;
|
|
13345
13591
|
const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(snapshot));
|
|
13346
13592
|
await this.#db.client.none(
|
|
13347
|
-
`INSERT INTO ${
|
|
13593
|
+
`INSERT INTO ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
|
|
13348
13594
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
13349
13595
|
ON CONFLICT (workflow_name, run_id) DO UPDATE
|
|
13350
13596
|
SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
|
|
@@ -13402,7 +13648,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13402
13648
|
}
|
|
13403
13649
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
13404
13650
|
const query = `
|
|
13405
|
-
SELECT * FROM ${
|
|
13651
|
+
SELECT * FROM ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })}
|
|
13406
13652
|
${whereClause}
|
|
13407
13653
|
ORDER BY "createdAt" DESC LIMIT 1
|
|
13408
13654
|
`;
|
|
@@ -13430,7 +13676,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13430
13676
|
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
13431
13677
|
try {
|
|
13432
13678
|
await this.#db.client.none(
|
|
13433
|
-
`DELETE FROM ${
|
|
13679
|
+
`DELETE FROM ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
|
|
13434
13680
|
[runId, workflowName]
|
|
13435
13681
|
);
|
|
13436
13682
|
} catch (error$1) {
|
|
@@ -13498,7 +13744,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13498
13744
|
const usePagination = typeof perPage === "number" && typeof page === "number";
|
|
13499
13745
|
if (usePagination) {
|
|
13500
13746
|
const countResult = await this.#db.client.one(
|
|
13501
|
-
`SELECT COUNT(*) as count FROM ${
|
|
13747
|
+
`SELECT COUNT(*) as count FROM ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} ${whereClause}`,
|
|
13502
13748
|
values
|
|
13503
13749
|
);
|
|
13504
13750
|
total = Number(countResult.count);
|
|
@@ -13506,7 +13752,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
13506
13752
|
const normalizedPerPage = usePagination ? storage.normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
|
|
13507
13753
|
const offset = usePagination ? page * normalizedPerPage : void 0;
|
|
13508
13754
|
const query = `
|
|
13509
|
-
SELECT * FROM ${
|
|
13755
|
+
SELECT * FROM ${getTableName7({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })}
|
|
13510
13756
|
${whereClause}
|
|
13511
13757
|
ORDER BY "createdAt" DESC
|
|
13512
13758
|
${usePagination ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ""}
|
|
@@ -14231,7 +14477,8 @@ var ALL_DOMAINS = [
|
|
|
14231
14477
|
DatasetsPG,
|
|
14232
14478
|
ExperimentsPG,
|
|
14233
14479
|
BackgroundTasksPG,
|
|
14234
|
-
ChannelsPG
|
|
14480
|
+
ChannelsPG,
|
|
14481
|
+
SchedulesPG
|
|
14235
14482
|
];
|
|
14236
14483
|
function exportSchemas(schemaName) {
|
|
14237
14484
|
const statements = [];
|
|
@@ -14287,7 +14534,8 @@ var PostgresStore = class extends storage.MastraCompositeStore {
|
|
|
14287
14534
|
datasets: new DatasetsPG(domainConfig),
|
|
14288
14535
|
experiments: new ExperimentsPG(domainConfig),
|
|
14289
14536
|
backgroundTasks: new BackgroundTasksPG(domainConfig),
|
|
14290
|
-
channels: new ChannelsPG(domainConfig)
|
|
14537
|
+
channels: new ChannelsPG(domainConfig),
|
|
14538
|
+
schedules: new SchedulesPG(domainConfig)
|
|
14291
14539
|
};
|
|
14292
14540
|
} catch (e) {
|
|
14293
14541
|
throw new error.MastraError(
|
|
@@ -14491,6 +14739,7 @@ exports.PgVector = PgVector;
|
|
|
14491
14739
|
exports.PoolAdapter = PoolAdapter;
|
|
14492
14740
|
exports.PostgresStore = PostgresStore;
|
|
14493
14741
|
exports.PromptBlocksPG = PromptBlocksPG;
|
|
14742
|
+
exports.SchedulesPG = SchedulesPG;
|
|
14494
14743
|
exports.ScorerDefinitionsPG = ScorerDefinitionsPG;
|
|
14495
14744
|
exports.ScoresPG = ScoresPG;
|
|
14496
14745
|
exports.SkillsPG = SkillsPG;
|