@mastra/pg 1.9.4 → 1.10.0-alpha.1

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
@@ -1,5 +1,5 @@
1
1
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
2
- import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_SCHEMAS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, DATASETS_SCHEMA, TABLE_CONFIGS, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, ensureDate, safelyParseJSON, ExperimentsStorage, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SkillsStorage, TABLE_SKILLS, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, TraceStatus, getDefaultValue, transformScoreRow as transformScoreRow$1, getSqlType } from '@mastra/core/storage';
2
+ import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_SCHEMAS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, DATASETS_SCHEMA, TABLE_CONFIGS, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, ensureDate, safelyParseJSON, ExperimentsStorage, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SkillsStorage, TABLE_SKILLS, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, TraceStatus, getDefaultValue, transformScoreRow as transformScoreRow$1, getSqlType } from '@mastra/core/storage';
3
3
  import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
4
4
  import { MastraVector, validateTopK, validateUpsertInput } from '@mastra/core/vector';
5
5
  import { Mutex } from 'async-mutex';
@@ -11352,6 +11352,284 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
11352
11352
  };
11353
11353
  }
11354
11354
  };
11355
+ function getSchemaName5(schema) {
11356
+ return schema ? `"${schema}"` : '"public"';
11357
+ }
11358
+ function getTableName5(table, schema) {
11359
+ const quoted = `"${table}"`;
11360
+ return schema ? `${schema}.${quoted}` : quoted;
11361
+ }
11362
+ function parseJson2(val) {
11363
+ if (val == null) return void 0;
11364
+ if (typeof val === "string") {
11365
+ try {
11366
+ return JSON.parse(val);
11367
+ } catch {
11368
+ return val;
11369
+ }
11370
+ }
11371
+ return val;
11372
+ }
11373
+ function toNumber(val) {
11374
+ if (typeof val === "bigint") return Number(val);
11375
+ return Number(val);
11376
+ }
11377
+ function rowToSchedule(row) {
11378
+ const target = parseJson2(row.target);
11379
+ if (!target) {
11380
+ throw new Error(`Schedule row ${row.id} has invalid target`);
11381
+ }
11382
+ const schedule = {
11383
+ id: String(row.id),
11384
+ target,
11385
+ cron: String(row.cron),
11386
+ status: String(row.status),
11387
+ nextFireAt: toNumber(row.next_fire_at),
11388
+ createdAt: toNumber(row.created_at),
11389
+ updatedAt: toNumber(row.updated_at)
11390
+ };
11391
+ if (row.timezone != null) schedule.timezone = String(row.timezone);
11392
+ if (row.last_fire_at != null) schedule.lastFireAt = toNumber(row.last_fire_at);
11393
+ if (row.last_run_id != null) schedule.lastRunId = String(row.last_run_id);
11394
+ const metadata = parseJson2(row.metadata);
11395
+ if (metadata !== void 0) schedule.metadata = metadata;
11396
+ if (row.owner_type != null) schedule.ownerType = String(row.owner_type);
11397
+ if (row.owner_id != null) schedule.ownerId = String(row.owner_id);
11398
+ return schedule;
11399
+ }
11400
+ function rowToTrigger(row) {
11401
+ const trigger = {
11402
+ id: row.id != null ? String(row.id) : void 0,
11403
+ scheduleId: String(row.schedule_id),
11404
+ runId: row.run_id != null ? String(row.run_id) : null,
11405
+ scheduledFireAt: toNumber(row.scheduled_fire_at),
11406
+ actualFireAt: toNumber(row.actual_fire_at),
11407
+ outcome: String(row.outcome),
11408
+ triggerKind: row.trigger_kind != null ? String(row.trigger_kind) : "schedule-fire"
11409
+ };
11410
+ if (row.error != null) trigger.error = String(row.error);
11411
+ if (row.parent_trigger_id != null) trigger.parentTriggerId = String(row.parent_trigger_id);
11412
+ const metadata = parseJson2(row.metadata);
11413
+ if (metadata !== void 0) trigger.metadata = metadata;
11414
+ return trigger;
11415
+ }
11416
+ var SchedulesPG = class extends SchedulesStorage {
11417
+ #db;
11418
+ #client;
11419
+ #schema;
11420
+ /** Tables managed by this domain */
11421
+ static MANAGED_TABLES = [TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS];
11422
+ constructor(config) {
11423
+ super();
11424
+ const { client, schemaName, skipDefaultIndexes } = resolvePgConfig(config);
11425
+ this.#client = client;
11426
+ this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
11427
+ this.#schema = schemaName || "public";
11428
+ }
11429
+ async init() {
11430
+ await this.#db.createTable({
11431
+ tableName: TABLE_SCHEDULES,
11432
+ schema: TABLE_SCHEMAS[TABLE_SCHEDULES]
11433
+ });
11434
+ await this.#db.createTable({
11435
+ tableName: TABLE_SCHEDULE_TRIGGERS,
11436
+ schema: TABLE_SCHEMAS[TABLE_SCHEDULE_TRIGGERS]
11437
+ });
11438
+ }
11439
+ static getExportDDL(schemaName) {
11440
+ return [
11441
+ generateTableSQL({
11442
+ tableName: TABLE_SCHEDULES,
11443
+ schema: TABLE_SCHEMAS[TABLE_SCHEDULES],
11444
+ schemaName,
11445
+ includeAllConstraints: true
11446
+ }),
11447
+ generateTableSQL({
11448
+ tableName: TABLE_SCHEDULE_TRIGGERS,
11449
+ schema: TABLE_SCHEMAS[TABLE_SCHEDULE_TRIGGERS],
11450
+ schemaName,
11451
+ includeAllConstraints: true
11452
+ })
11453
+ ];
11454
+ }
11455
+ async dangerouslyClearAll() {
11456
+ await this.#db.clearTable({ tableName: TABLE_SCHEDULE_TRIGGERS });
11457
+ await this.#db.clearTable({ tableName: TABLE_SCHEDULES });
11458
+ }
11459
+ #table(tableName) {
11460
+ const schema = parseSqlIdentifier(this.#schema, "schema name");
11461
+ return getTableName5(tableName, getSchemaName5(schema));
11462
+ }
11463
+ async createSchedule(schedule) {
11464
+ const existing = await this.getSchedule(schedule.id);
11465
+ if (existing) {
11466
+ throw new Error(`Schedule with id "${schedule.id}" already exists`);
11467
+ }
11468
+ await this.#db.insert({
11469
+ tableName: TABLE_SCHEDULES,
11470
+ record: {
11471
+ id: schedule.id,
11472
+ target: schedule.target,
11473
+ cron: schedule.cron,
11474
+ timezone: schedule.timezone ?? null,
11475
+ status: schedule.status,
11476
+ next_fire_at: schedule.nextFireAt,
11477
+ last_fire_at: schedule.lastFireAt ?? null,
11478
+ last_run_id: schedule.lastRunId ?? null,
11479
+ created_at: schedule.createdAt,
11480
+ updated_at: schedule.updatedAt,
11481
+ metadata: schedule.metadata ?? null,
11482
+ owner_type: schedule.ownerType ?? null,
11483
+ owner_id: schedule.ownerId ?? null
11484
+ }
11485
+ });
11486
+ return schedule;
11487
+ }
11488
+ async getSchedule(id) {
11489
+ const row = await this.#client.oneOrNone(
11490
+ `SELECT * FROM ${this.#table(TABLE_SCHEDULES)} WHERE id = $1`,
11491
+ [id]
11492
+ );
11493
+ return row ? rowToSchedule(row) : null;
11494
+ }
11495
+ async listSchedules(filter) {
11496
+ const conditions = [];
11497
+ const params = [];
11498
+ if (filter?.status) {
11499
+ params.push(filter.status);
11500
+ conditions.push(`status = $${params.length}`);
11501
+ }
11502
+ if (filter?.workflowId) {
11503
+ params.push(filter.workflowId);
11504
+ conditions.push(`target->>'workflowId' = $${params.length}`);
11505
+ }
11506
+ if (filter?.ownerType !== void 0) {
11507
+ if (filter.ownerType === null) {
11508
+ conditions.push("owner_type IS NULL");
11509
+ } else {
11510
+ params.push(filter.ownerType);
11511
+ conditions.push(`owner_type = $${params.length}`);
11512
+ }
11513
+ }
11514
+ if (filter?.ownerId !== void 0) {
11515
+ if (filter.ownerId === null) {
11516
+ conditions.push("owner_id IS NULL");
11517
+ } else {
11518
+ params.push(filter.ownerId);
11519
+ conditions.push(`owner_id = $${params.length}`);
11520
+ }
11521
+ }
11522
+ const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
11523
+ const rows = await this.#client.manyOrNone(
11524
+ `SELECT * FROM ${this.#table(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(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
+ if ("ownerType" in patch) push("owner_type = ?", patch.ownerType ?? null);
11558
+ if ("ownerId" in patch) push("owner_id = ?", patch.ownerId ?? null);
11559
+ push("updated_at = ?", Date.now());
11560
+ if (setClauses.length === 1) {
11561
+ const existing = await this.getSchedule(id);
11562
+ if (!existing) throw new Error(`Schedule ${id} not found`);
11563
+ return existing;
11564
+ }
11565
+ params.push(id);
11566
+ await this.#client.none(
11567
+ `UPDATE ${this.#table(TABLE_SCHEDULES)} SET ${setClauses.join(", ")} WHERE id = $${params.length}`,
11568
+ params
11569
+ );
11570
+ const updated = await this.getSchedule(id);
11571
+ if (!updated) throw new Error(`Schedule ${id} not found`);
11572
+ return updated;
11573
+ }
11574
+ async updateScheduleNextFire(id, expectedNextFireAt, newNextFireAt, lastFireAt, lastRunId) {
11575
+ const result = await this.#client.query(
11576
+ `UPDATE ${this.#table(TABLE_SCHEDULES)}
11577
+ SET next_fire_at = $1, last_fire_at = $2, last_run_id = $3, updated_at = $4
11578
+ WHERE id = $5 AND next_fire_at = $6 AND status = $7`,
11579
+ [newNextFireAt, lastFireAt, lastRunId, Date.now(), id, expectedNextFireAt, "active"]
11580
+ );
11581
+ return (result.rowCount ?? 0) > 0;
11582
+ }
11583
+ async deleteSchedule(id) {
11584
+ await this.#client.none(`DELETE FROM ${this.#table(TABLE_SCHEDULE_TRIGGERS)} WHERE schedule_id = $1`, [id]);
11585
+ await this.#client.none(`DELETE FROM ${this.#table(TABLE_SCHEDULES)} WHERE id = $1`, [id]);
11586
+ }
11587
+ async recordTrigger(trigger) {
11588
+ const id = trigger.id ?? crypto.randomUUID();
11589
+ await this.#db.insert({
11590
+ tableName: TABLE_SCHEDULE_TRIGGERS,
11591
+ record: {
11592
+ id,
11593
+ schedule_id: trigger.scheduleId,
11594
+ run_id: trigger.runId,
11595
+ scheduled_fire_at: trigger.scheduledFireAt,
11596
+ actual_fire_at: trigger.actualFireAt,
11597
+ outcome: trigger.outcome,
11598
+ error: trigger.error ?? null,
11599
+ trigger_kind: trigger.triggerKind ?? "schedule-fire",
11600
+ parent_trigger_id: trigger.parentTriggerId ?? null,
11601
+ metadata: trigger.metadata ?? null
11602
+ }
11603
+ });
11604
+ }
11605
+ async listTriggers(scheduleId, opts) {
11606
+ const conditions = [];
11607
+ const params = [];
11608
+ params.push(scheduleId);
11609
+ conditions.push(`schedule_id = $${params.length}`);
11610
+ if (opts?.fromActualFireAt != null) {
11611
+ params.push(opts.fromActualFireAt);
11612
+ conditions.push(`actual_fire_at >= $${params.length}`);
11613
+ }
11614
+ if (opts?.toActualFireAt != null) {
11615
+ params.push(opts.toActualFireAt);
11616
+ conditions.push(`actual_fire_at < $${params.length}`);
11617
+ }
11618
+ let limitClause = "";
11619
+ if (opts?.limit != null) {
11620
+ params.push(Math.floor(opts.limit));
11621
+ limitClause = `LIMIT $${params.length}`;
11622
+ }
11623
+ const rows = await this.#client.manyOrNone(
11624
+ `SELECT * FROM ${this.#table(TABLE_SCHEDULE_TRIGGERS)}
11625
+ WHERE ${conditions.join(" AND ")}
11626
+ ORDER BY actual_fire_at DESC
11627
+ ${limitClause}`,
11628
+ params
11629
+ );
11630
+ return rows.map(rowToTrigger);
11631
+ }
11632
+ };
11355
11633
  var SNAPSHOT_FIELDS4 = [
11356
11634
  "name",
11357
11635
  "description",
@@ -12019,10 +12297,10 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends ScorerDefinitionsSt
12019
12297
  };
