@mastra/pg 1.8.4 → 1.8.5

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
@@ -7330,7 +7330,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7330
7330
  };
7331
7331
  }
7332
7332
  const limitValue = perPageInput === false ? total : perPage;
7333
- const dataQuery = `SELECT id, "resourceId", title, metadata, "createdAt", "createdAtZ", "updatedAt", "updatedAtZ" ${baseQuery} ORDER BY "${field}" ${direction} LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`;
7333
+ const dataQuery = `SELECT id, "resourceId", title, metadata, "createdAt", "createdAtZ", "updatedAt", "updatedAtZ" ${baseQuery} ORDER BY COALESCE("${field}Z", "${field}") ${direction} LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`;
7334
7334
  const rows = await this.#db.client.manyOrNone(
7335
7335
  dataQuery,
7336
7336
  [...queryParams, limitValue, offset]
@@ -7448,7 +7448,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7448
7448
  ...metadata
7449
7449
  };
7450
7450
  try {
7451
- const now = (/* @__PURE__ */ new Date()).toISOString();
7451
+ const now = /* @__PURE__ */ new Date();
7452
7452
  const thread = await this.#db.client.one(
7453
7453
  `UPDATE ${threadTableName}
7454
7454
  SET
@@ -7694,7 +7694,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7694
7694
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
7695
7695
  try {
7696
7696
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
7697
- const orderByStatement = `ORDER BY "${field}" ${direction}`;
7697
+ const orderByStatement = `ORDER BY COALESCE("${field}Z", "${field}") ${direction}`;
7698
7698
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7699
7699
  const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
7700
7700
  const conditions = [`thread_id IN (${inPlaceholders(threadIds.length)})`];
@@ -7833,7 +7833,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7833
7833
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
7834
7834
  try {
7835
7835
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
7836
- const orderByStatement = `ORDER BY "${field}" ${direction}`;
7836
+ const orderByStatement = `ORDER BY COALESCE("${field}Z", "${field}") ${direction}`;
7837
7837
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7838
7838
  const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
7839
7839
  const conditions = [];
@@ -7843,12 +7843,12 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7843
7843
  queryParams.push(resourceId);
7844
7844
  if (filter?.dateRange?.start) {
7845
7845
  const startOp = filter.dateRange.startExclusive ? ">" : ">=";
7846
- conditions.push(`"createdAt" ${startOp} $${paramIndex++}`);
7846
+ conditions.push(`COALESCE("createdAtZ", "createdAt") ${startOp} $${paramIndex++}`);
7847
7847
  queryParams.push(filter.dateRange.start);
7848
7848
  }
7849
7849
  if (filter?.dateRange?.end) {
7850
7850
  const endOp = filter.dateRange.endExclusive ? "<" : "<=";
7851
- conditions.push(`"createdAt" ${endOp} $${paramIndex++}`);
7851
+ conditions.push(`COALESCE("createdAtZ", "createdAt") ${endOp} $${paramIndex++}`);
7852
7852
  queryParams.push(filter.dateRange.end);
7853
7853
  }
7854
7854
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
@@ -7988,8 +7988,8 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7988
7988
  message.id,
7989
7989
  message.threadId,
7990
7990
  typeof message.content === "string" ? message.content : JSON.stringify(message.content),
7991
- message.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
7992
- message.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
7991
+ message.createdAt || /* @__PURE__ */ new Date(),
7992
+ message.createdAt || /* @__PURE__ */ new Date(),
7993
7993
  message.role,
7994
7994
  message.type || "v2",
7995
7995
  message.resourceId
@@ -7997,14 +7997,14 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7997
7997
  );
7998
7998
  }
7999
7999
  const threadTableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
8000
- const nowStr = (/* @__PURE__ */ new Date()).toISOString();
8000
+ const now = /* @__PURE__ */ new Date();
8001
8001
  await t.none(
8002
8002
  `UPDATE ${threadTableName}
8003
8003
  SET
8004
8004
  "updatedAt" = $1,
8005
8005
  "updatedAtZ" = $2
8006
8006
  WHERE id = $3`,
8007
- [nowStr, nowStr, threadId]
8007
+ [now, now, threadId]
8008
8008
  );
8009
8009
  });
8010
8010
  const messagesWithParsedContent = messages.map((message) => {