@mastra/pg 1.8.2 → 1.8.3-alpha.0

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,18 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.8.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Added storage support for dataset targeting and experiment status fields. ([#14470](https://github.com/mastra-ai/mastra/pull/14470))
8
+ - Added `targetType` (text) and `targetIds` (jsonb) columns to datasets table for entity association
9
+ - Added `tags` (jsonb) column to datasets table for tag vocabulary
10
+ - Added `status` column to experiment results for review workflow tracking
11
+ - Added migration logic to add new columns to existing tables
12
+
13
+ - Updated dependencies [[`68ed4e9`](https://github.com/mastra-ai/mastra/commit/68ed4e9f118e8646b60a6112dabe854d0ef53902), [`085c1da`](https://github.com/mastra-ai/mastra/commit/085c1daf71b55a97b8ebad26623089e40055021c), [`4a75e10`](https://github.com/mastra-ai/mastra/commit/4a75e106bd31c283a1b3fe74c923610dcc46415b), [`085c1da`](https://github.com/mastra-ai/mastra/commit/085c1daf71b55a97b8ebad26623089e40055021c)]:
14
+ - @mastra/core@1.16.0-alpha.0
15
+
3
16
  ## 1.8.2
4
17
 
5
18
  ### 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.8.2"
6
+ version: "1.8.3-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.2",
2
+ "version": "1.8.3-alpha.0",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -4352,7 +4352,11 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4352
4352
  });
4353
4353
  await this.#db.createTable({ tableName: storage.TABLE_DATASET_VERSIONS, schema: storage.DATASET_VERSIONS_SCHEMA });
4354
4354
  await this.#addColumnIfNotExists(storage.TABLE_DATASETS, "requestContextSchema", "JSONB");
4355
+ await this.#addColumnIfNotExists(storage.TABLE_DATASETS, "tags", "JSONB");
4356
+ await this.#addColumnIfNotExists(storage.TABLE_DATASETS, "targetType", "TEXT");
4357
+ await this.#addColumnIfNotExists(storage.TABLE_DATASETS, "targetIds", "JSONB");
4355
4358
  await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "requestContext", "JSONB");
4359
+ await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "source", "JSONB");
4356
4360
  await this.createDefaultIndexes();
4357
4361
  await this.createCustomIndexes();
4358
4362
  }
@@ -4419,6 +4423,9 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4419
4423
  inputSchema: row.inputSchema ? storage.safelyParseJSON(row.inputSchema) : void 0,
4420
4424
  groundTruthSchema: row.groundTruthSchema ? storage.safelyParseJSON(row.groundTruthSchema) : void 0,
4421
4425
  requestContextSchema: row.requestContextSchema ? storage.safelyParseJSON(row.requestContextSchema) : void 0,
4426
+ tags: row.tags ? storage.safelyParseJSON(row.tags) : void 0,
4427
+ targetType: row.targetType || null,
4428
+ targetIds: row.targetIds || null,
4422
4429
  version: row.version,
4423
4430
  createdAt: storage.ensureDate(row.createdAtZ || row.createdAt),
4424
4431
  updatedAt: storage.ensureDate(row.updatedAtZ || row.updatedAt)
@@ -4433,6 +4440,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4433
4440
  groundTruth: row.groundTruth ? storage.safelyParseJSON(row.groundTruth) : void 0,
4434
4441
  requestContext: row.requestContext ? storage.safelyParseJSON(row.requestContext) : void 0,
4435
4442
  metadata: row.metadata ? storage.safelyParseJSON(row.metadata) : void 0,
4443
+ source: row.source ? storage.safelyParseJSON(row.source) : void 0,
4436
4444
  createdAt: storage.ensureDate(row.createdAtZ || row.createdAt),
4437
4445
  updatedAt: storage.ensureDate(row.updatedAtZ || row.updatedAt)
4438
4446
  };
@@ -4448,6 +4456,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4448
4456
  groundTruth: row.groundTruth ? storage.safelyParseJSON(row.groundTruth) : void 0,
4449
4457
  requestContext: row.requestContext ? storage.safelyParseJSON(row.requestContext) : void 0,
4450
4458
  metadata: row.metadata ? storage.safelyParseJSON(row.metadata) : void 0,
