docs(nostr-patterns): point monotonic created_at at the shared helper
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) <noreply@anthropic.com>
This commit is contained in:
parent
b88eba62b0
commit
e82a9a667a
1 changed files with 9 additions and 5 deletions
|
|
@ -7,15 +7,19 @@ in this file follows from that single fact.
|
||||||
|
|
||||||
## Strictly-monotonic `created_at` per coord
|
## Strictly-monotonic `created_at` per coord
|
||||||
|
|
||||||
**Canonical:** `src/modules/events/composables/useRSVP.ts` —
|
**Canonical helper:** `src/lib/nostr/timestamp.ts` —
|
||||||
`lastPublishAt` map + the `Math.max(now, previous + 1)` line.
|
`monotonicCreatedAt(lastCreatedAt, now?)` returns `max(now, last + 1)`.
|
||||||
|
Use it for **every** replaceable-event publish; track the last
|
||||||
|
`created_at` per coord (a `Map<coord, number>` 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
|
```ts
|
||||||
|
import { monotonicCreatedAt } from '@/lib/nostr/timestamp'
|
||||||
|
|
||||||
const lastPublishAt = new Map<string, number>()
|
const lastPublishAt = new Map<string, number>()
|
||||||
|
|
||||||
const now = Math.floor(Date.now() / 1000)
|
const createdAt = monotonicCreatedAt(lastPublishAt.get(coord))
|
||||||
const previous = lastPublishAt.get(coord) ?? 0
|
|
||||||
const createdAt = Math.max(now, previous + 1)
|
|
||||||
…
|
…
|
||||||
lastPublishAt.set(coord, signedEvent.created_at) // only after publish success
|
lastPublishAt.set(coord, signedEvent.created_at) // only after publish success
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue