@openpeepshq/core 0.4.0 → 0.4.10
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/db/pg/schema/edges.js +1 -1
- package/dist/db/pg/sql/0017_unique_has_role_edges.sql +8 -0
- package/dist/db/pg/sql/meta/{0015_snapshot.json → 0017_snapshot.json} +23 -2
- package/dist/db/pg/sql/meta/_journal.json +7 -0
- package/dist/posts/mutations.js +15 -2
- package/dist/profiles/helpers.d.ts +7 -11
- package/dist/profiles/helpers.js +21 -1
- package/package.json +3 -3
|
@@ -30,7 +30,7 @@ export const hasSeen = edgeTable('has_seen');
|
|
|
30
30
|
export const hasRead = edgeTable('has_read');
|
|
31
31
|
export const userGroups = edgeTable('user_groups');
|
|
32
32
|
export const postGroups = edgeTable('post_groups');
|
|
33
|
-
export const hasRole = edgeTable('has_role');
|
|
33
|
+
export const hasRole = edgeTable('has_role', true);
|
|
34
34
|
export const profileAccessTokens = edgeTable('profile_access_tokens', true);
|
|
35
35
|
export const accountToPushSubscription = edgeTable('account_to_push_subscription');
|
|
36
36
|
export const createdReport = edgeTable('created_report');
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Deduplicate existing has_role edges before constraining: keep the oldest
|
|
2
|
+
-- edge per (profile, role), drop the rest. uuidv7 ids are time-ordered.
|
|
3
|
+
DELETE FROM "has_role" a USING "has_role" b
|
|
4
|
+
WHERE a."from_id" = b."from_id"
|
|
5
|
+
AND a."to_id" = b."to_id"
|
|
6
|
+
AND a."id" > b."id";
|
|
7
|
+
--> statement-breakpoint
|
|
8
|
+
CREATE UNIQUE INDEX "has_role_from_to_unique" ON "has_role" USING btree ("from_id","to_id");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "
|
|
3
|
-
"prevId": "
|
|
2
|
+
"id": "cf3c93e7-d862-445f-b74b-6da4dfe23c66",
|
|
3
|
+
"prevId": "dfefc4cf-8580-4232-bcc9-fe7da89adb2e",
|
|
4
4
|
"version": "7",
|
|
5
5
|
"dialect": "postgresql",
|
|
6
6
|
"tables": {
|
|
@@ -2378,6 +2378,27 @@
|
|
|
2378
2378
|
"concurrently": false,
|
|
2379
2379
|
"method": "btree",
|
|
2380
2380
|
"with": {}
|
|
2381
|
+
},
|
|
2382
|
+
"has_role_from_to_unique": {
|
|
2383
|
+
"name": "has_role_from_to_unique",
|
|
2384
|
+
"columns": [
|
|
2385
|
+
{
|
|
2386
|
+
"expression": "from_id",
|
|
2387
|
+
"isExpression": false,
|
|
2388
|
+
"asc": true,
|
|
2389
|
+
"nulls": "last"
|
|
2390
|
+
},
|
|
2391
|
+
{
|
|
2392
|
+
"expression": "to_id",
|
|
2393
|
+
"isExpression": false,
|
|
2394
|
+
"asc": true,
|
|
2395
|
+
"nulls": "last"
|
|
2396
|
+
}
|
|
2397
|
+
],
|
|
2398
|
+
"isUnique": true,
|
|
2399
|
+
"concurrently": false,
|
|
2400
|
+
"method": "btree",
|
|
2401
|
+
"with": {}
|
|
2381
2402
|
}
|
|
2382
2403
|
},
|
|
2383
2404
|
"foreignKeys": {},
|
|
@@ -120,6 +120,13 @@
|
|
|
120
120
|
"when": 1791620000000,
|
|
121
121
|
"tag": "0016_posts_search_vector_title_tags_path",
|
|
122
122
|
"breakpoints": true
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"idx": 17,
|
|
126
|
+
"version": "7",
|
|
127
|
+
"when": 1794031928690,
|
|
128
|
+
"tag": "0017_unique_has_role_edges",
|
|
129
|
+
"breakpoints": true
|
|
123
130
|
}
|
|
124
131
|
]
|
|
125
132
|
}
|
package/dist/posts/mutations.js
CHANGED
|
@@ -14,7 +14,7 @@ import { findOrCreateHashtag } from '../hashtags/index.js';
|
|
|
14
14
|
import { hub } from '../events/index.js';
|
|
15
15
|
import { listUnseenGroupPostIds } from './unseenCounts.js';
|
|
16
16
|
import { AP_LIKE_REACTION, canManageEventRsvps, capacityRsvpDecision, eventDataForDbUpdate, getEffectiveRsvp, instanceRsvpIdsForProfile, isOneToOneDm, normalizeEventDataForSave, overlaySeriesRsvpEntries, participantIds, passThroughUndefined, rsvpCancelNotice, rsvpTargetsPastEvent, sameRecurrenceId, } from '@openpeepshq/common/lib';
|
|
17
|
-
import { forbidden, unprocessableRequest } from '../errors/index.js';
|
|
17
|
+
import { forbidden, notFound, unprocessableRequest } from '../errors/index.js';
|
|
18
18
|
import { areBlocked, hasBlockAmong } from '../profiles/blocks.js';
|
|
19
19
|
import { rebuildEventOccurrences, clearEventOccurrences, } from './eventOccurrences.js';
|
|
20
20
|
import { cancelPollEnd, schedulePollEnd } from './pollEndJobs.js';
|
|
@@ -33,6 +33,11 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
33
33
|
const repliedToPost = relations.inReplyToId
|
|
34
34
|
? await postsMapping.find(db, relations.inReplyToId)
|
|
35
35
|
: undefined;
|
|
36
|
+
// A reply to a deleted post must be rejected; silently dropping the link
|
|
37
|
+
// would republish it as a top-level post on the community feed.
|
|
38
|
+
if (relations.inReplyToId && !repliedToPost) {
|
|
39
|
+
throw notFound({ errorKey: 'error.postDeleted' });
|
|
40
|
+
}
|
|
36
41
|
if (repliedToPost) {
|
|
37
42
|
postData.visibility = repliedToPost.visibility;
|
|
38
43
|
}
|
|
@@ -71,7 +76,15 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
71
76
|
data,
|
|
72
77
|
});
|
|
73
78
|
if (repliedToPost) {
|
|
74
|
-
|
|
79
|
+
// The guard above ran before several awaits; re-check so a concurrent
|
|
80
|
+
// delete cannot leave this reply attached to a tombstoned parent.
|
|
81
|
+
const liveParent = await postsMapping.find(db, repliedToPost.id);
|
|
82
|
+
if (!liveParent) {
|
|
83
|
+
const stored = await postsMapping.find(db, post.id);
|
|
84
|
+
await deletePost(await transformPost(stored), profile);
|
|
85
|
+
throw notFound({ errorKey: 'error.postDeleted' });
|
|
86
|
+
}
|
|
87
|
+
await replyConnector(db, post, liveParent);
|
|
75
88
|
await bumpConversationActivity(db, post.id);
|
|
76
89
|
}
|
|
77
90
|
if (group) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Profile, ProfileWithMeta, Role } from '@openpeepshq/common/types';
|
|
2
|
-
|
|
2
|
+
import type { PgDb } from '../db/pg/client';
|
|
3
|
+
export declare const followConnector: (db: PgDb, from: Profile, to: Profile, data?: {
|
|
3
4
|
uri?: string | undefined;
|
|
4
5
|
reblogs?: boolean | undefined;
|
|
5
6
|
notify?: boolean | undefined;
|
|
@@ -15,17 +16,12 @@ export declare const followConnector: (db: import("../db").PgDb, from: Profile,
|
|
|
15
16
|
_from: string;
|
|
16
17
|
_to: string;
|
|
17
18
|
}>>;
|
|
18
|
-
export declare const followDisconnector: (db:
|
|
19
|
-
export declare const followFinder: (db:
|
|
19
|
+
export declare const followDisconnector: (db: PgDb, from: Profile, to: Profile) => Promise<void>;
|
|
20
|
+
export declare const followFinder: (db: PgDb, from: Profile, to: Profile) => Promise<Record<string, unknown> | undefined>;
|
|
20
21
|
export declare const expandProfiles: (profiles: Profile[]) => Promise<ProfileWithMeta[]>;
|
|
21
|
-
export declare const roleAssigner: (db:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_from: string;
|
|
25
|
-
_to: string;
|
|
26
|
-
}>>;
|
|
27
|
-
export declare const roleUnassigner: (db: import("../db").PgDb, from: Profile, to: Role) => Promise<void>;
|
|
28
|
-
export declare const giveControl: (db: import("../db").PgDb, from: {
|
|
22
|
+
export declare const roleAssigner: (db: PgDb, profile: Profile, role: Role) => Promise<void>;
|
|
23
|
+
export declare const roleUnassigner: (db: PgDb, from: Profile, to: Role) => Promise<void>;
|
|
24
|
+
export declare const giveControl: (db: PgDb, from: {
|
|
29
25
|
id: string;
|
|
30
26
|
}, to: {
|
|
31
27
|
id: string;
|
package/dist/profiles/helpers.js
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
+
import { uuidv7 } from 'uuidv7';
|
|
1
2
|
import { connectionFinder, connector, disconnector } from '../db/helpers.js';
|
|
2
3
|
import { collectionInfos } from '../db/index.js';
|
|
4
|
+
import { nowIso } from '../db/pg/mappers.js';
|
|
5
|
+
import { hasRole } from '../db/pg/schema/index.js';
|
|
3
6
|
import { getProfiles } from './cache.js';
|
|
4
7
|
export const followConnector = connector(collectionInfos.profilesCollection, collectionInfos.profilesCollection, collectionInfos.followsCollection);
|
|
5
8
|
export const followDisconnector = disconnector(collectionInfos.profilesCollection, collectionInfos.profilesCollection, collectionInfos.followsCollection);
|
|
6
9
|
export const followFinder = connectionFinder(collectionInfos.profilesCollection, collectionInfos.profilesCollection, collectionInfos.followsCollection);
|
|
7
10
|
export const expandProfiles = (profiles) => getProfiles(profiles.map((p) => p.id));
|
|
8
|
-
|
|
11
|
+
// Idempotent and race-safe: a role the profile already holds is a no-op, and
|
|
12
|
+
// concurrent assigns (parallel first logins, login racing email validation)
|
|
13
|
+
// insert against has_role_from_to_unique instead of one failing with a
|
|
14
|
+
// unique violation.
|
|
15
|
+
export const roleAssigner = async (db, profile, role) => {
|
|
16
|
+
const ts = nowIso();
|
|
17
|
+
await db
|
|
18
|
+
.insert(hasRole)
|
|
19
|
+
.values({
|
|
20
|
+
id: uuidv7(),
|
|
21
|
+
fromId: profile.id,
|
|
22
|
+
toId: role.id,
|
|
23
|
+
body: {},
|
|
24
|
+
createdAt: ts,
|
|
25
|
+
updatedAt: ts,
|
|
26
|
+
})
|
|
27
|
+
.onConflictDoNothing();
|
|
28
|
+
};
|
|
9
29
|
export const roleUnassigner = disconnector(collectionInfos.profilesCollection, collectionInfos.rolesCollection, collectionInfos.hasRoleCollection);
|
|
10
30
|
export const giveControl = connector(collectionInfos.accountsCollection, collectionInfos.profilesCollection, collectionInfos.controlsCollection);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
40
|
"@openpeepshq/common": "0.5.0",
|
|
41
|
-
"@openpeepshq/
|
|
41
|
+
"@openpeepshq/i18n": "^0.4.1",
|
|
42
42
|
"@openpeepshq/fetch-client": "^0.2.1",
|
|
43
|
-
"@openpeepshq/
|
|
43
|
+
"@openpeepshq/geocoder": "^0.1.2"
|
|
44
44
|
},
|
|
45
45
|
"main": "dist/index.js",
|
|
46
46
|
"types": "dist/index.d.ts",
|