@mastra/pg 0.17.5 → 0.17.6

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,23 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.17.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixes "invalid input syntax for type json" error in AI tracing with PostgreSQL. ([#9181](https://github.com/mastra-ai/mastra/pull/9181))
8
+
9
+ - Updated dependencies [[`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18), [`2c4438b`](https://github.com/mastra-ai/mastra/commit/2c4438b87817ab7eed818c7990fef010475af1a3)]:
10
+ - @mastra/core@0.23.0
11
+
12
+ ## 0.17.6-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Fixes "invalid input syntax for type json" error in AI tracing with PostgreSQL. ([#9181](https://github.com/mastra-ai/mastra/pull/9181))
17
+
18
+ - Updated dependencies [[`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18), [`2c4438b`](https://github.com/mastra-ai/mastra/commit/2c4438b87817ab7eed818c7990fef010475af1a3)]:
19
+ - @mastra/core@0.23.0-alpha.0
20
+
3
21
  ## 0.17.5
4
22
 
5
23
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -2689,7 +2689,7 @@ var StoreOperationsPG = class extends storage.StoreOperations {
2689
2689
  return Object.entries(record).map(([key, value]) => {
2690
2690
  const schema = storage.TABLE_SCHEMAS[tableName];
2691
2691
  const columnSchema = schema?.[key];
2692
- if (columnSchema?.type === "jsonb" && value !== null && typeof value === "object") {
2692
+ if (columnSchema?.type === "jsonb" && value !== null && value !== void 0) {
2693
2693
  return JSON.stringify(value);
2694
2694
  }
2695
2695
  return value;
@@ -2711,15 +2711,24 @@ var StoreOperationsPG = class extends storage.StoreOperations {
2711
2711
  }
2712
2712
  /**
2713
2713
  * Prepares a value for database operations, handling Date objects and JSON serialization
2714
+ * This is schema-aware and only stringifies objects for JSONB columns
2714
2715
  */
2715
- prepareValue(value) {
2716
+ prepareValue(value, columnName, tableName) {
2717
+ if (value === null || value === void 0) {
2718
+ return value;
2719
+ }
2716
2720
  if (value instanceof Date) {
2717
2721
  return value.toISOString();
2718
- } else if (typeof value === "object" && value !== null) {
2722
+ }
2723
+ const schema = storage.TABLE_SCHEMAS[tableName];
2724
+ const columnSchema = schema?.[columnName];
2725
+ if (columnSchema?.type === "jsonb") {
2726
+ return JSON.stringify(value);
2727
+ }
2728
+ if (typeof value === "object") {
2719
2729
  return JSON.stringify(value);
2720
- } else {
2721
- return value;
2722
2730
  }
2731
+ return value;
2723
2732
  }
2724
2733
  async setupSchema() {
2725
2734
  if (!this.schemaName || this.schemaSetupComplete) {
@@ -3388,14 +3397,14 @@ var StoreOperationsPG = class extends storage.StoreOperations {
3388
3397
  Object.entries(data).forEach(([key, value]) => {
3389
3398
  const parsedKey = utils.parseSqlIdentifier(key, "column name");
3390
3399
  setColumns.push(`"${parsedKey}" = $${paramIndex++}`);
3391
- setValues.push(this.prepareValue(value));
3400
+ setValues.push(this.prepareValue(value, key, tableName));
3392
3401
  });
3393
3402
  const whereConditions = [];
3394
3403
  const whereValues = [];
3395
3404
  Object.entries(keys).forEach(([key, value]) => {
3396
3405
  const parsedKey = utils.parseSqlIdentifier(key, "column name");
3397
3406
  whereConditions.push(`"${parsedKey}" = $${paramIndex++}`);
3398
- whereValues.push(this.prepareValue(value));
3407
+ whereValues.push(this.prepareValue(value, key, tableName));
3399
3408
  });
3400
3409
  const tableName_ = getTableName({
3401
3410
  indexName: tableName,