@mastra/pg 1.8.4-alpha.1 → 1.8.4-alpha.3

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,30 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.8.4-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Added `scorerIds` persistence for datasets. The `scorerIds` field is now stored and retrieved correctly when creating or updating datasets. ([#14783](https://github.com/mastra-ai/mastra/pull/14783))
8
+
9
+ - Updated dependencies [[`fbf22a7`](https://github.com/mastra-ai/mastra/commit/fbf22a7ad86bcb50dcf30459f0d075e51ddeb468), [`04160ee`](https://github.com/mastra-ai/mastra/commit/04160eedf3130003cf842ad08428c8ff69af4cc1), [`2c27503`](https://github.com/mastra-ai/mastra/commit/2c275032510d131d2cde47f99953abf0fe02c081), [`424a1df`](https://github.com/mastra-ai/mastra/commit/424a1df7bee59abb5c83717a54807fdd674a6224), [`12c88a6`](https://github.com/mastra-ai/mastra/commit/12c88a6e32bf982c2fe0c6af62e65a3414519a75), [`43595bf`](https://github.com/mastra-ai/mastra/commit/43595bf7b8df1a6edce7a23b445b5124d2a0b473), [`78670e9`](https://github.com/mastra-ai/mastra/commit/78670e97e76d7422cf7025faf371b2aeafed860d), [`d400e7c`](https://github.com/mastra-ai/mastra/commit/d400e7c8b8d7afa6ba2c71769eace4048e3cef8e), [`f58d1a7`](https://github.com/mastra-ai/mastra/commit/f58d1a7a457588a996c3ecb53201a68f3d28c432), [`a49a929`](https://github.com/mastra-ai/mastra/commit/a49a92904968b4fc67e01effee8c7c8d0464ba85)]:
10
+ - @mastra/core@1.18.0-alpha.4
11
+
12
+ ## 1.8.4-alpha.2
13
+
14
+ ### Patch Changes
15
+
16
+ - Add `getReviewSummary()` to experiments storage for aggregating review status counts ([#14649](https://github.com/mastra-ai/mastra/pull/14649))
17
+
18
+ Query experiment results grouped by experiment ID, returning counts of `needs-review`, `reviewed`, and `complete` items in a single query instead of fetching all results client-side.
19
+
20
+ ```ts
21
+ const summary = await storage.experiments.getReviewSummary();
22
+ // [{ experimentId: 'exp-1', needsReview: 3, reviewed: 5, complete: 2, total: 10 }, ...]
23
+ ```
24
+
25
+ - Updated dependencies [[`dc9fc19`](https://github.com/mastra-ai/mastra/commit/dc9fc19da4437f6b508cc355f346a8856746a76b), [`260fe12`](https://github.com/mastra-ai/mastra/commit/260fe1295fe7354e39d6def2775e0797a7a277f0)]:
26
+ - @mastra/core@1.18.0-alpha.1
27
+
3
28
  ## 1.8.4-alpha.1
4
29
 
5
30
  ### 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.4-alpha.1"
6
+ version: "1.8.4-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.4-alpha.1",
2
+ "version": "1.8.4-alpha.3",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -4355,6 +4355,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4355
4355
  await this.#addColumnIfNotExists(storage.TABLE_DATASETS, "tags", "JSONB");
4356
4356
  await this.#addColumnIfNotExists(storage.TABLE_DATASETS, "targetType", "TEXT");
4357
4357
  await this.#addColumnIfNotExists(storage.TABLE_DATASETS, "targetIds", "JSONB");
4358
+ await this.#addColumnIfNotExists(storage.TABLE_DATASETS, "scorerIds", "JSONB");
4358
4359
  await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "requestContext", "JSONB");
4359
4360
  await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "source", "JSONB");
4360
4361
  await this.createDefaultIndexes();
@@ -4426,6 +4427,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4426
4427
  tags: row.tags ? storage.safelyParseJSON(row.tags) : void 0,
4427
4428
  targetType: row.targetType || null,
4428
4429
  targetIds: row.targetIds || null,
4430
+ scorerIds: row.scorerIds || null,
4429
4431
  version: row.version,
4430
4432
  createdAt: storage.ensureDate(row.createdAtZ || row.createdAt),
4431
4433
  updatedAt: storage.ensureDate(row.updatedAtZ || row.updatedAt)
@@ -4487,6 +4489,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4487
4489
  requestContextSchema: input.requestContextSchema ?? null,
4488
4490
  targetType: input.targetType ?? null,
4489
4491
  targetIds: input.targetIds !== void 0 ? JSON.stringify(input.targetIds) : null,
4492
+ scorerIds: input.scorerIds ? JSON.stringify(input.scorerIds) : null,
4490
4493
  version: 0,
4491
4494
  createdAt: nowIso,
4492
4495
  updatedAt: nowIso
@@ -4502,6 +4505,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4502
4505
  requestContextSchema: input.requestContextSchema ?? void 0,
4503
4506
  targetType: input.targetType ?? null,
4504
4507
  targetIds: input.targetIds ?? null,
4508
+ scorerIds: input.scorerIds ?? null,
4505
4509
  version: 0,
4506
4510
  createdAt: now,
4507
4511
  updatedAt: now
@@ -4585,6 +4589,10 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4585
4589
  setClauses.push(`"targetIds" = $${paramIndex++}`);
4586
4590
  values.push(args.targetIds === null ? null : JSON.stringify(args.targetIds));
4587
4591
  }
4592
+ if (args.scorerIds !== void 0) {
4593
+ setClauses.push(`"scorerIds" = $${paramIndex++}`);
4594
+ values.push(args.scorerIds === null ? null : JSON.stringify(args.scorerIds));
4595
+ }
4588
4596
  values.push(args.id);
4589
4597
  await this.#db.client.none(
4590
4598
  `UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE "id" = $${paramIndex}`,
@@ -4601,6 +4609,7 @@ var DatasetsPG = class _DatasetsPG extends storage.DatasetsStorage {
4601
4609
  tags: (args.tags !== void 0 ? args.tags : existing.tags) ?? void 0,
4602
4610
  targetType: (args.targetType !== void 0 ? args.targetType : existing.targetType) ?? null,
4603
4611
  targetIds: (args.targetIds !== void 0 ? args.targetIds : existing.targetIds) ?? null,
4612
+ scorerIds: (args.scorerIds !== void 0 ? args.scorerIds : existing.scorerIds) ?? null,
4604
4613
  updatedAt: new Date(now)
4605
4614
  };
4606
4615
  } catch (error$1) {
@@ -5764,6 +5773,38 @@ var ExperimentsPG = class _ExperimentsPG extends storage.ExperimentsStorage {
5764
5773
  );
5765
5774
  }
5766
5775
  }
5776
+ // --- Aggregation ---
5777
+ async getReviewSummary() {
5778
+ try {
5779
+ const tableName = getTableName2({ indexName: storage.TABLE_EXPERIMENT_RESULTS, schemaName: getSchemaName2(this.#schema) });
5780
+ const rows = await this.#db.client.manyOrNone(
5781
+ `SELECT
5782
+ "experimentId",
5783
+ COUNT(*)::int as total,
5784
+ SUM(CASE WHEN status = 'needs-review' THEN 1 ELSE 0 END)::int as "needsReview",
5785
+ SUM(CASE WHEN status = 'reviewed' THEN 1 ELSE 0 END)::int as reviewed,
5786
+ SUM(CASE WHEN status = 'complete' THEN 1 ELSE 0 END)::int as complete
5787
+ FROM ${tableName}
5788
+ GROUP BY "experimentId"`
5789
+ );
5790
+ return (rows || []).map((row) => ({
5791
+ experimentId: row.experimentId,
5792
+ total: Number(row.total ?? 0),
5793
+ needsReview: Number(row.needsReview ?? 0),
5794
+ reviewed: Number(row.reviewed ?? 0),
5795
+ complete: Number(row.complete ?? 0)
5796
+ }));
5797
+ } catch (error$1) {
5798
+ throw new error.MastraError(
5799
+ {
5800
+ id: storage.createStorageErrorId("PG", "GET_REVIEW_SUMMARY", "FAILED"),
5801
+ domain: error.ErrorDomain.STORAGE,
5802
+ category: error.ErrorCategory.THIRD_PARTY
5803
+ },
5804
+ error$1
5805
+ );
5806
+ }
5807
+ }
5767
5808
  // --- Clear ---
5768
5809
  async dangerouslyClearAll() {
5769
5810
  await this.#db.clearTable({ tableName: storage.TABLE_EXPERIMENT_RESULTS });
@@ -12388,7 +12429,7 @@ function getTableName5({ indexName, schemaName }) {
12388
12429
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
12389
12430
  }
12390
12431
  function sanitizeJsonForPg(jsonString) {
12391
- return jsonString.replace(/\\u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})/g, "");
12432
+ return jsonString.replace(/(^|[^\\])(\\(?!["\\/bfnrtu]))/g, "$1\\\\").replace(/\\u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})/g, "");
12392
12433
  }
12393
12434
  var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
12394
12435
  #db;