12020
12298
  }
12021
12299
  };
12022
- function getSchemaName5(schema) {
12300
+ function getSchemaName6(schema) {
12023
12301
  return schema ? `"${schema}"` : '"public"';
12024
12302
  }
12025
- function getTableName5({ indexName, schemaName }) {
12303
+ function getTableName6({ indexName, schemaName }) {
12026
12304
  const quotedIndexName = `"${indexName}"`;
12027
12305
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
12028
12306
  }
@@ -12136,7 +12414,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
12136
12414
  async getScoreById({ id }) {
12137
12415
  try {
12138
12416
  const result = await this.#db.client.oneOrNone(
12139
- `SELECT * FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE id = $1`,
12417
+ `SELECT * FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE id = $1`,
12140
12418
  [id]
12141
12419
  );
12142
12420
  return result ? transformScoreRow(result) : null;
@@ -12176,7 +12454,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
12176
12454
  }
12177
12455
  const whereClause = conditions.join(" AND ");
12178
12456
  const total = await this.#db.client.oneOrNone(
12179
- `SELECT COUNT(*) FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE ${whereClause}`,
12457
+ `SELECT COUNT(*) FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE ${whereClause}`,
12180
12458
  queryParams
12181
12459
  );
12182
12460
  const { page, perPage: perPageInput } = pagination;
@@ -12196,7 +12474,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
12196
12474
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
12197
12475
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
12198
12476
  const result = await this.#db.client.manyOrNone(
12199
- `SELECT * FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
12477
+ `SELECT * FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
12200
12478
  [...queryParams, limitValue, start]
12201
12479
  );
