From e82a9a667abefff5d6cedbd9e88f9587e464ea7a Mon Sep 17 00:00:00 2001 From: Padreug Date: Thu, 18 Jun 2026 13:33:15 +0200 Subject: [PATCH] docs(nostr-patterns): point monotonic created_at at the shared helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "strictly-monotonic created_at per coord" section named useRSVP.ts as canonical, but that file no longer exists. monotonicCreatedAt() in src/lib/nostr/timestamp.ts is now the single implementation — make the doc reference it and show both the per-coord-Map and single-field tracking shapes. Keeps doc and code aligned per the docs discipline. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/nostr-patterns/replaceable-events.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/nostr-patterns/replaceable-events.md b/docs/nostr-patterns/replaceable-events.md index 0cad379..f02158b 100644 --- a/docs/nostr-patterns/replaceable-events.md +++ b/docs/nostr-patterns/replaceable-events.md @@ -7,15 +7,19 @@ in this file follows from that single fact. ## Strictly-monotonic `created_at` per coord -**Canonical:** `src/modules/events/composables/useRSVP.ts` — -`lastPublishAt` map + the `Math.max(now, previous + 1)` line. +**Canonical helper:** `src/lib/nostr/timestamp.ts` — +`monotonicCreatedAt(lastCreatedAt, now?)` returns `max(now, last + 1)`. +Use it for **every** replaceable-event publish; track the last +`created_at` per coord (a `Map` when one composable +publishes many coords like `useRSVP.ts`, or a single field when there's +one coord per user like `useBookmarks.ts`' kind-10003 list). ```ts +import { monotonicCreatedAt } from '@/lib/nostr/timestamp' + const lastPublishAt = new Map() -const now = Math.floor(Date.now() / 1000) -const previous = lastPublishAt.get(coord) ?? 0 -const createdAt = Math.max(now, previous + 1) +const createdAt = monotonicCreatedAt(lastPublishAt.get(coord)) … lastPublishAt.set(coord, signedEvent.created_at) // only after publish success ```