@mastra/pg 1.17.1-alpha.0 → 1.17.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,16 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.17.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Improved Factory work-item concurrency by replacing distributed advisory locks with atomic claims, idempotent replay, and serializable relationship transactions. ([#20135](https://github.com/mastra-ai/mastra/pull/20135))
8
+
9
+ - Hardened distributed lock cleanup so clients are destroyed when transaction rollback fails. ([#20135](https://github.com/mastra-ai/mastra/pull/20135))
10
+
11
+ - Updated dependencies [[`c8d8a01`](https://github.com/mastra-ai/mastra/commit/c8d8a010ee2efe2b7bf4d07707382c34c87b14e4), [`df6a9ce`](https://github.com/mastra-ai/mastra/commit/df6a9ce87214f7aadb2edfe62f67605fe998a0a4), [`73839cb`](https://github.com/mastra-ai/mastra/commit/73839cb58322679c170627d1015669ede5f619aa), [`371cf60`](https://github.com/mastra-ai/mastra/commit/371cf6075cef88ac6919a08d59a82e485397364a), [`8e4dc79`](https://github.com/mastra-ai/mastra/commit/8e4dc793dcf035ea506f9ce79f56d2d501a4be14), [`2db93cc`](https://github.com/mastra-ai/mastra/commit/2db93ccd0b872e4de7853a93383efe0647901df8), [`094ab61`](https://github.com/mastra-ai/mastra/commit/094ab6129a1a3ecf6eeb86decac17d5faea4e02a), [`fe80944`](https://github.com/mastra-ai/mastra/commit/fe80944f3ef6681fea6eae8200fce387b7bb3c2f), [`263d2ca`](https://github.com/mastra-ai/mastra/commit/263d2cac80ba3b03b9c0f008db6f1f1b9eb0278c), [`75f843d`](https://github.com/mastra-ai/mastra/commit/75f843d09f758223e6eeb321321bdcc5c7e779d0), [`e51e166`](https://github.com/mastra-ai/mastra/commit/e51e166c52e220abc9b64554ce37359dca8544b1)]:
12
+ - @mastra/core@1.53.0
13
+
3
14
  ## 1.17.1-alpha.0
4
15
 
5
16
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.17.1-alpha.0"
6
+ version: "1.17.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.17.1-alpha.0",
2
+ "version": "1.17.1",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -9598,6 +9598,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9598
9598
  }
9599
9599
  const perPage = storage.normalizePerPage(perPageInput, 40);
9600
9600
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
9601
+ const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
9601
9602
  try {
9602
9603
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
9603
9604
  const orderByStatement = `ORDER BY COALESCE("${field}Z", "${field}") ${direction}`;
@@ -9639,13 +9640,27 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9639
9640
  hasMore: false
9640
9641
  };
9641
9642
  }
9642
- const countQuery = `SELECT COUNT(*) FROM ${tableName} ${whereClause}`;
9643
- const countResult = await this.#db.client.one(countQuery, queryParams);
9644
- const total = parseInt(countResult.count, 10);
9645
- const limitValue = perPageInput === false ? total : perPage;
9646
- const dataQuery = `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement} LIMIT $${paramIndex++} OFFSET $${paramIndex++}`;
9647
- const rows = await this.#db.client.manyOrNone(dataQuery, [...queryParams, limitValue, offset]);
9648
- const messages = [...rows || []];
9643
+ let total;
9644
+ let messages;
9645
+ if (metadataFilter) {
9646
+ const rows = await this.#db.client.manyOrNone(
9647
+ `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement}`,
9648
+ queryParams
9649
+ );
9650
+ const filteredRows = (rows || []).filter(
9651
+ (row) => storage.storageMessageMatchesMetadataFilter(row.content, metadataFilter)
9652
+ );
9653
+ total = filteredRows.length;
9654
+ messages = perPageInput === false ? filteredRows : filteredRows.slice(offset, offset + perPage);
9655
+ } else {
9656
+ const countResult = await this.#db.client.one(`SELECT COUNT(*) FROM ${tableName} ${whereClause}`, queryParams);
9657
+ total = parseInt(countResult.count, 10);
9658
+ const limitValue = perPageInput === false ? total : perPage;
9659
+ const dataQuery = `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement} LIMIT $${paramIndex++} OFFSET $${paramIndex++}`;
9660
+ const rows = await this.#db.client.manyOrNone(dataQuery, [...queryParams, limitValue, offset]);
9661
+ messages = [...rows || []];
9662
+ }
9663
+ const primaryPageCount = messages.length;
9649
9664
  if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
9650
9665
  return {
9651
9666
  messages: [],
@@ -9675,7 +9690,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9675
9690
  finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
9676
9691
  );
9677
9692
  const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
9678
- const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
9693
+ const hasMore = metadataFilter ? perPageInput !== false && offset + primaryPageCount < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
9679
9694
  return {
9680
9695
  messages: finalMessages,
9681
9696
  total,
@@ -9737,6 +9752,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9737
9752
  }
9738
9753
  const perPage = storage.normalizePerPage(perPageInput, 40);
9739
9754
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
9755
+ const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
9740
9756
  try {
9741
9757
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
9742
9758
  const orderByStatement = `ORDER BY COALESCE("${field}Z", "${field}") ${direction}`;
@@ -9782,13 +9798,26 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9782
9798
  hasMore: false
9783
9799
  };
9784
9800
  }
9785
- const countQuery = `SELECT COUNT(*) FROM ${tableName} ${whereClause}`;
9786
- const countResult = await this.#db.client.one(countQuery, queryParams);
9787
- const total = parseInt(countResult.count, 10);
9788
- const limitValue = perPageInput === false ? total : perPage;
9789
- const dataQuery = `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement} LIMIT $${paramIndex++} OFFSET $${paramIndex++}`;
9790
- const rows = await this.#db.client.manyOrNone(dataQuery, [...queryParams, limitValue, offset]);
9791
- const messages = [...rows || []];
9801
+ let total;
9802
+ let messages;
9803
+ if (metadataFilter) {
9804
+ const rows = await this.#db.client.manyOrNone(
9805
+ `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement}`,
9806
+ queryParams
9807
+ );
9808
+ const filteredRows = (rows || []).filter(
9809
+ (row) => storage.storageMessageMatchesMetadataFilter(row.content, metadataFilter)
9810
+ );
9811
+ total = filteredRows.length;
9812
+ messages = perPageInput === false ? filteredRows : filteredRows.slice(offset, offset + perPage);
9813
+ } else {
9814
+ const countResult = await this.#db.client.one(`SELECT COUNT(*) FROM ${tableName} ${whereClause}`, queryParams);
9815
+ total = parseInt(countResult.count, 10);
9816
+ const limitValue = perPageInput === false ? total : perPage;
9817
+ const dataQuery = `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement} LIMIT $${paramIndex++} OFFSET $${paramIndex++}`;
9818
+ const rows = await this.#db.client.manyOrNone(dataQuery, [...queryParams, limitValue, offset]);
9819
+ messages = [...rows || []];
9820
+ }
9792
9821
  if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
9793
9822
  return {
9794
9823
  messages: [],