12202
12480
  return {
@@ -12291,7 +12569,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
12291
12569
  }) {
12292
12570
  try {
12293
12571
  const total = await this.#db.client.oneOrNone(
12294
- `SELECT COUNT(*) FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "runId" = $1`,
12572
+ `SELECT COUNT(*) FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "runId" = $1`,
12295
12573
  [runId]
12296
12574
  );
12297
12575
  const { page, perPage: perPageInput } = pagination;
@@ -12311,7 +12589,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
12311
12589
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
12312
12590
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
12313
12591
  const result = await this.#db.client.manyOrNone(
12314
- `SELECT * FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
12592
+ `SELECT * FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
12315
12593
  [runId, limitValue, start]
12316
12594
  );
12317
12595
  return {
@@ -12341,7 +12619,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
12341
12619
  }) {
12342
12620
  try {
12343
12621
  const total = await this.#db.client.oneOrNone(
12344
- `SELECT COUNT(*) FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
12622
+ `SELECT COUNT(*) FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
12345
12623
  [entityId, entityType]
12346
12624
  );
12347
12625
  const { page, perPage: perPageInput } = pagination;
@@ -12361,7 +12639,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
12361
12639
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
12362
12640
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
12363
12641
  const result = await this.#db.client.manyOrNone(
12364
- `SELECT * FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
12642
+ `SELECT * FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
12365
12643
  [entityId, entityType, limitValue, start]
12366
12644
  );
