@wtfalch/threads 0.1.0 → 0.1.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/threads.js +5 -2
- package/package.json +2 -1
package/dist/threads.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { and, asc, desc, eq, inArray, isNull, ne, sql } from 'drizzle-orm';
|
|
1
|
+
import { and, asc, desc, eq, gt, inArray, isNull, ne, sql } from 'drizzle-orm';
|
|
2
2
|
import { CATEGORY, ThreadsError, categorySubject, } from './gates.js';
|
|
3
3
|
import { schema, threadCategories, threadComments, threadOutbox, threadPeople, threadSubscriptions, threadVotes, threads, } from './schema.js';
|
|
4
4
|
export const DEFAULT_LIMITS = { threadsPerHour: 5, commentsPerTenMinutes: 30 };
|
|
@@ -70,10 +70,13 @@ export function createThreads(opts) {
|
|
|
70
70
|
}
|
|
71
71
|
async function underLimit(table, authorId, windowMs, max, what) {
|
|
72
72
|
const since = new Date(now().getTime() - windowMs);
|
|
73
|
+
// `gt`, not a raw `sql` fragment: the operator maps the Date through the
|
|
74
|
+
// column's type, which every driver accepts; a bare Date parameter is
|
|
75
|
+
// refused by postgres-js and only happened to work on PGlite.
|
|
73
76
|
const [row] = await db
|
|
74
77
|
.select({ n: sql `count(*)::int` })
|
|
75
78
|
.from(table)
|
|
76
|
-
.where(and(eq(table.authorId, authorId),
|
|
79
|
+
.where(and(eq(table.authorId, authorId), gt(table.createdAt, since)));
|
|
77
80
|
if ((row?.n ?? 0) >= max)
|
|
78
81
|
throw new ThreadsError('rate_limited', `too many ${what}, try later`);
|
|
79
82
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtfalch/threads",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Threads, comments, votes and subscriptions attached to a subject the host names: a forum, a feedback board, a comment section. Per-app Postgres, host-supplied gates, React on @wtfalch/design.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"@wtfalch/design": "^0.3.0",
|
|
60
60
|
"drizzle-orm": "^0.39.3",
|
|
61
61
|
"jsdom": "^30.0.1",
|
|
62
|
+
"postgres": "^3.4.5",
|
|
62
63
|
"react": "^19",
|
|
63
64
|
"react-dom": "^19",
|
|
64
65
|
"typescript": "^5.9.0",
|