| 1 | import { type SQL, sql } from 'drizzle-orm'; |
| 2 | import type { AnyPgColumn |
| 3 | import { customAlphabet } |
| 4 | import slugify from 'slugify |
| 5 | |
| 6 | const slugAlphabet = customAlphabet |
| 7 | '_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', |
| 8 | 10, |
| 9 | ); |
| 10 | |
| 11 | export function titleToSlug(title |
| 12 | const slugified = |
| 13 | const slugifiedWithSuffix = |
| 14 | return { |
| 15 | slugified, |
| 16 | slugifiedWithSuffix, |
| 17 | }; |
| 18 | } |
| 19 | |
| 20 | // Opaque keyset cursor: a (timestamp, id) pair, base64url encoded so callers treat it as a token instead of something they can hand-build. |
| 21 | export function encodeCursor({ |
| 22 | return Buffer.from |
| 23 | } |
| 24 | |
| 25 | export function decodeCursor(cursor |
| 26 | const [timestamp, |
| 27 | .toString('utf8') |
| 28 | .split('|') |
| 29 | if (!timestamp || |
| 30 | const date = |
| 31 | if (Number.isNaN |
| 32 | return { date, |
| 33 | } |
| 34 | |
| 35 | // Timestamps leave the database already in the shape responses promise, so nothing downstream has to convert them. The format matches `Date.prototype.toISOString` byte for byte. |
| 36 | export function isoTimestamp(column |
| 37 | return sql<string |
| 38 | } |
| 39 | |
| 40 | // For `ilike`: a search for "50%" or "a_b" matches those characters, not any. |
| 41 | export function escapeLike(value |
| 42 | return value.replace |
| 43 | } |