12367
12645
  return {
@@ -12390,7 +12668,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
12390
12668
  pagination
12391
12669
  }) {
12392
12670
  try {
12393
- const tableName = getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) });
12671
+ const tableName = getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) });
12394
12672
  const countSQLResult = await this.#db.client.oneOrNone(
12395
12673
  `SELECT COUNT(*) as count FROM ${tableName} WHERE "traceId" = $1 AND "spanId" = $2`,
12396
12674
  [traceId, spanId]
@@ -13093,10 +13371,10 @@ var SkillsPG = class _SkillsPG extends SkillsStorage {
13093
13371
  };
13094
13372
  }
13095
13373
  };
13096
- function getSchemaName6(schema) {
13374
+ function getSchemaName7(schema) {
13097
13375
  return schema ? `"${schema}"` : '"public"';
13098
13376
  }
13099
- function getTableName6({ indexName, schemaName }) {
13377
+ function getTableName7({ indexName, schemaName }) {
13100
13378
  const quotedIndexName = `"${indexName}"`;
13101
13379
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
13102
13380
  }
@@ -13208,7 +13486,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
13208
13486
  }) {
13209
13487
  try {
13210
13488
  return await this.#db.client.tx(async (t) => {
13211
- const tableName = getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) });
13489
+ const tableName = getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) });
13212
13490
  const existingSnapshotResult = await t.oneOrNone(
13213
13491
  `SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
13214
13492
  [workflowName, runId]
@@ -13269,7 +13547,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
13269
13547
  }) {
13270
13548
  try {
13271
13549
  return await this.#db.client.tx(async (t) => {
13272
- const tableName = getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) });
13550
+ const tableName = getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) });
13273
13551
  const existingSnapshotResult = await t.oneOrNone(
13274
13552
  `SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
13275
13553
  [workflowName, runId]
@@ -13319,7 +13597,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
13319
13597
  const updatedAtValue = updatedAt ? updatedAt : now;
13320
13598
  const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(snapshot));
13321
13599
  await this.#db.client.none(
13322
- `INSERT INTO ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
13600
+ `INSERT INTO ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
13323
13601
  VALUES ($1, $2, $3, $4, $5, $6)
13324
13602
  ON CONFLICT (workflow_name, run_id) DO UPDATE
13325
13603
  SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
@@ -13377,7 +13655,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
13377
13655
  }
13378
13656
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
13379
13657
  const query = `
13380
- SELECT * FROM ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })}
13658
+ SELECT * FROM ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })}
13381
13659
  ${whereClause}
13382
13660
  ORDER BY "createdAt" DESC LIMIT 1
13383
13661
  `;
@@ -13405,7 +13683,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
13405
13683
  async deleteWorkflowRunById({ runId, workflowName }) {
13406
13684
  try {
13407
13685
  await this.#db.client.none(
13408
- `DELETE FROM ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
13686
+ `DELETE FROM ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
13409
13687
  [runId, workflowName]
13410
13688
  );
13411
13689
  } catch (error) {
@@ -13473,7 +13751,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
13473
13751
  const usePagination = typeof perPage === "number" && typeof page === "number";
13474
13752
  if (usePagination) {
13475
13753
  const countResult = await this.#db.client.one(
13476
- `SELECT COUNT(*) as count FROM ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} ${whereClause}`,
13754
+ `SELECT COUNT(*) as count FROM ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} ${whereClause}`,
13477
13755
  values
13478
13756
  );
13479
13757
  total = Number(countResult.count);
@@ -13481,7 +13759,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
13481
13759
  const normalizedPerPage = usePagination ? normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
13482
13760
  const offset = usePagination ? page * normalizedPerPage : void 0;
13483
13761
  const query = `
13484
- SELECT * FROM ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })}
13762
+ SELECT * FROM ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })}
13485
13763
  ${whereClause}
13486
13764
  ORDER BY "createdAt" DESC
13487
13765
  ${usePagination ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ""}
@@ -14206,7 +14484,8 @@ var ALL_DOMAINS = [
14206
14484
  DatasetsPG,
14207
14485
  ExperimentsPG,
14208
14486
  BackgroundTasksPG,
14209
- ChannelsPG
14487
+ ChannelsPG,
14488
+ SchedulesPG
14210
14489
  ];
14211
14490
  function exportSchemas(schemaName) {
14212
14491
  const statements = [];
@@ -14262,7 +14541,8 @@ var PostgresStore = class extends MastraCompositeStore {
14262
14541
  datasets: new DatasetsPG(domainConfig),
14263
14542
  experiments: new ExperimentsPG(domainConfig),
14264
14543
  backgroundTasks: new BackgroundTasksPG(domainConfig),
14265
- channels: new ChannelsPG(domainConfig)
14544
+ channels: new ChannelsPG(domainConfig),
14545
+ schedules: new SchedulesPG(domainConfig)
14266
14546
  };
14267
14547
  } catch (e) {
14268
14548
  throw new MastraError(
@@ -14451,6 +14731,6 @@ Example Complex Query:
14451
14731
  ]
14452
14732
  }`;
14453
14733
 
14454
- export { AgentsPG, BackgroundTasksPG, BlobsPG, ChannelsPG, DatasetsPG, ExperimentsPG, MCPClientsPG, MCPServersPG, MemoryPG, ObservabilityPG, PGVECTOR_PROMPT, PgVector, PoolAdapter, PostgresStore, PromptBlocksPG, ScorerDefinitionsPG, ScoresPG, SkillsPG, WorkflowsPG, WorkspacesPG, exportSchemas };
14734
+ export { AgentsPG, BackgroundTasksPG, BlobsPG, ChannelsPG, DatasetsPG, ExperimentsPG, MCPClientsPG, MCPServersPG, MemoryPG, ObservabilityPG, PGVECTOR_PROMPT, PgVector, PoolAdapter, PostgresStore, PromptBlocksPG, SchedulesPG, ScorerDefinitionsPG, ScoresPG, SkillsPG, WorkflowsPG, WorkspacesPG, exportSchemas };
14455
14735
  //# sourceMappingURL=index.js.map
14456
14736
  //# sourceMappingURL=index.js.map