@mastra/pg 1.6.0 → 1.6.1-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/dist/index.js CHANGED
@@ -4341,7 +4341,7 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
4341
4341
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
4342
4342
  const limitValue = perPageInput === false ? total : perPage;
4343
4343
  const rows = await this.#db.client.manyOrNone(
4344
- `SELECT * FROM ${tableName} ORDER BY "createdAt" DESC LIMIT $1 OFFSET $2`,
4344
+ `SELECT * FROM ${tableName} ORDER BY "createdAt" DESC, "id" ASC LIMIT $1 OFFSET $2`,
4345
4345
  [limitValue, offset]
4346
4346
  );
4347
4347
  return {
@@ -4745,7 +4745,7 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
4745
4745
  try {
4746
4746
  const tableName = getTableName2({ indexName: TABLE_DATASET_ITEMS, schemaName: getSchemaName2(this.#schema) });
4747
4747
  const rows = await this.#db.client.manyOrNone(
4748
- `SELECT * FROM ${tableName} WHERE "datasetId" = $1 AND "datasetVersion" <= $2 AND ("validTo" IS NULL OR "validTo" > $3) AND "isDeleted" = false ORDER BY "createdAt" DESC`,
4748
+ `SELECT * FROM ${tableName} WHERE "datasetId" = $1 AND "datasetVersion" <= $2 AND ("validTo" IS NULL OR "validTo" > $3) AND "isDeleted" = false ORDER BY "createdAt" DESC, "id" ASC`,
4749
4749
  [datasetId, version, version]
4750
4750
  );
4751
4751
  return (rows || []).map((row) => this.transformItemRow(row));
@@ -4816,7 +4816,7 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
4816
4816
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
4817
4817
  const limitValue = perPageInput === false ? total : perPage;
4818
4818
  const rows = await this.#db.client.manyOrNone(
4819
- `SELECT * FROM ${tableName} ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`,
4819
+ `SELECT * FROM ${tableName} ${whereClause} ORDER BY "createdAt" DESC, "id" ASC LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`,
4820
4820
  [...queryParams, limitValue, offset]
4821
4821
  );
4822
4822
  return {
@@ -9420,7 +9420,7 @@ var ObservabilityPG = class _ObservabilityPG extends ObservabilityStorage {
9420
9420
  }
9421
9421
  }
9422
9422
  };
9423
- var SNAPSHOT_FIELDS3 = ["name", "description", "content", "rules"];
9423
+ var SNAPSHOT_FIELDS3 = ["name", "description", "content", "rules", "requestContextSchema"];
9424
9424
  var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
9425
9425
  #db;
9426
9426
  #schema;
@@ -9493,6 +9493,11 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
9493
9493
  tableName: TABLE_PROMPT_BLOCK_VERSIONS,
9494
9494
  schema: TABLE_SCHEMAS[TABLE_PROMPT_BLOCK_VERSIONS]
9495
9495
  });
9496
+ await this.#db.alterTable({
9497
+ tableName: TABLE_PROMPT_BLOCK_VERSIONS,
9498
+ schema: TABLE_SCHEMAS[TABLE_PROMPT_BLOCK_VERSIONS],
9499
+ ifNotExists: ["requestContextSchema"]
9500
+ });
9496
9501
  await this.createDefaultIndexes();
9497
9502
  await this.createCustomIndexes();
9498
9503
  }
@@ -9684,7 +9689,7 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
9684
9689
  }
9685
9690
  }
9686
9691
  async list(args) {
9687
- const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status = "published" } = args || {};
9692
+ const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status } = args || {};
9688
9693
  const { field, direction } = this.parseOrderBy(orderBy);
9689
9694
  if (page < 0) {
9690
9695
  throw new MastraError(
@@ -9704,8 +9709,10 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
9704
9709
  const conditions = [];
9705
9710
  const queryParams = [];
9706
9711
  let paramIdx = 1;
9707
- conditions.push(`status = $${paramIdx++}`);
9708
- queryParams.push(status);
9712
+ if (status) {
9713
+ conditions.push(`status = $${paramIdx++}`);
9714
+ queryParams.push(status);
9715
+ }
9709
9716
  if (authorId !== void 0) {
9710
9717
  conditions.push(`"authorId" = $${paramIdx++}`);
9711
9718
  queryParams.push(authorId);
@@ -9714,7 +9721,7 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
9714
9721
  conditions.push(`metadata @> $${paramIdx++}::jsonb`);
9715
9722
  queryParams.push(JSON.stringify(metadata));
9716
9723
  }
9717
- const whereClause = `WHERE ${conditions.join(" AND ")}`;
9724
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
9718
9725
  const countResult = await this.#db.client.one(
9719
9726
  `SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`,
9720
9727
  queryParams
@@ -9768,10 +9775,10 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
9768
9775
  await this.#db.client.none(
9769
9776
  `INSERT INTO ${tableName} (
9770
9777
  id, "blockId", "versionNumber",
9771
- name, description, content, rules,
9778
+ name, description, content, rules, "requestContextSchema",
9772
9779
  "changedFields", "changeMessage",
9773
9780
  "createdAt", "createdAtZ"
9774
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)`,
9781
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)`,
9775
9782
  [
9776
9783
  input.id,
9777
9784
  input.blockId,
@@ -9780,6 +9787,7 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
9780
9787
  input.description ?? null,
9781
9788
  input.content,
9782
9789
  input.rules ? JSON.stringify(input.rules) : null,
9790
+ input.requestContextSchema ? JSON.stringify(input.requestContextSchema) : null,
9783
9791
  input.changedFields ? JSON.stringify(input.changedFields) : null,
9784
9792
  input.changeMessage ?? null,
9785
9793
  nowIso,
@@ -10051,6 +10059,7 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
10051
10059
  description: row.description,
10052
10060
  content: row.content,
10053
10061
  rules: this.parseJson(row.rules, "rules"),
10062
+ requestContextSchema: this.parseJson(row.requestContextSchema, "requestContextSchema"),
10054
10063
  changedFields: this.parseJson(row.changedFields, "changedFields"),
10055
10064
  changeMessage: row.changeMessage,
10056
10065
  createdAt: new Date(row.createdAtZ || row.createdAt)