4459
+ source: row.source ? storage.safelyParseJSON(row.source) : void 0,
4451
4460
  createdAt: storage.ensureDate(row.createdAtZ || row.createdAt),
4452
4461
  updatedAt: storage.ensureDate(row.updatedAtZ || row.updatedAt)
4453
4462
  };
@@ -4476,6 +4485,8 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4476
4485
  inputSchema: input.inputSchema ?? null,
4477
4486
  groundTruthSchema: input.groundTruthSchema ?? null,
4478
4487
  requestContextSchema: input.requestContextSchema ?? null,
4488
+ targetType: input.targetType ?? null,
4489
+ targetIds: input.targetIds !== void 0 ? JSON.stringify(input.targetIds) : null,
4479
4490
  version: 0,
4480
4491
  createdAt: nowIso,
4481
4492
  updatedAt: nowIso
@@ -4489,6 +4500,8 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4489
4500
  inputSchema: input.inputSchema ?? void 0,
4490
4501
  groundTruthSchema: input.groundTruthSchema ?? void 0,
4491
4502
  requestContextSchema: input.requestContextSchema ?? void 0,
4503
+ targetType: input.targetType ?? null,
4504
+ targetIds: input.targetIds ?? null,
4492
4505
  version: 0,
4493
4506
  createdAt: now,
4494
4507
  updatedAt: now
@@ -4560,6 +4573,18 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4560
4573
  setClauses.push(`"requestContextSchema" = $${paramIndex++}`);
4561
4574
  values.push(args.requestContextSchema === null ? null : JSON.stringify(args.requestContextSchema));
4562
4575
  }
4576
+ if (args.tags !== void 0) {
4577
+ setClauses.push(`"tags" = $${paramIndex++}`);
4578
+ values.push(args.tags === null ? null : JSON.stringify(args.tags));
4579
+ }
4580
+ if (args.targetType !== void 0) {
4581
+ setClauses.push(`"targetType" = $${paramIndex++}`);
4582
+ values.push(args.targetType);
4583
+ }
4584
+ if (args.targetIds !== void 0) {
4585
+ setClauses.push(`"targetIds" = $${paramIndex++}`);
4586
+ values.push(args.targetIds === null ? null : JSON.stringify(args.targetIds));
4587
+ }
4563
4588
  values.push(args.id);
4564
4589
  await this.#db.client.none(
4565
4590
  `UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE "id" = $${paramIndex}`,
@@ -4573,6 +4598,9 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4573
4598
  inputSchema: (args.inputSchema !== void 0 ? args.inputSchema : existing.inputSchema) ?? void 0,
4574
4599
  groundTruthSchema: (args.groundTruthSchema !== void 0 ? args.groundTruthSchema : existing.groundTruthSchema) ?? void 0,
4575
4600
  requestContextSchema: (args.requestContextSchema !== void 0 ? args.requestContextSchema : existing.requestContextSchema) ?? void 0,
4601
+ tags: (args.tags !== void 0 ? args.tags : existing.tags) ?? void 0,
4602
+ targetType: (args.targetType !== void 0 ? args.targetType : existing.targetType) ?? null,
4603
+ targetIds: (args.targetIds !== void 0 ? args.targetIds : existing.targetIds) ?? null,
4576
4604
  updatedAt: new Date(now)
4577
4605
  };
4578
4606
  } catch (error$1) {
@@ -4688,7 +4716,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4688
4716
  );
4689
4717
  newVersion = row.version;
4690
4718
  await t.none(
4691
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11)`,
4719
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11,$12)`,
4692
4720
  [
4693
4721
  id,
4694
4722
  args.datasetId,
@@ -4697,6 +4725,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4697
4725
  jsonbArg(args.groundTruth),
4698
4726
  jsonbArg(args.requestContext),
4699
4727
  jsonbArg(args.metadata),
4728
+ jsonbArg(args.source),
4700
4729
  nowIso,
4701
4730
  nowIso,
4702
4731
  nowIso,
@@ -4716,6 +4745,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4716
4745
  groundTruth: args.groundTruth,
4717
4746
  requestContext: args.requestContext,
4718
4747
  metadata: args.metadata,
4748
+ source: args.source,
4719
4749
  createdAt: now,
4720
4750
  updatedAt: now
4721
4751
  };
@@ -4763,6 +4793,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4763
4793
  const mergedGroundTruth = args.groundTruth ?? existing.groundTruth;
