@mastra/pg 1.22.3-alpha.3 → 1.22.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.
@@ -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.22.3-alpha.3"
6
+ version: "1.22.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.22.3-alpha.3",
2
+ "version": "1.22.3",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -39,6 +39,12 @@ Polls storage for due cron schedules and publishes `workflow.start` events. It's
39
39
 
40
40
  The scheduler reads declarative `schedule` fields from your workflow definitions automatically. See [Scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows) for how to declare schedules.
41
41
 
42
+ The scheduler only polls storage once a schedule exists. At boot, a process with no declared schedules runs a single `listSchedules()` check. If that check finds no rows, the poll loop never starts, so idle deployments issue no recurring scheduler queries and can scale to zero.
43
+
44
+ When a schedule is created at runtime, Mastra publishes a wake event on the PubSub backend. Any process running the default worker set starts its scheduler in response, which is how a standalone worker discovers schedules created by the API process. This requires both processes to share the same PubSub backend.
45
+
46
+ To poll from startup regardless of whether schedules exist (for example, when your processes don't share a PubSub backend), set `scheduler: { enabled: true }` on the worker or run it with `MASTRA_WORKERS=scheduler`.
47
+
42
48
  **Don't run more than one scheduler instance.** Multiple schedulers polling the same storage would fire duplicate events for the same schedule.
43
49
 
44
50
  ### Background task worker
package/dist/index.cjs CHANGED
@@ -14073,6 +14073,11 @@ const FEEDBACK_EVENT_COLUMNS = [
14073
14073
  type: "text",
14074
14074
  nullable: true
14075
14075
  },
14076
+ {
14077
+ name: "reviewStatus",
14078
+ type: "text",
14079
+ defaultSql: "'needs-review'"
14080
+ },
14076
14081
  ...COMMON_CONTEXT_COLUMNS,
14077
14082
  {
14078
14083
  name: "tags",
@@ -14513,6 +14518,10 @@ function additiveColumns(schema) {
14513
14518
  table: TABLE_SPAN_EVENTS,
14514
14519
  column: "isPending",
14515
14520
  ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "isPending" boolean NOT NULL DEFAULT false`
14521
+ }, {
14522
+ table: TABLE_FEEDBACK_EVENTS,
14523
+ column: "reviewStatus",
14524
+ ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_FEEDBACK_EVENTS)} ADD COLUMN IF NOT EXISTS "reviewStatus" text NOT NULL DEFAULT 'needs-review'`
14516
14525
  }];
14517
14526
  }
14518
14527
  /** Existence probe for an additive column. Params: schema, table, column. */
@@ -14835,6 +14844,31 @@ function whereOrEmpty(acc) {
14835
14844
  return acc.conditions.length ? `WHERE ${acc.conditions.join(" AND ")}` : "";
14836
14845
  }
14837
14846
  //#endregion
14847
+ //#region src/storage/domains/observability/v-next/review-status.ts
14848
+ const FEEDBACK_REVIEW_STATUSES = ["needs-review", "reviewed"];
14849
+ function isFeedbackReviewStatus(value) {
14850
+ return FEEDBACK_REVIEW_STATUSES.some((status) => status === value);
14851
+ }
14852
+ /** Normalize a stored value to a review status, defaulting legacy/unknown values to `needs-review`. */
14853
+ function coerceFeedbackReviewStatus(value) {
14854
+ return isFeedbackReviewStatus(value) ? value : "needs-review";
14855
+ }
14856
+ function parseUpdateFeedbackReviewStatusArgs(args) {
14857
+ const invalid = (text) => new _mastra_core_error.MastraError({
14858
+ id: "OBSERVABILITY_UPDATE_FEEDBACK_REVIEW_STATUS_INVALID_ARGS",
14859
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
14860
+ category: _mastra_core_error.ErrorCategory.USER,
14861
+ text
14862
+ });
14863
+ if (typeof args !== "object" || args === null) throw invalid("args must be an object");
14864
+ if (typeof args.feedbackId !== "string" || args.feedbackId.length === 0) throw invalid("feedbackId is required");
14865
+ if (!isFeedbackReviewStatus(args.reviewStatus)) throw invalid(`reviewStatus must be one of: ${FEEDBACK_REVIEW_STATUSES.join(", ")}`);
14866
+ return {
14867
+ feedbackId: args.feedbackId,
14868
+ reviewStatus: args.reviewStatus
14869
+ };
14870
+ }
14871
+ //#endregion
14838
14872
  //#region src/storage/domains/observability/v-next/helpers.ts
