@mastra/pg 1.8.1 → 1.8.2

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
@@ -7819,7 +7819,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7819
7819
  try {
7820
7820
  const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
7821
7821
  await this.#db.client.tx(async (t) => {
7822
- const messageInserts = messages.map((message) => {
7822
+ for (const message of messages) {
7823
7823
  if (!message.threadId) {
7824
7824
  throw new Error(
7825
7825
  `Expected to find a threadId for message, but couldn't find one. An unexpected error has occurred.`
@@ -7830,7 +7830,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7830
7830
  `Expected to find a resourceId for message, but couldn't find one. An unexpected error has occurred.`
7831
7831
  );
7832
7832
  }
7833
- return t.none(
7833
+ await t.none(
7834
7834
  `INSERT INTO ${tableName} (id, thread_id, content, "createdAt", "createdAtZ", role, type, "resourceId")
7835
7835
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
7836
7836
  ON CONFLICT (id) DO UPDATE SET
@@ -7850,19 +7850,17 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7850
7850
  message.resourceId
7851
7851
  ]
7852
7852
  );
7853
- });
7853
+ }
7854
7854
  const threadTableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7855
7855
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
7856
- const threadUpdate = t.none(
7856
+ await t.none(
7857
7857
  `UPDATE ${threadTableName}
7858
- SET
7859
- "updatedAt" = $1,
7860
- "updatedAtZ" = $2
7861
- WHERE id = $3
7862
- `,
7858
+ SET
7859
+ "updatedAt" = $1,
7860
+ "updatedAtZ" = $2
7861
+ WHERE id = $3`,
7863
7862
  [nowStr, nowStr, threadId]
7864
7863
  );
7865
- await Promise.all([...messageInserts, threadUpdate]);
7866
7864
  });
7867
7865
  const messagesWithParsedContent = messages.map((message) => {
7868
7866
  if (typeof message.content === "string") {
@@ -7999,10 +7997,10 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7999
7997
  const threadIds = messages?.map((msg) => msg.thread_id).filter(Boolean) || [];
8000
7998
  await t.none(`DELETE FROM ${messageTableName} WHERE id IN (${placeholders})`, messageIds);
8001
7999
  if (threadIds.length > 0) {
8002
- const updatePromises = threadIds.map(
8003
- (threadId) => t.none(`UPDATE ${threadTableName} SET "updatedAt" = NOW(), "updatedAtZ" = NOW() WHERE id = $1`, [threadId])
8000
+ await t.none(
8001
+ `UPDATE ${threadTableName} SET "updatedAt" = NOW(), "updatedAtZ" = NOW() WHERE id IN (${inPlaceholders(threadIds.length)})`,
8002
+ threadIds
8004
8003
  );
8005
- await Promise.all(updatePromises);
8006
8004
  }
8007
8005
  });
8008
8006
  } catch (error) {