4764
4794
  const mergedRequestContext = args.requestContext ?? existing.requestContext;
4765
4795
  const mergedMetadata = args.metadata ?? existing.metadata;
4796
+ const mergedSource = args.source ?? existing.source;
4766
4797
  let newVersion;
4767
4798
  await this.#db.client.tx(async (t) => {
4768
4799
  const row = await t.one(
@@ -4775,7 +4806,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4775
4806
  [newVersion, args.id]
4776
4807
  );
4777
4808
  await t.none(
4778
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11)`,
4809
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11,$12)`,
4779
4810
  [
4780
4811
  args.id,
4781
4812
  args.datasetId,
@@ -4784,6 +4815,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4784
4815
  jsonbArg(mergedGroundTruth),
4785
4816
  jsonbArg(mergedRequestContext),
4786
4817
  jsonbArg(mergedMetadata),
4818
+ jsonbArg(mergedSource),
4787
4819
  existing.createdAt.toISOString(),
4788
4820
  existing.createdAt.toISOString(),
4789
4821
  nowIso,
@@ -4802,6 +4834,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4802
4834
  groundTruth: mergedGroundTruth,
4803
4835
  requestContext: mergedRequestContext,
4804
4836
  metadata: mergedMetadata,
4837
+ source: mergedSource,
4805
4838
  updatedAt: now
4806
4839
  };
4807
4840
  } catch (error$1) {
@@ -4847,7 +4880,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4847
4880
  [newVersion, id]
4848
4881
  );
4849
4882
  await t.none(
4850
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,true,$4,$5,$6,$7,$8,$9,$10,$11)`,
4883
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,true,$4,$5,$6,$7,$8,$9,$10,$11,$12)`,
4851
4884
  [
4852
4885
  id,
4853
4886
  datasetId,
@@ -4856,6 +4889,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4856
4889
  jsonbArg(existing.groundTruth),
4857
4890
  jsonbArg(existing.requestContext),
4858
4891
  jsonbArg(existing.metadata),
4892
+ jsonbArg(existing.source),
4859
4893
  existing.createdAt.toISOString(),
4860
4894
  existing.createdAt.toISOString(),
4861
4895
  nowIso,
@@ -4909,7 +4943,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4909
4943
  newVersion = row.version;
4910
4944
  for (const { id, input: itemInput } of itemsWithIds) {
4911
4945
  await t.none(
4912
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11)`,
4946
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11,$12)`,
4913
4947
  [
4914
4948
  id,
4915
4949
  input.datasetId,
@@ -4918,6 +4952,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4918
4952
  jsonbArg(itemInput.groundTruth),
4919
4953
  jsonbArg(itemInput.requestContext),
4920
4954
  jsonbArg(itemInput.metadata),
4955
+ jsonbArg(itemInput.source),
4921
4956
  nowIso,
4922
4957
  nowIso,
4923
4958
  nowIso,
@@ -4938,6 +4973,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4938
4973
  groundTruth: itemInput.groundTruth,
4939
4974
  requestContext: itemInput.requestContext,
4940
4975
  metadata: itemInput.metadata,
4976
+ source: itemInput.source,
4941
4977
  createdAt: now,
4942
4978
  updatedAt: now
4943
4979
  }));
@@ -4992,7 +5028,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4992
5028
  [newVersion, item.id]
4993
5029
  );
4994
5030
  await t.none(
4995
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,true,$4,$5,$6,$7,$8,$9,$10,$11)`,
5031
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,true,$4,$5,$6,$7,$8,$9,$10,$11,$12)`,
4996
5032
  [
4997
5033
  item.id,
4998
5034
  input.datasetId,
@@ -5001,6 +5037,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
5001
5037
  jsonbArg(item.groundTruth),
5002
5038
  jsonbArg(item.requestContext),
5003
5039
  jsonbArg(item.metadata),
5040
+ jsonbArg(item.source),
5004
5041
  item.createdAt.toISOString(),
5005
5042
  item.createdAt.toISOString(),
5006
5043
  nowIso,
@@ -5321,6 +5358,8 @@ var ExperimentsPG = class _ExperimentsPG extends storage.ExperimentsStorage {
5321
5358
  completedAt: storage.ensureDate(row.completedAtZ || row.completedAt),
5322
5359
  retryCount: row.retryCount,
5323
5360
  traceId: row.traceId ?? null,
5361
+ status: row.status ?? null,
5362
+ tags: row.tags ? storage.safelyParseJSON(row.tags) : null,
5324
5363
  createdAt: storage.ensureDate(row.createdAtZ || row.createdAt)
5325
5364
  };
5326
5365
  }
