@mastra/pg 1.6.0 → 1.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed non-deterministic query ordering by adding secondary sort on id for dataset and dataset item queries. ([#13399](https://github.com/mastra-ai/mastra/pull/13399))
8
+
9
+ - Prompt blocks can now define their own variables schema (`requestContextSchema`), allowing you to create reusable prompt blocks with typed variable placeholders. The server now correctly computes and returns draft/published status for prompt blocks. Existing databases are automatically migrated when upgrading. ([#13351](https://github.com/mastra-ai/mastra/pull/13351))
10
+
11
+ - Updated dependencies [[`24284ff`](https://github.com/mastra-ai/mastra/commit/24284ffae306ddf0ab83273e13f033520839ef40), [`f5097cc`](https://github.com/mastra-ai/mastra/commit/f5097cc8a813c82c3378882c31178320cadeb655), [`71e237f`](https://github.com/mastra-ai/mastra/commit/71e237fa852a3ad9a50a3ddb3b5f3b20b9a8181c), [`13a291e`](https://github.com/mastra-ai/mastra/commit/13a291ebb9f9bca80befa0d9166b916bb348e8e9), [`397af5a`](https://github.com/mastra-ai/mastra/commit/397af5a69f34d4157f51a7c8da3f1ded1e1d611c), [`d4701f7`](https://github.com/mastra-ai/mastra/commit/d4701f7e24822b081b70f9c806c39411b1a712e7), [`2b40831`](https://github.com/mastra-ai/mastra/commit/2b40831dcca2275c9570ddf09b7f25ba3e8dc7fc), [`6184727`](https://github.com/mastra-ai/mastra/commit/6184727e812bf7a65cee209bacec3a2f5a16e923), [`0c338b8`](https://github.com/mastra-ai/mastra/commit/0c338b87362dcd95ff8191ca00df645b6953f534), [`6f6385b`](https://github.com/mastra-ai/mastra/commit/6f6385be5b33687cd21e71fc27e972e6928bb34c), [`14aba61`](https://github.com/mastra-ai/mastra/commit/14aba61b9cff76d72bc7ef6f3a83ae2c5d059193), [`dd9dd1c`](https://github.com/mastra-ai/mastra/commit/dd9dd1c9ae32ae79093f8c4adde1732ac6357233)]:
12
+ - @mastra/core@1.7.0
13
+
14
+ ## 1.6.1-alpha.0
15
+
16
+ ### Patch Changes
17
+
18
+ - Fixed non-deterministic query ordering by adding secondary sort on id for dataset and dataset item queries. ([#13399](https://github.com/mastra-ai/mastra/pull/13399))
19
+
20
+ - Prompt blocks can now define their own variables schema (`requestContextSchema`), allowing you to create reusable prompt blocks with typed variable placeholders. The server now correctly computes and returns draft/published status for prompt blocks. Existing databases are automatically migrated when upgrading. ([#13351](https://github.com/mastra-ai/mastra/pull/13351))
21
+
22
+ - Updated dependencies [[`24284ff`](https://github.com/mastra-ai/mastra/commit/24284ffae306ddf0ab83273e13f033520839ef40), [`f5097cc`](https://github.com/mastra-ai/mastra/commit/f5097cc8a813c82c3378882c31178320cadeb655), [`71e237f`](https://github.com/mastra-ai/mastra/commit/71e237fa852a3ad9a50a3ddb3b5f3b20b9a8181c), [`13a291e`](https://github.com/mastra-ai/mastra/commit/13a291ebb9f9bca80befa0d9166b916bb348e8e9), [`397af5a`](https://github.com/mastra-ai/mastra/commit/397af5a69f34d4157f51a7c8da3f1ded1e1d611c), [`d4701f7`](https://github.com/mastra-ai/mastra/commit/d4701f7e24822b081b70f9c806c39411b1a712e7), [`2b40831`](https://github.com/mastra-ai/mastra/commit/2b40831dcca2275c9570ddf09b7f25ba3e8dc7fc), [`6184727`](https://github.com/mastra-ai/mastra/commit/6184727e812bf7a65cee209bacec3a2f5a16e923), [`6f6385b`](https://github.com/mastra-ai/mastra/commit/6f6385be5b33687cd21e71fc27e972e6928bb34c), [`14aba61`](https://github.com/mastra-ai/mastra/commit/14aba61b9cff76d72bc7ef6f3a83ae2c5d059193), [`dd9dd1c`](https://github.com/mastra-ai/mastra/commit/dd9dd1c9ae32ae79093f8c4adde1732ac6357233)]:
23
+ - @mastra/core@1.7.0-alpha.0
24
+
3
25
  ## 1.6.0
4
26
 
5
27
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -4365,7 +4365,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4365
4365
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
4366
4366
  const limitValue = perPageInput === false ? total : perPage;
4367
4367
  const rows = await this.#db.client.manyOrNone(
4368
- `SELECT * FROM ${tableName} ORDER BY "createdAt" DESC LIMIT $1 OFFSET $2`,
4368
+ `SELECT * FROM ${tableName} ORDER BY "createdAt" DESC, "id" ASC LIMIT $1 OFFSET $2`,
4369
4369
  [limitValue, offset]
4370
4370
  );
4371
4371
  return {
@@ -4769,7 +4769,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4769
4769
  try {
4770
4770
  const tableName = getTableName2({ indexName: storage.TABLE_DATASET_ITEMS, schemaName: getSchemaName2(this.#schema) });
4771
4771
  const rows = await this.#db.client.manyOrNone(
4772
- `SELECT * FROM ${tableName} WHERE "datasetId" = $1 AND "datasetVersion" <= $2 AND ("validTo" IS NULL OR "validTo" > $3) AND "isDeleted" = false ORDER BY "createdAt" DESC`,
4772
+ `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`,
4773
4773
  [datasetId, version, version]
4774
4774
  );
4775
4775
  return (rows || []).map((row) => this.transformItemRow(row));
@@ -4840,7 +4840,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4840
4840
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
4841
4841
  const limitValue = perPageInput === false ? total : perPage;
4842
4842
  const rows = await this.#db.client.manyOrNone(
4843
- `SELECT * FROM ${tableName} ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`,
4843
+ `SELECT * FROM ${tableName} ${whereClause} ORDER BY "createdAt" DESC, "id" ASC LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`,
4844
4844
  [...queryParams, limitValue, offset]
4845
4845
  );
4846
4846
  return {
@@ -9444,7 +9444,7 @@ var ObservabilityPG = class _ObservabilityPG extends storage.ObservabilityStorag
9444
9444
  }
9445
9445
  }
9446
9446
  };
9447
- var SNAPSHOT_FIELDS3 = ["name", "description", "content", "rules"];
9447
+ var SNAPSHOT_FIELDS3 = ["name", "description", "content", "rules", "requestContextSchema"];
9448
9448
  var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
9449
9449
  #db;
9450
9450
  #schema;
@@ -9517,6 +9517,11 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
9517
9517
  tableName: storage.TABLE_PROMPT_BLOCK_VERSIONS,
9518
9518
  schema: storage.TABLE_SCHEMAS[storage.TABLE_PROMPT_BLOCK_VERSIONS]
9519
9519
  });
9520
+ await this.#db.alterTable({
9521
+ tableName: storage.TABLE_PROMPT_BLOCK_VERSIONS,
9522
+ schema: storage.TABLE_SCHEMAS[storage.TABLE_PROMPT_BLOCK_VERSIONS],
9523
+ ifNotExists: ["requestContextSchema"]
9524
+ });
9520
9525
  await this.createDefaultIndexes();
9521
9526
  await this.createCustomIndexes();
9522
9527
  }
@@ -9708,7 +9713,7 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
9708
9713
  }
9709
9714
  }
9710
9715
  async list(args) {
9711
- const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status = "published" } = args || {};
9716
+ const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status } = args || {};
9712
9717
  const { field, direction } = this.parseOrderBy(orderBy);
9713
9718
  if (page < 0) {
9714
9719
  throw new error.MastraError(
@@ -9728,8 +9733,10 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
9728
9733
  const conditions = [];
9729
9734
  const queryParams = [];
9730
9735
  let paramIdx = 1;
9731
- conditions.push(`status = $${paramIdx++}`);
9732
- queryParams.push(status);
9736
+ if (status) {
9737
+ conditions.push(`status = $${paramIdx++}`);
9738
+ queryParams.push(status);
9739
+ }
9733
9740
  if (authorId !== void 0) {
9734
9741
  conditions.push(`"authorId" = $${paramIdx++}`);
9735
9742
  queryParams.push(authorId);
@@ -9738,7 +9745,7 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
9738
9745
  conditions.push(`metadata @> $${paramIdx++}::jsonb`);
9739
9746
  queryParams.push(JSON.stringify(metadata));
9740
9747
  }
9741
- const whereClause = `WHERE ${conditions.join(" AND ")}`;
9748
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
9742
9749
  const countResult = await this.#db.client.one(
9743
9750
  `SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`,
9744
9751
  queryParams
@@ -9792,10 +9799,10 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
9792
9799
  await this.#db.client.none(
9793
9800
  `INSERT INTO ${tableName} (
9794
9801
  id, "blockId", "versionNumber",
9795
- name, description, content, rules,
9802
+ name, description, content, rules, "requestContextSchema",
9796
9803
  "changedFields", "changeMessage",
9797
9804
  "createdAt", "createdAtZ"
9798
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)`,
9805
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)`,
9799
9806
  [
9800
9807
  input.id,
9801
9808
  input.blockId,
@@ -9804,6 +9811,7 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
9804
9811
  input.description ?? null,
9805
9812
  input.content,
9806
9813
  input.rules ? JSON.stringify(input.rules) : null,
9814
+ input.requestContextSchema ? JSON.stringify(input.requestContextSchema) : null,
9807
9815
  input.changedFields ? JSON.stringify(input.changedFields) : null,
9808
9816
  input.changeMessage ?? null,
9809
9817
  nowIso,
@@ -10075,6 +10083,7 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
10075
10083
  description: row.description,
10076
10084
  content: row.content,
10077
10085
  rules: this.parseJson(row.rules, "rules"),
10086
+ requestContextSchema: this.parseJson(row.requestContextSchema, "requestContextSchema"),
10078
10087
  changedFields: this.parseJson(row.changedFields, "changedFields"),
10079
10088
  changeMessage: row.changeMessage,
10080
10089
  createdAt: new Date(row.createdAtZ || row.createdAt)