14839
14873
  const PROMOTED_KEYS = /* @__PURE__ */ new Set([
14840
14874
  "experimentId",
@@ -15199,6 +15233,7 @@ function feedbackRecordToRow(feedback) {
15199
15233
  spanId: feedback.spanId ?? null,
15200
15234
  feedbackUserId: feedback.feedbackUserId ?? null,
15201
15235
  sourceId: feedback.sourceId ?? null,
15236
+ reviewStatus: feedback.reviewStatus ?? "needs-review",
15202
15237
  feedbackSource,
15203
15238
  feedbackType: feedback.feedbackType,
15204
15239
  valueString: typeof feedback.value === "string" ? feedback.value : null,
@@ -15220,6 +15255,7 @@ function rowToFeedbackRecord(row) {
15220
15255
  spanId: nullableString(row.spanId),
15221
15256
  feedbackUserId: nullableString(row.feedbackUserId),
15222
15257
  sourceId: nullableString(row.sourceId),
15258
+ reviewStatus: coerceFeedbackReviewStatus(row.reviewStatus),
15223
15259
  feedbackSource,
15224
15260
  feedbackType: row.feedbackType,
15225
15261
  value: hasNumber ? Number(row.valueNumber) : nullableString(row.valueString) ?? "",
@@ -15739,6 +15775,10 @@ function applyFeedbackFilters(acc, filters) {
15739
15775
  acc.conditions.push(`"feedbackUserId" = $${acc.next++}`);
15740
15776
  acc.params.push(filters.feedbackUserId);
15741
15777
  }
15778
+ if (filters?.reviewStatus) {
15779
+ acc.conditions.push(`"reviewStatus" = $${acc.next++}`);
15780
+ acc.params.push(filters.reviewStatus);
15781
+ }
15742
15782
  }
15743
15783
  /**
15744
15784
  * OLAP queries take an explicit feedbackType / feedbackSource pair as
@@ -15762,6 +15802,21 @@ async function batchCreateFeedback(client, schema, args) {
15762
15802
  const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, args.feedbacks.map(feedbackRecordToRow));
15763
15803
  if (insert) await client.query(insert.text, insert.values);
15764
15804
  }
15805
+ async function updateFeedbackReviewStatus(client, schema, args) {
15806
+ const { feedbackId, reviewStatus } = parseUpdateFeedbackReviewStatusArgs(args);
15807
+ const row = await client.oneOrNone(`UPDATE ${qualifiedTable(schema, TABLE_FEEDBACK_EVENTS)}
15808
+ SET "reviewStatus" = $2
15809
+ WHERE "feedbackId" = $1
15810
+ RETURNING ${FEEDBACK_SELECT_COLUMNS}`, [feedbackId, reviewStatus]);
15811
+ if (!row) throw new _mastra_core_error.MastraError({
15812
+ id: "OBSERVABILITY_UPDATE_FEEDBACK_REVIEW_STATUS_NOT_FOUND",
15813
+ domain: _mastra_core_error.ErrorDomain.MASTRA_OBSERVABILITY,
15814
+ category: _mastra_core_error.ErrorCategory.USER,
15815
+ text: "Feedback record not found",
15816
+ details: { feedbackId }
15817
+ });
15818
+ return rowToFeedbackRecord(row);
15819
+ }
15765
15820
  async function listFeedback(client, schema, args) {
15766
15821
  const { mode, filters, pagination, orderBy, after, limit } = _mastra_core_storage.listFeedbackArgsSchema.parse(args);
15767
15822
  const table = qualifiedTable(schema, TABLE_FEEDBACK_EVENTS);
@@ -17625,6 +17680,9 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
17625
17680
  async listFeedback(args) {
17626
17681
  return this.#run("LIST_FEEDBACK", () => listFeedback(this.#client, this.#schema, args));
17627
17682
  }
17683
+ async updateFeedbackReviewStatus(args) {
17684
+ return this.#run("UPDATE_FEEDBACK_REVIEW_STATUS", () => updateFeedbackReviewStatus(this.#client, this.#schema, args), { feedbackId: args.feedbackId });
17685
+ }
17628
17686
  async getMetricAggregate(args) {
17629
17687
  return this.#run("GET_METRIC_AGGREGATE", () => getMetricAggregate(this.#client, this.#schema, args));
17630
17688
  }