@spfn/monitor 0.1.0-beta.22 → 0.1.0-beta.23

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/server.d.ts CHANGED
@@ -291,6 +291,13 @@ declare class ErrorGroupsRepository extends BaseRepository {
291
291
  findMany(filters?: ErrorGroupFilters): Promise<ErrorGroup[]>;
292
292
  create(data: NewErrorGroup): Promise<ErrorGroup>;
293
293
  incrementCount(id: number): Promise<ErrorGroup | null>;
294
+ /**
295
+ * Reopen a resolved group: set active, clear resolvedAt, and bump count +
296
+ * lastSeenAt in a SINGLE UPDATE (the reopen path used to do updateStatus then
297
+ * incrementCount — two round trips writing the same row, the second clobbering
298
+ * the first).
299
+ */
300
+ reactivate(id: number): Promise<ErrorGroup | null>;
294
301
  updateStatus(id: number, status: ErrorGroupStatus): Promise<ErrorGroup | null>;
295
302
  countByStatus(): Promise<Record<ErrorGroupStatus, number>>;
296
303
  }
package/dist/server.js CHANGED
@@ -2786,6 +2786,23 @@ var ErrorGroupsRepository = class extends BaseRepository {
2786
2786
  }).where(eq(errorGroups.id, id4)).returning();
2787
2787
  return result[0] ?? null;
2788
2788
  }
2789
+ /**
2790
+ * Reopen a resolved group: set active, clear resolvedAt, and bump count +
2791
+ * lastSeenAt in a SINGLE UPDATE (the reopen path used to do updateStatus then
2792
+ * incrementCount — two round trips writing the same row, the second clobbering
2793
+ * the first).
2794
+ */
2795
+ async reactivate(id4) {
2796
+ const now = /* @__PURE__ */ new Date();
2797
+ const result = await this.db.update(errorGroups).set({
2798
+ status: "active",
2799
+ resolvedAt: null,
2800
+ count: sql`${errorGroups.count} + 1`,
2801
+ lastSeenAt: now,
2802
+ updatedAt: now
2803
+ }).where(eq(errorGroups.id, id4)).returning();
2804
+ return result[0] ?? null;
2805
+ }
2789
2806
  async updateStatus(id4, status) {
2790
2807
  const now = /* @__PURE__ */ new Date();
2791
2808
  const result = await this.db.update(errorGroups).set({
@@ -2829,8 +2846,8 @@ var ErrorEventsRepository = class extends BaseRepository2 {
2829
2846
  return await this.readDb.select().from(errorEvents).where(eq2(errorEvents.groupId, groupId)).orderBy(desc2(errorEvents.createdAt)).limit(limit).offset(offset);
2830
2847
  }
2831
2848
  async deleteOlderThan(date) {
2832
- const result = await this.db.delete(errorEvents).where(lt(errorEvents.createdAt, date)).returning();
2833
- return result.length;
2849
+ const result = await this.db.delete(errorEvents).where(lt(errorEvents.createdAt, date));
2850
+ return result.rowCount ?? result.count ?? 0;
2834
2851
  }
2835
2852
  };
2836
2853
  var errorEventsRepository = new ErrorEventsRepository();
@@ -2905,8 +2922,8 @@ var LogsRepository = class extends BaseRepository3 {
2905
2922
  return counts;
2906
2923
  }
2907
2924
  async deleteOlderThan(date) {
2908
- const result = await this.db.delete(logs).where(lt2(logs.createdAt, date)).returning();
2909
- return result.length;
2925
+ const result = await this.db.delete(logs).where(lt2(logs.createdAt, date));
2926
+ return result.rowCount ?? result.count ?? 0;
2910
2927
  }
2911
2928
  };
2912
2929
  var logsRepository = new LogsRepository();
@@ -3053,8 +3070,7 @@ async function trackError(err, ctx, metadata) {
3053
3070
  return;
3054
3071
  }
3055
3072
  if (existing.status === "resolved") {
3056
- await errorGroupsRepository.updateStatus(existing.id, "active");
3057
- await errorGroupsRepository.incrementCount(existing.id);
3073
+ await errorGroupsRepository.reactivate(existing.id);
3058
3074
  const event = await safeCreateEvent(existing.id, err, ctx, metadata);
3059
3075
  logger2.info("Error group reopened", { fingerprint, groupId: existing.id });
3060
3076
  if (event) {