@mastra/pg 1.35.0-alpha.0 → 1.35.0-alpha.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.js CHANGED
@@ -20503,6 +20503,18 @@ const PERCENTILES = {
20503
20503
  "duration.p95": .95,
20504
20504
  "duration.p99": .99
20505
20505
  };
20506
+ /** Quantile for each percentile statistic of a time-to-first measure. */
20507
+ const STATISTIC_PERCENTILES = {
20508
+ p50: .5,
20509
+ p90: .9,
20510
+ p95: .95,
20511
+ p99: .99
20512
+ };
20513
+ /**
20514
+ * Store features this compiler supports beyond `trace-aggregate` / `span-aggregate`. Core before
20515
+ * the time-to-first measures rejects them, so they are only declared when core plans them.
20516
+ */
20517
+ const aggregateTimeToFirstFeatures = "timeToFirstToken.p50" in coreStorage.TRACE_AGGREGATE_MEASURE_REGISTRY ? ["aggregate-time-to-first-measures"] : [];
20506
20518
  const COMPARISON_SQL = {
20507
20519
  eq: "=",
20508
20520
  ne: "<>",
@@ -20570,6 +20582,8 @@ function compilePostgresAggregate(schema, plan, source) {
20570
20582
  factColumns.push(`(${distinctSql(measure.field)})::text AS ${column}`);
20571
20583
  }
20572
20584
  factColumns.push(`(${durationMsSql("r.\"startedAt\"", "r.\"endedAt\"")})::float8 AS "durationMs"`, `r."error" IS NOT NULL AS "isError"`);
20585
+ const timeToFirstFields = new Set(plan.measures.map((measure) => measureRule(measure.name)?.field));
20586
+ for (const field of timeToFirstFields) if (field) factColumns.push(`r."${field}"::float8 AS "${field}"`);
20573
20587
  if (plan.interval !== void 0) {
20574
20588
  const intervalMs = coreStorage.TRACE_AGGREGATE_INTERVAL_MS[plan.interval];
20575
20589
  if (intervalMs === void 0) throw new Error(`Unsupported trusted trace-aggregate interval: ${plan.interval}`);
@@ -20601,6 +20615,15 @@ function compilePostgresAggregate(schema, plan, source) {
20601
20615
  const aggregate = rule.statistic === "avg" ? "AVG" : "SUM";
20602
20616
  return `(CASE WHEN ${mixedUnitsSql(alias)} THEN NULL ELSE ${aggregate}(${column("traceCost")}) END)::float8`;
20603
20617
  }
20618
+ if (rule?.field) {
20619
+ const value = column(rule.field);
20620
+ if (rule.statistic === "count") return `COUNT(${value})::float8`;
20621
+ if (rule.statistic === "avg") return `AVG(${value})`;
20622
+ if (rule.statistic === "min") return `MIN(${value})`;
20623
+ if (rule.statistic === "max") return `MAX(${value})`;
20624
+ const quantile = rule.statistic && STATISTIC_PERCENTILES[rule.statistic];
20625
+ if (quantile !== void 0) return `percentile_cont(${quantile}) WITHIN GROUP (ORDER BY ${value})`;
20626
+ }
20604
20627
  if (name === "errorCount") return `(COUNT(*) FILTER (WHERE ${column("isError")}))::float8`;
20605
20628
  if (name === "errorRate") return `(COUNT(*) FILTER (WHERE ${column("isError")}))::float8 / COUNT(*)`;
20606
20629
  if (name === "duration.avg") return `AVG(${column("durationMs")})`;
@@ -21755,6 +21778,7 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
21755
21778
  "metric-discovery",
21756
21779
  "trace-query",
21757
21780
  "trace-aggregate",
21781
+ ...aggregateTimeToFirstFeatures,
21758
21782
  ...spanQueryFeatures,
21759
21783
  ...spanAggregateFeatures,
21760
21784
  ...typeof coreStorage.planThreadRowsQuery === "function" ? ["thread-query-rows"] : [],
@@ -21781,6 +21805,7 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
21781
21805
  "delta-polling",
21782
21806
  "trace-query",
21783
21807
  "trace-aggregate",
21808
+ ...aggregateTimeToFirstFeatures,
21784
21809
  ...spanQueryFeatures,
21785
21810
  ...spanAggregateFeatures,
21786
21811
  ...typeof coreStorage.planThreadRowsQuery === "function" ? ["thread-query-rows"] : [],