@@ -5561,6 +5600,8 @@ var ExperimentsPG = class _ExperimentsPG extends storage.ExperimentsStorage {
5561
5600
  completedAt: input.completedAt.toISOString(),
5562
5601
  retryCount: input.retryCount,
5563
5602
  traceId: input.traceId ?? null,
5603
+ status: input.status ?? null,
5604
+ tags: input.tags ?? null,
5564
5605
  createdAt: nowIso
5565
5606
  }
5566
5607
  });
@@ -5577,6 +5618,8 @@ var ExperimentsPG = class _ExperimentsPG extends storage.ExperimentsStorage {
5577
5618
  completedAt: input.completedAt,
5578
5619
  retryCount: input.retryCount,
5579
5620
  traceId: input.traceId ?? null,
5621
+ status: input.status ?? null,
5622
+ tags: input.tags ?? null,
5580
5623
  createdAt: now
5581
5624
  };
5582
5625
  } catch (error$1) {
@@ -5590,6 +5633,64 @@ var ExperimentsPG = class _ExperimentsPG extends storage.ExperimentsStorage {
5590
5633
  );
5591
5634
  }
5592
5635
  }
5636
+ async updateExperimentResult(input) {
5637
+ try {
5638
+ const tableName = getTableName2({ indexName: storage.TABLE_EXPERIMENT_RESULTS, schemaName: getSchemaName2(this.#schema) });
5639
+ const setClauses = [];
5640
+ const values = [];
5641
+ let paramIndex = 1;
5642
+ if (input.status !== void 0) {
5643
+ setClauses.push(`"status" = $${paramIndex++}`);
5644
+ values.push(input.status);
5645
+ }
5646
+ if (input.tags !== void 0) {
5647
+ setClauses.push(`"tags" = $${paramIndex++}`);
5648
+ values.push(JSON.stringify(input.tags));
5649
+ }
5650
+ if (setClauses.length === 0) {
5651
+ const existing = await this.getExperimentResultById({ id: input.id });
5652
+ if (!existing) {
5653
+ throw new error.MastraError({
5654
+ id: storage.createStorageErrorId("PG", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
5655
+ domain: error.ErrorDomain.STORAGE,
5656
+ category: error.ErrorCategory.USER,
5657
+ details: { resultId: input.id }
5658
+ });
5659
+ }
5660
+ return existing;
5661
+ }
5662
+ values.push(input.id);
5663
+ let whereClause = `"id" = $${paramIndex}`;
5664
+ if (input.experimentId) {
5665
+ paramIndex++;
5666
+ values.push(input.experimentId);
5667
+ whereClause += ` AND "experimentId" = $${paramIndex}`;
5668
+ }
5669
+ const row = await this.#db.client.oneOrNone(
5670
+ `UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE ${whereClause} RETURNING *`,
5671
+ values
5672
+ );
5673
+ if (!row) {
5674
+ throw new error.MastraError({
5675
+ id: storage.createStorageErrorId("PG", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
5676
+ domain: error.ErrorDomain.STORAGE,
5677
+ category: error.ErrorCategory.USER,
5678
+ details: { resultId: input.id }
5679
+ });
5680
+ }
5681
+ return this.transformExperimentResultRow(row);
5682
+ } catch (error$1) {
5683
+ if (error$1 instanceof error.MastraError) throw error$1;
5684
+ throw new error.MastraError(
5685
+ {
5686
+ id: storage.createStorageErrorId("PG", "UPDATE_EXPERIMENT_RESULT", "FAILED"),
5687
+ domain: error.ErrorDomain.STORAGE,
5688
+ category: error.ErrorCategory.THIRD_PARTY
5689
+ },
5690
+ error$1
5691
+ );
5692
+ }
5693
+ }
5593
5694
  async getExperimentResultById({ id }) {
5594
5695
  try {
5595
5696
  const tableName = getTableName2({ indexName: storage.TABLE_EXPERIMENT_RESULTS, schemaName: getSchemaName2(this.#schema) });