@mastra/pg 1.10.1-alpha.1 → 1.10.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/dist/index.cjs CHANGED
@@ -2038,7 +2038,6 @@ var PoolAdapter = class {
2038
2038
  constructor($pool) {
2039
2039
  this.$pool = $pool;
2040
2040
  }
2041
- $pool;
2042
2041
  connect() {
2043
2042
  return this.$pool.connect();
2044
2043
  }
@@ -2107,7 +2106,6 @@ var TransactionClient = class {
2107
2106
  constructor(client) {
2108
2107
  this.client = client;
2109
2108
  }
2110
- client;
2111
2109
  async none(query, values) {
2112
2110
  await this.client.query(query, values);
2113
2111
  return null;
@@ -3451,6 +3449,15 @@ function getTableName2({ indexName, schemaName }) {
3451
3449
  const quotedSchemaName = schemaName;
3452
3450
  return quotedSchemaName ? `${quotedSchemaName}.${quotedIndexName}` : quotedIndexName;
3453
3451
  }
3452
+ function parseJsonResilient(value, _fieldName) {
3453
+ if (value == null) return void 0;
3454
+ if (typeof value !== "string") return value;
3455
+ try {
3456
+ return JSON.parse(value);
3457
+ } catch {
3458
+ return value;
3459
+ }
3460
+ }
3454
3461
  function transformFromSqlRow({
3455
3462
  tableName,
3456
3463
  sqlRow
@@ -3712,38 +3719,13 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
3712
3719
  await this.#db.clearTable({ tableName: storage.TABLE_AGENT_VERSIONS });
3713
3720
  await this.#db.clearTable({ tableName: storage.TABLE_AGENTS });
3714
3721
  }
3715
- parseJson(value, fieldName) {
3716
- if (!value) return void 0;
3717
- if (typeof value !== "string") return value;
3718
- try {
3719
- return JSON.parse(value);
3720
- } catch (error$1) {
3721
- if (error$1 instanceof error.MastraError) throw error$1;
3722
- const details = {
3723
- value: value.length > 100 ? value.substring(0, 100) + "..." : value
3724
- };
3725
- if (fieldName) {
3726
- details.field = fieldName;
3727
- }
3728
- throw new error.MastraError(
3729
- {
3730
- id: storage.createStorageErrorId("PG", "PARSE_JSON", "INVALID_JSON"),
3731
- domain: error.ErrorDomain.STORAGE,
3732
- category: error.ErrorCategory.SYSTEM,
3733
- text: `Failed to parse JSON${fieldName ? ` for field "${fieldName}"` : ""}: ${error$1 instanceof Error ? error$1.message : "Unknown error"}`,
3734
- details
3735
- },
3736
- error$1
3737
- );
3738
- }
3739
- }
3740
3722
  parseRow(row) {
3741
3723
  return {
3742
3724
  id: row.id,
3743
3725
  status: row.status,
3744
3726
  activeVersionId: row.activeVersionId,
3745
3727
  authorId: row.authorId,
3746
- metadata: this.parseJson(row.metadata, "metadata"),
3728
+ metadata: parseJsonResilient(row.metadata),
3747
3729
  createdAt: row.createdAtZ || row.createdAt,
3748
3730
  updatedAt: row.updatedAtZ || row.updatedAt
3749
3731
  };
@@ -3972,7 +3954,14 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
3972
3954
  `SELECT * FROM ${tableName} ${whereClause} ORDER BY "${field}" ${direction} LIMIT $${paramIdx++} OFFSET $${paramIdx++}`,
3973
3955
  [...queryParams, limitValue, offset]
3974
3956
  );
3975
- const agents = (dataResult || []).map((row) => this.parseRow(row));
3957
+ const agents = (dataResult || []).flatMap((row) => {
3958
+ try {
3959
+ return [this.parseRow(row)];
3960
+ } catch (err) {
3961
+ this.logger?.warn?.("[PG] Failed to map agent row, skipping", { id: row?.id, error: err });
3962
+ return [];
3963
+ }
3964
+ });
3976
3965
  return {
3977
3966
  agents,
3978
3967
  total,
@@ -4160,7 +4149,14 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
4160
4149
  `SELECT * FROM ${tableName} WHERE "agentId" = $1 ORDER BY "${field}" ${direction} LIMIT $2 OFFSET $3`,
4161
4150
  [agentId, limitValue, offset]
4162
4151
  );
4163
- const versions = (dataResult || []).map((row) => this.parseVersionRow(row));
4152
+ const versions = (dataResult || []).flatMap((row) => {
4153
+ try {
4154
+ return [this.parseVersionRow(row)];
4155
+ } catch (err) {
4156
+ this.logger?.warn?.("[PG] Failed to map agent version row, skipping", { id: row?.id, error: err });
4157
+ return [];
4158
+ }
4159
+ });
4164
4160
  return {
4165
4161
  versions,
4166
4162
  total,
@@ -4259,22 +4255,22 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
4259
4255
  name: row.name,
4260
4256
  description: row.description,
4261
4257
  instructions: this.deserializeInstructions(row.instructions),
4262
- model: this.parseJson(row.model, "model"),
4263
- tools: this.parseJson(row.tools, "tools"),
4264
- defaultOptions: this.parseJson(row.defaultOptions, "defaultOptions"),
4265
- workflows: this.parseJson(row.workflows, "workflows"),
4266
- agents: this.parseJson(row.agents, "agents"),
4267
- integrationTools: this.parseJson(row.integrationTools, "integrationTools"),
4268
- inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
4269
- outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
4270
- memory: this.parseJson(row.memory, "memory"),
4271
- scorers: this.parseJson(row.scorers, "scorers"),
4272
- mcpClients: this.parseJson(row.mcpClients, "mcpClients"),
4273
- requestContextSchema: this.parseJson(row.requestContextSchema, "requestContextSchema"),
4274
- workspace: this.parseJson(row.workspace, "workspace"),
4275
- skills: this.parseJson(row.skills, "skills"),
4258
+ model: parseJsonResilient(row.model),
4259
+ tools: parseJsonResilient(row.tools),
4260
+ defaultOptions: parseJsonResilient(row.defaultOptions),
4261
+ workflows: parseJsonResilient(row.workflows),
4262
+ agents: parseJsonResilient(row.agents),
4263
+ integrationTools: parseJsonResilient(row.integrationTools),
4264
+ inputProcessors: parseJsonResilient(row.inputProcessors),
4265
+ outputProcessors: parseJsonResilient(row.outputProcessors),
4266
+ memory: parseJsonResilient(row.memory),
4267
+ scorers: parseJsonResilient(row.scorers),
4268
+ mcpClients: parseJsonResilient(row.mcpClients),
4269
+ requestContextSchema: parseJsonResilient(row.requestContextSchema),
4270
+ workspace: parseJsonResilient(row.workspace),
4271
+ skills: parseJsonResilient(row.skills),
4276
4272
  skillsFormat: row.skillsFormat,
4277
- changedFields: this.parseJson(row.changedFields, "changedFields"),
4273
+ changedFields: parseJsonResilient(row.changedFields),
4278
4274
  changeMessage: row.changeMessage,
4279
4275
  createdAt: row.createdAtZ || row.createdAt
4280
4276
  };
@@ -6714,7 +6710,14 @@ var MCPClientsPG = class _MCPClientsPG extends storage.MCPClientsStorage {
6714
6710
  `SELECT * FROM ${tableName} ${whereClause} ORDER BY "${field}" ${direction} LIMIT $${paramIdx++} OFFSET $${paramIdx++}`,
6715
6711
  [...queryParams, limitValue, offset]
6716
6712
  );
6717
- const mcpClients = (dataResult || []).map((row) => this.parseMCPClientRow(row));
6713
+ const mcpClients = (dataResult || []).flatMap((row) => {
6714
+ try {
6715
+ return [this.parseMCPClientRow(row)];
6716
+ } catch (err) {
6717
+ this.logger?.warn?.("[PG] Failed to map mcp client row, skipping", { id: row?.id, error: err });
6718
+ return [];
6719
+ }
6720
+ });
6718
6721
  return {
6719
6722
  mcpClients,
6720
6723
  total,
@@ -6900,7 +6903,14 @@ var MCPClientsPG = class _MCPClientsPG extends storage.MCPClientsStorage {
6900
6903
  `SELECT * FROM ${tableName} WHERE "mcpClientId" = $1 ORDER BY "${field}" ${direction} LIMIT $2 OFFSET $3`,
6901
6904
  [mcpClientId, limitValue, offset]
6902
6905
  );
6903
- const versions = (dataResult || []).map((row) => this.parseVersionRow(row));
6906
+ const versions = (dataResult || []).flatMap((row) => {
6907
+ try {
6908
+ return [this.parseVersionRow(row)];
6909
+ } catch (err) {
6910
+ this.logger?.warn?.("[PG] Failed to map mcp client version row, skipping", { id: row?.id, error: err });
6911
+ return [];
6912
+ }
6913
+ });
6904
6914
  return {
6905
6915
  versions,
6906
6916
  total,
@@ -6987,38 +6997,13 @@ var MCPClientsPG = class _MCPClientsPG extends storage.MCPClientsStorage {
6987
6997
  // ==========================================================================
6988
6998
  // Private Helper Methods
6989
6999
  // ==========================================================================
6990
- parseJson(value, fieldName) {
6991
- if (!value) return void 0;
6992
- if (typeof value !== "string") return value;
6993
- try {
6994
- return JSON.parse(value);
6995
- } catch (error$1) {
6996
- if (error$1 instanceof error.MastraError) throw error$1;
6997
- const details = {
6998
- value: value.length > 100 ? value.substring(0, 100) + "..." : value
6999
- };
7000
- if (fieldName) {
7001
- details.field = fieldName;
7002
- }
7003
- throw new error.MastraError(
7004
- {
7005
- id: storage.createStorageErrorId("PG", "PARSE_JSON", "INVALID_JSON"),
7006
- domain: error.ErrorDomain.STORAGE,
7007
- category: error.ErrorCategory.SYSTEM,
7008
- text: `Failed to parse JSON${fieldName ? ` for field "${fieldName}"` : ""}: ${error$1 instanceof Error ? error$1.message : "Unknown error"}`,
7009
- details
7010
- },
7011
- error$1
7012
- );
7013
- }
7014
- }
7015
7000
  parseMCPClientRow(row) {
7016
7001
  return {
7017
7002
  id: row.id,
7018
7003
  status: row.status,
7019
7004
  activeVersionId: row.activeVersionId,
7020
7005
  authorId: row.authorId,
7021
- metadata: this.parseJson(row.metadata, "metadata"),
7006
+ metadata: parseJsonResilient(row.metadata),
7022
7007
  createdAt: new Date(row.createdAtZ || row.createdAt),
7023
7008
  updatedAt: new Date(row.updatedAtZ || row.updatedAt)
7024
7009
  };
@@ -7030,8 +7015,8 @@ var MCPClientsPG = class _MCPClientsPG extends storage.MCPClientsStorage {
7030
7015
  versionNumber: row.versionNumber,
7031
7016
  name: row.name,
7032
7017
  description: row.description,
7033
- servers: this.parseJson(row.servers, "servers"),
7034
- changedFields: this.parseJson(row.changedFields, "changedFields"),
7018
+ servers: parseJsonResilient(row.servers),
7019
+ changedFields: parseJsonResilient(row.changedFields),
7035
7020
  changeMessage: row.changeMessage,
7036
7021
  createdAt: new Date(row.createdAtZ || row.createdAt)
7037
7022
  };
@@ -7338,7 +7323,14 @@ var MCPServersPG = class _MCPServersPG extends storage.MCPServersStorage {
7338
7323
  `SELECT * FROM ${tableName} ${whereClause} ORDER BY "${field}" ${direction} LIMIT $${paramIdx++} OFFSET $${paramIdx++}`,
7339
7324
  [...queryParams, limitValue, offset]
7340
7325
  );
7341
- const mcpServers = (dataResult || []).map((row) => this.parseMCPServerRow(row));
7326
+ const mcpServers = (dataResult || []).flatMap((row) => {
7327
+ try {
7328
+ return [this.parseMCPServerRow(row)];
7329
+ } catch (err) {
7330
+ this.logger?.warn?.("[PG] Failed to map mcp server row, skipping", { id: row?.id, error: err });
7331
+ return [];
7332
+ }
7333
+ });
7342
7334
  return {
7343
7335
  mcpServers,
7344
7336
  total,
@@ -7534,7 +7526,14 @@ var MCPServersPG = class _MCPServersPG extends storage.MCPServersStorage {
7534
7526
  `SELECT * FROM ${tableName} WHERE "mcpServerId" = $1 ORDER BY "${field}" ${direction} LIMIT $2 OFFSET $3`,
7535
7527
  [mcpServerId, limitValue, offset]
7536
7528
  );
7537
- const versions = (dataResult || []).map((row) => this.parseVersionRow(row));
7529
+ const versions = (dataResult || []).flatMap((row) => {
7530
+ try {
7531
+ return [this.parseVersionRow(row)];
7532
+ } catch (err) {
7533
+ this.logger?.warn?.("[PG] Failed to map mcp server version row, skipping", { id: row?.id, error: err });
7534
+ return [];
7535
+ }
7536
+ });
7538
7537
  return {
7539
7538
  versions,
7540
7539
  total,
@@ -7621,38 +7620,13 @@ var MCPServersPG = class _MCPServersPG extends storage.MCPServersStorage {
7621
7620
  // ==========================================================================
7622
7621
  // Private Helper Methods
7623
7622
  // ==========================================================================
7624
- parseJson(value, fieldName) {
7625
- if (!value) return void 0;
7626
- if (typeof value !== "string") return value;
7627
- try {
7628
- return JSON.parse(value);
7629
- } catch (error$1) {
7630
- if (error$1 instanceof error.MastraError) throw error$1;
7631
- const details = {
7632
- valueLength: String(value.length)
7633
- };
7634
- if (fieldName) {
7635
- details.field = fieldName;
7636
- }
7637
- throw new error.MastraError(
7638
- {
7639
- id: storage.createStorageErrorId("PG", "PARSE_JSON", "INVALID_JSON"),
7640
- domain: error.ErrorDomain.STORAGE,
7641
- category: error.ErrorCategory.SYSTEM,
7642
- text: `Failed to parse JSON${fieldName ? ` for field "${fieldName}"` : ""}: ${error$1 instanceof Error ? error$1.message : "Unknown error"}`,
7643
- details
7644
- },
7645
- error$1
7646
- );
7647
- }
7648
- }
7649
7623
  parseMCPServerRow(row) {
7650
7624
  return {
7651
7625
  id: row.id,
7652
7626
  status: row.status,
7653
7627
  activeVersionId: row.activeVersionId,
7654
7628
  authorId: row.authorId,
7655
- metadata: this.parseJson(row.metadata, "metadata"),
7629
+ metadata: parseJsonResilient(row.metadata),
7656
7630
  createdAt: new Date(row.createdAtZ || row.createdAt),
7657
7631
  updatedAt: new Date(row.updatedAtZ || row.updatedAt)
7658
7632
  };
@@ -7666,14 +7640,14 @@ var MCPServersPG = class _MCPServersPG extends storage.MCPServersStorage {
7666
7640
  version: row.version,
7667
7641
  description: row.description,
7668
7642
  instructions: row.instructions,
7669
- repository: this.parseJson(row.repository, "repository"),
7643
+ repository: parseJsonResilient(row.repository),
7670
7644
  releaseDate: row.releaseDate,
7671
7645
  isLatest: row.isLatest,
7672
7646
  packageCanonical: row.packageCanonical,
7673
- tools: this.parseJson(row.tools, "tools"),
7674
- agents: this.parseJson(row.agents, "agents"),
7675
- workflows: this.parseJson(row.workflows, "workflows"),
7676
- changedFields: this.parseJson(row.changedFields, "changedFields"),
7647
+ tools: parseJsonResilient(row.tools),
7648
+ agents: parseJsonResilient(row.agents),
7649
+ workflows: parseJsonResilient(row.workflows),
7650
+ changedFields: parseJsonResilient(row.changedFields),
7677
7651
  changeMessage: row.changeMessage,
7678
7652
  createdAt: new Date(row.createdAtZ || row.createdAt)
7679
7653
  };
@@ -11082,7 +11056,14 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
11082
11056
  `SELECT * FROM ${tableName} ${whereClause} ORDER BY "${field}" ${direction} LIMIT $${paramIdx++} OFFSET $${paramIdx++}`,
11083
11057
  [...queryParams, limitValue, offset]
11084
11058
  );
11085
- const promptBlocks = (dataResult || []).map((row) => this.parseBlockRow(row));
11059
+ const promptBlocks = (dataResult || []).flatMap((row) => {
11060
+ try {
11061
+ return [this.parseBlockRow(row)];
11062
+ } catch (err) {
11063
+ this.logger?.warn?.("[PG] Failed to map prompt block row, skipping", { id: row?.id, error: err });
11064
+ return [];
11065
+ }
11066
+ });
11086
11067
  return {
11087
11068
  promptBlocks,
11088
11069
  total,
@@ -11269,7 +11250,14 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
11269
11250
  `SELECT * FROM ${tableName} WHERE "blockId" = $1 ORDER BY "${field}" ${direction} LIMIT $2 OFFSET $3`,
11270
11251
  [blockId, limitValue, offset]
11271
11252
  );
11272
- const versions = (dataResult || []).map((row) => this.parseVersionRow(row));
11253
+ const versions = (dataResult || []).flatMap((row) => {
11254
+ try {
11255
+ return [this.parseVersionRow(row)];
11256
+ } catch (err) {
11257
+ this.logger?.warn?.("[PG] Failed to map prompt block version row, skipping", { id: row?.id, error: err });
11258
+ return [];
11259
+ }
11260
+ });
11273
11261
  return {
11274
11262
  versions,
11275
11263
  total,
@@ -11356,37 +11344,13 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
11356
11344
  // ==========================================================================
11357
11345
  // Private Helper Methods
11358
11346
  // ==========================================================================
11359
- parseJson(value, fieldName) {
11360
- if (!value) return void 0;
11361
- if (typeof value !== "string") return value;
11362
- try {
11363
- return JSON.parse(value);
11364
- } catch (error$1) {
11365
- const details = {
11366
- value: value.length > 100 ? value.substring(0, 100) + "..." : value
11367
- };
11368
- if (fieldName) {
11369
- details.field = fieldName;
11370
- }
11371
- throw new error.MastraError(
11372
- {
11373
- id: storage.createStorageErrorId("PG", "PARSE_JSON", "INVALID_JSON"),
11374
- domain: error.ErrorDomain.STORAGE,
11375
- category: error.ErrorCategory.SYSTEM,
11376
- text: `Failed to parse JSON${fieldName ? ` for field "${fieldName}"` : ""}: ${error$1 instanceof Error ? error$1.message : "Unknown error"}`,
11377
- details
11378
- },
11379
- error$1
11380
- );
11381
- }
11382
- }
11383
11347
  parseBlockRow(row) {
11384
11348
  return {
11385
11349
  id: row.id,
11386
11350
  status: row.status,
11387
11351
  activeVersionId: row.activeVersionId,
11388
11352
  authorId: row.authorId,
11389
- metadata: this.parseJson(row.metadata, "metadata"),
11353
+ metadata: parseJsonResilient(row.metadata),
11390
11354
  createdAt: new Date(row.createdAtZ || row.createdAt),
11391
11355
  updatedAt: new Date(row.updatedAtZ || row.updatedAt)
11392
11356
  };
@@ -11399,9 +11363,9 @@ var PromptBlocksPG = class _PromptBlocksPG extends storage.PromptBlocksStorage {
11399
11363
  name: row.name,
11400
11364
  description: row.description,
11401
11365
  content: row.content,
11402
- rules: this.parseJson(row.rules, "rules"),
11403
- requestContextSchema: this.parseJson(row.requestContextSchema, "requestContextSchema"),
11404
- changedFields: this.parseJson(row.changedFields, "changedFields"),
11366
+ rules: parseJsonResilient(row.rules),
11367
+ requestContextSchema: parseJsonResilient(row.requestContextSchema),
11368
+ changedFields: parseJsonResilient(row.changedFields),
11405
11369
  changeMessage: row.changeMessage,
11406
11370
  createdAt: new Date(row.createdAtZ || row.createdAt)
11407
11371
  };
@@ -12018,7 +11982,14 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends storage.ScorerDefin
12018
11982
  `SELECT * FROM ${tableName} ${whereClause} ORDER BY "${field}" ${direction} LIMIT $${paramIdx++} OFFSET $${paramIdx++}`,
12019
11983
  [...queryParams, limitValue, offset]
12020
11984
  );
12021
- const scorerDefinitions = (dataResult || []).map((row) => this.parseScorerRow(row));
11985
+ const scorerDefinitions = (dataResult || []).flatMap((row) => {
11986
+ try {
11987
+ return [this.parseScorerRow(row)];
11988
+ } catch (err) {
11989
+ this.logger?.warn?.("[PG] Failed to map scorer definition row, skipping", { id: row?.id, error: err });
11990
+ return [];
11991
+ }
11992
+ });
12022
11993
  return {
12023
11994
  scorerDefinitions,
12024
11995
  total,
@@ -12209,7 +12180,17 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends storage.ScorerDefin
12209
12180
  `SELECT * FROM ${tableName} WHERE "scorerDefinitionId" = $1 ORDER BY "${field}" ${direction} LIMIT $2 OFFSET $3`,
12210
12181
  [scorerDefinitionId, limitValue, offset]
12211
12182
  );
12212
- const versions = (dataResult || []).map((row) => this.parseVersionRow(row));
12183
+ const versions = (dataResult || []).flatMap((row) => {
12184
+ try {
12185
+ return [this.parseVersionRow(row)];
12186
+ } catch (err) {
12187
+ this.logger?.warn?.("[PG] Failed to map scorer definition version row, skipping", {
12188
+ id: row?.id,
12189
+ error: err
12190
+ });
12191
+ return [];
12192
+ }
12193
+ });
12213
12194
  return {
12214
12195
  versions,
12215
12196
  total,
@@ -12297,38 +12278,13 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends storage.ScorerDefin
12297
12278
  // ==========================================================================
12298
12279
  // Private Helper Methods
12299
12280
  // ==========================================================================
12300
- parseJson(value, fieldName) {
12301
- if (!value) return void 0;
12302
- if (typeof value !== "string") return value;
12303
- try {
12304
- return JSON.parse(value);
12305
- } catch (error$1) {
12306
- if (error$1 instanceof error.MastraError) throw error$1;
12307
- const details = {
12308
- value: value.length > 100 ? value.substring(0, 100) + "..." : value
12309
- };
12310
- if (fieldName) {
12311
- details.field = fieldName;
12312
- }
12313
- throw new error.MastraError(
12314
- {
12315
- id: storage.createStorageErrorId("PG", "PARSE_JSON", "INVALID_JSON"),
12316
- domain: error.ErrorDomain.STORAGE,
12317
- category: error.ErrorCategory.SYSTEM,
12318
- text: `Failed to parse JSON${fieldName ? ` for field "${fieldName}"` : ""}: ${error$1 instanceof Error ? error$1.message : "Unknown error"}`,
12319
- details
12320
- },
12321
- error$1
12322
- );
12323
- }
12324
- }
12325
12281
  parseScorerRow(row) {
12326
12282
  return {
12327
12283
  id: row.id,
12328
12284
  status: row.status,
12329
12285
  activeVersionId: row.activeVersionId,
12330
12286
  authorId: row.authorId,
12331
- metadata: this.parseJson(row.metadata, "metadata"),
12287
+ metadata: parseJsonResilient(row.metadata),
12332
12288
  createdAt: new Date(row.createdAtZ || row.createdAt),
12333
12289
  updatedAt: new Date(row.updatedAtZ || row.updatedAt)
12334
12290
  };
@@ -12341,12 +12297,12 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends storage.ScorerDefin
12341
12297
  name: row.name,
12342
12298
  description: row.description,
12343
12299
  type: row.type,
12344
- model: this.parseJson(row.model, "model"),
12300
+ model: parseJsonResilient(row.model),
12345
12301
  instructions: row.instructions,
12346
- scoreRange: this.parseJson(row.scoreRange, "scoreRange"),
12347
- presetConfig: this.parseJson(row.presetConfig, "presetConfig"),
12348
- defaultSampling: this.parseJson(row.defaultSampling, "defaultSampling"),
12349
- changedFields: this.parseJson(row.changedFields, "changedFields"),
12302
+ scoreRange: parseJsonResilient(row.scoreRange),
12303
+ presetConfig: parseJsonResilient(row.presetConfig),
12304
+ defaultSampling: parseJsonResilient(row.defaultSampling),
12305
+ changedFields: parseJsonResilient(row.changedFields),
12350
12306
  changeMessage: row.changeMessage,
12351
12307
  createdAt: new Date(row.createdAtZ || row.createdAt)
12352
12308
  };
@@ -13088,7 +13044,14 @@ var SkillsPG = class _SkillsPG extends storage.SkillsStorage {
13088
13044
  `SELECT * FROM ${tableName} ${whereClause} ORDER BY "${field}" ${direction} LIMIT $${paramIdx++} OFFSET $${paramIdx++}`,
13089
13045
  [...queryParams, limitValue, offset]
13090
13046
  );
13091
- const skills = (dataResult || []).map((row) => this.parseSkillRow(row));
13047
+ const skills = (dataResult || []).flatMap((row) => {
13048
+ try {
13049
+ return [this.parseSkillRow(row)];
13050
+ } catch (err) {
13051
+ this.logger?.warn?.("[PG] Failed to map skill row, skipping", { id: row?.id, error: err });
13052
+ return [];
13053
+ }
13054
+ });
13092
13055
  return {
13093
13056
  skills,
13094
13057
  total,
@@ -13282,7 +13245,14 @@ var SkillsPG = class _SkillsPG extends storage.SkillsStorage {
13282
13245
  `SELECT * FROM ${tableName} WHERE "skillId" = $1 ORDER BY "${field}" ${direction} LIMIT $2 OFFSET $3`,
13283
13246
  [skillId, limitValue, offset]
13284
13247
  );
13285
- const versions = (dataResult || []).map((row) => this.parseVersionRow(row));
13248
+ const versions = (dataResult || []).flatMap((row) => {
13249
+ try {
13250
+ return [this.parseVersionRow(row)];
13251
+ } catch (err) {
13252
+ this.logger?.warn?.("[PG] Failed to map skill version row, skipping", { id: row?.id, error: err });
13253
+ return [];
13254
+ }
13255
+ });
13286
13256
  return {
13287
13257
  versions,
13288
13258
  total,
@@ -13369,31 +13339,6 @@ var SkillsPG = class _SkillsPG extends storage.SkillsStorage {
13369
13339
  // ==========================================================================
13370
13340
  // Private Helper Methods
13371
13341
  // ==========================================================================
13372
- parseJson(value, fieldName) {
13373
- if (!value) return void 0;
13374
- if (typeof value !== "string") return value;
13375
- try {
13376
- return JSON.parse(value);
13377
- } catch (error$1) {
13378
- if (error$1 instanceof error.MastraError) throw error$1;
13379
- const details = {
13380
- value: value.length > 100 ? value.substring(0, 100) + "..." : value
13381
- };
13382
- if (fieldName) {
13383
- details.field = fieldName;
13384
- }
13385
- throw new error.MastraError(
13386
- {
13387
- id: storage.createStorageErrorId("PG", "PARSE_JSON", "INVALID_JSON"),
13388
- domain: error.ErrorDomain.STORAGE,
13389
- category: error.ErrorCategory.SYSTEM,
13390
- text: `Failed to parse JSON${fieldName ? ` for field "${fieldName}"` : ""}: ${error$1 instanceof Error ? error$1.message : "Unknown error"}`,
13391
- details
13392
- },
13393
- error$1
13394
- );
13395
- }
13396
- }
13397
13342
  parseSkillRow(row) {
13398
13343
  return {
13399
13344
  id: row.id,
@@ -13413,14 +13358,14 @@ var SkillsPG = class _SkillsPG extends storage.SkillsStorage {
13413
13358
  description: row.description,
13414
13359
  instructions: row.instructions,
13415
13360
  license: row.license,
13416
- compatibility: this.parseJson(row.compatibility, "compatibility"),
13417
- source: this.parseJson(row.source, "source"),
13418
- references: this.parseJson(row.references, "references"),
13419
- scripts: this.parseJson(row.scripts, "scripts"),
13420
- assets: this.parseJson(row.assets, "assets"),
13421
- metadata: this.parseJson(row.metadata, "metadata"),
13422
- tree: this.parseJson(row.tree, "tree"),
13423
- changedFields: this.parseJson(row.changedFields, "changedFields"),
13361
+ compatibility: parseJsonResilient(row.compatibility),
13362
+ source: parseJsonResilient(row.source),
13363
+ references: parseJsonResilient(row.references),
13364
+ scripts: parseJsonResilient(row.scripts),
13365
+ assets: parseJsonResilient(row.assets),
13366
+ metadata: parseJsonResilient(row.metadata),
13367
+ tree: parseJsonResilient(row.tree),
13368
+ changedFields: parseJsonResilient(row.changedFields),
13424
13369
  changeMessage: row.changeMessage,
13425
13370
  createdAt: new Date(row.createdAtZ || row.createdAt)
13426
13371
  };
@@ -14186,7 +14131,14 @@ var WorkspacesPG = class _WorkspacesPG extends storage.WorkspacesStorage {
14186
14131
  `SELECT * FROM ${tableName} ${whereClause} ORDER BY "${field}" ${direction} LIMIT $${paramIdx++} OFFSET $${paramIdx++}`,
14187
14132
  [...queryParams, limitValue, offset]
14188
14133
  );
14189
- const workspaces = (dataResult || []).map((row) => this.parseWorkspaceRow(row));
14134
+ const workspaces = (dataResult || []).flatMap((row) => {
14135
+ try {
14136
+ return [this.parseWorkspaceRow(row)];
14137
+ } catch (err) {
14138
+ this.logger?.warn?.("[PG] Failed to map workspace row, skipping", { id: row?.id, error: err });
14139
+ return [];
14140
+ }
14141
+ });
14190
14142
  return {
14191
14143
  workspaces,
14192
14144
  total,
@@ -14380,7 +14332,14 @@ var WorkspacesPG = class _WorkspacesPG extends storage.WorkspacesStorage {
14380
14332
  `SELECT * FROM ${tableName} WHERE "workspaceId" = $1 ORDER BY "${field}" ${direction} LIMIT $2 OFFSET $3`,
14381
14333
  [workspaceId, limitValue, offset]
14382
14334
  );
14383
- const versions = (dataResult || []).map((row) => this.parseVersionRow(row));
14335
+ const versions = (dataResult || []).flatMap((row) => {
14336
+ try {
14337
+ return [this.parseVersionRow(row)];
14338
+ } catch (err) {
14339
+ this.logger?.warn?.("[PG] Failed to map workspace version row, skipping", { id: row?.id, error: err });
14340
+ return [];
14341
+ }
14342
+ });
14384
14343
  return {
14385
14344
  versions,
14386
14345
  total,
@@ -14467,38 +14426,13 @@ var WorkspacesPG = class _WorkspacesPG extends storage.WorkspacesStorage {
14467
14426
  // ==========================================================================
14468
14427
  // Private Helper Methods
14469
14428
  // ==========================================================================
14470
- parseJson(value, fieldName) {
14471
- if (!value) return void 0;
14472
- if (typeof value !== "string") return value;
14473
- try {
14474
- return JSON.parse(value);
14475
- } catch (error$1) {
14476
- if (error$1 instanceof error.MastraError) throw error$1;
14477
- const details = {
14478
- value: value.length > 100 ? value.substring(0, 100) + "..." : value
14479
- };
14480
- if (fieldName) {
14481
- details.field = fieldName;
14482
- }
14483
- throw new error.MastraError(
14484
- {
14485
- id: storage.createStorageErrorId("PG", "PARSE_JSON", "INVALID_JSON"),
14486
- domain: error.ErrorDomain.STORAGE,
14487
- category: error.ErrorCategory.SYSTEM,
14488
- text: `Failed to parse JSON${fieldName ? ` for field "${fieldName}"` : ""}: ${error$1 instanceof Error ? error$1.message : "Unknown error"}`,
14489
- details
14490
- },
14491
- error$1
14492
- );
14493
- }
14494
- }
14495
14429
  parseWorkspaceRow(row) {
14496
14430
  return {
14497
14431
  id: row.id,
14498
14432
  status: row.status,
14499
14433
  activeVersionId: row.activeVersionId,
14500
14434
  authorId: row.authorId,
14501
- metadata: this.parseJson(row.metadata, "metadata"),
14435
+ metadata: parseJsonResilient(row.metadata),
14502
14436
  createdAt: new Date(row.createdAtZ || row.createdAt),
14503
14437
  updatedAt: new Date(row.updatedAtZ || row.updatedAt)
14504
14438
  };
@@ -14510,15 +14444,15 @@ var WorkspacesPG = class _WorkspacesPG extends storage.WorkspacesStorage {
14510
14444
  versionNumber: row.versionNumber,
14511
14445
  name: row.name,
14512
14446
  description: row.description,
14513
- filesystem: this.parseJson(row.filesystem, "filesystem"),
14514
- sandbox: this.parseJson(row.sandbox, "sandbox"),
14515
- mounts: this.parseJson(row.mounts, "mounts"),
14516
- search: this.parseJson(row.search, "search"),
14517
- skills: this.parseJson(row.skills, "skills"),
14518
- tools: this.parseJson(row.tools, "tools"),
14447
+ filesystem: parseJsonResilient(row.filesystem),
14448
+ sandbox: parseJsonResilient(row.sandbox),
14449
+ mounts: parseJsonResilient(row.mounts),
14450
+ search: parseJsonResilient(row.search),
14451
+ skills: parseJsonResilient(row.skills),
14452
+ tools: parseJsonResilient(row.tools),
14519
14453
  autoSync: Boolean(row.autoSync),
14520
14454
  operationTimeout: row.operationTimeout != null ? Number(row.operationTimeout) : void 0,
14521
- changedFields: this.parseJson(row.changedFields, "changedFields"),
14455
+ changedFields: parseJsonResilient(row.changedFields),
14522
14456
  changeMessage: row.changeMessage,
14523
14457
  createdAt: new Date(row.createdAtZ || row.createdAt)
14524
14458
  };