@openpeepshq/core 0.1.33 → 0.1.34
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/accounts/mutations.js +33 -35
- package/dist/analytics/compile.js +16 -10
- package/dist/analytics/read.js +52 -9
- package/dist/analytics/report.d.ts +20 -0
- package/dist/backups/index.js +75 -15
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +7 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +3 -0
- package/dist/config/index.d.ts +21 -0
- package/dist/config/index.js +7 -1
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +11 -3
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/init.js +2 -3
- package/dist/db/migration/importCollections.d.ts +14 -9
- package/dist/db/migration/importCollections.js +114 -164
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +2 -52
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/posts.d.ts +10 -0
- package/dist/db/pg/filters/posts.js +28 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/map/filters.js +32 -2
- package/dist/db/pg/map/mutations.js +13 -8
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +64 -24
- package/dist/db/pg/map/relations.js +9 -5
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +6 -6
- package/dist/db/pg/queries/activity.js +3 -3
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +279 -41
- package/dist/db/pg/schema/documents.js +21 -8
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +2 -1
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +43 -1
- package/dist/email/render.js +11 -3
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +26 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +60 -0
- package/dist/jams/health.d.ts +8 -0
- package/dist/jams/health.js +46 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +23 -16
- package/dist/jams/jobs.js +1 -1
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +56 -39
- package/dist/jams/mapping.d.ts +3 -3
- package/dist/jams/mutations.d.ts +1 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +32 -0
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +18 -7
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +6 -1
- package/dist/jobs/jobDetail.js +1 -6
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +23 -8
- package/dist/media/processing.js +18 -7
- package/dist/notifications/defaultNotifications/follow/index.js +2 -2
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +18 -0
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/jobs.js +3 -1
- package/dist/notifications/mutations.js +4 -0
- package/dist/plugins/index.js +37 -1
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +281 -49
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +10 -6
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +35 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +15 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -2
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +10 -4
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +21 -0
- package/dist/posts/finders.d.ts +15 -8
- package/dist/posts/finders.js +67 -18
- package/dist/posts/helpers/filters.js +13 -8
- package/dist/posts/helpers/index.d.ts +27 -14
- package/dist/posts/helpers/index.js +34 -14
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +216 -13
- package/dist/posts/mapping.js +14 -13
- package/dist/posts/mutations.d.ts +440 -3
- package/dist/posts/mutations.js +155 -32
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +7 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +14 -16
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/profileSettings/cache.js +22 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +87 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +1 -0
- package/dist/profiles/cache.js +19 -6
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +8 -3
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +31 -2
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +86 -3
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.js +24 -12
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +98 -0
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +9 -5
- package/dist/stats/mapping.d.ts +0 -1
- package/dist/stats/mapping.js +0 -3
- package/package.json +4 -5
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -33
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -20
- package/dist/db/migration/transform.js +0 -232
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
- package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.js +0 -4
- package/dist/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -95
|
@@ -7,12 +7,12 @@ const edge = (name) => ({
|
|
|
7
7
|
});
|
|
8
8
|
/** Named collection/edge refs aligned with `documentRegistry` and `edgeRegistry`. */
|
|
9
9
|
export const collectionInfos = {
|
|
10
|
-
dataMigrationsCollection: document('dataMigrations'),
|
|
11
10
|
i18nCollection: document('i18n'),
|
|
12
11
|
configCollection: document('configs'),
|
|
13
12
|
accountsCollection: document('accounts'),
|
|
14
13
|
profilesCollection: document('profiles'),
|
|
15
14
|
followsCollection: edge('follows'),
|
|
15
|
+
blocksCollection: edge('blocks'),
|
|
16
16
|
requestsFollowCollection: edge('requestsFollow'),
|
|
17
17
|
controlsCollection: edge('controls'),
|
|
18
18
|
postsCollection: document('posts'),
|
|
@@ -25,7 +25,6 @@ export const collectionInfos = {
|
|
|
25
25
|
isReportedProfileCollection: edge('isReportedProfile'),
|
|
26
26
|
isReportedObjectCollection: edge('isReportedObject'),
|
|
27
27
|
entriesCollection: edge('entries'),
|
|
28
|
-
reactionsCollection: edge('reactions'),
|
|
29
28
|
repliesCollection: edge('replyTo'),
|
|
30
29
|
repostCollection: edge('repost'),
|
|
31
30
|
mediaAttachmentsCollection: document('mediaAttachments'),
|
|
@@ -50,4 +49,5 @@ export const collectionInfos = {
|
|
|
50
49
|
postSeenCollection: edge('postSeen'),
|
|
51
50
|
profileSettingsCollection: document('profileSettings'),
|
|
52
51
|
jamRecordingsCollection: edge('jamRecordings'),
|
|
52
|
+
profileHashtagsCollection: edge('profileHashtags'),
|
|
53
53
|
};
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import type { FeedCursor } from '@openpeepshq/common';
|
|
1
2
|
import { type SqlFilter } from './types';
|
|
2
3
|
export declare const postFilters: {
|
|
3
4
|
notDirect: () => SqlFilter;
|
|
4
5
|
isDirect: () => SqlFilter;
|
|
6
|
+
/** Original posts only — replies belong in the parent thread, not the feed. */
|
|
7
|
+
notReply: () => SqlFilter;
|
|
8
|
+
/**
|
|
9
|
+
* Keyset for `ORDER BY last_activity_at DESC, id DESC`. A uuid-only cursor
|
|
10
|
+
* looks up the referenced row so older clients keep paginating.
|
|
11
|
+
*/
|
|
12
|
+
afterActivity: (cursor: FeedCursor) => SqlFilter;
|
|
5
13
|
hasJam: () => SqlFilter;
|
|
6
14
|
creatorId: (id: string) => SqlFilter;
|
|
15
|
+
notCreatorIn: (ids: string[]) => SqlFilter | undefined;
|
|
7
16
|
myFeed: (profileId: string, followedProfileIds: string[], groupIds: string[]) => SqlFilter;
|
|
8
17
|
type: (type: string) => SqlFilter;
|
|
9
18
|
replyCount: (op: "==" | "!=" | ">" | ">=" | "<" | "<=", count: number) => SqlFilter;
|
|
@@ -11,6 +20,7 @@ export declare const postFilters: {
|
|
|
11
20
|
replyCountPositive: () => SqlFilter;
|
|
12
21
|
isJamModerator: (profileId: string) => SqlFilter;
|
|
13
22
|
hasYesOrMaybeRsvp: (profileId: string) => SqlFilter;
|
|
23
|
+
hasAnyHashtag: (hashtagIds: string[]) => SqlFilter | undefined;
|
|
14
24
|
};
|
|
15
25
|
export declare const eventTimeFilters: {
|
|
16
26
|
upcoming: (now?: string) => SqlFilter;
|
|
@@ -1,17 +1,38 @@
|
|
|
1
|
-
import { and, eq, inArray, isNotNull, ne, or, sql } from 'drizzle-orm';
|
|
1
|
+
import { and, eq, inArray, isNotNull, ne, notInArray, or, sql, } from 'drizzle-orm';
|
|
2
2
|
import { posts } from '../schema/documents.js';
|
|
3
|
-
import { postGroups } from '../schema/edges.js';
|
|
3
|
+
import { postGroups, postHashtags, replyTo } from '../schema/edges.js';
|
|
4
4
|
import { postHasYesOrMaybeRsvpExpr, postReplyCountExpr, } from '../queries/activity.js';
|
|
5
5
|
import { compareCount } from './common.js';
|
|
6
6
|
import { pgSql } from './types.js';
|
|
7
7
|
const eventStart = sql `${posts.body}->>'start'`;
|
|
8
8
|
const eventEnd = sql `${posts.body}->>'end'`;
|
|
9
|
+
// Open-ended events count as one hour long when they are current or past.
|
|
10
|
+
const eventEffectiveEnd = sql `COALESCE(NULLIF(${eventEnd}, '')::timestamptz, ${eventStart}::timestamptz + interval '1 hour')`;
|
|
9
11
|
const postsReplyCountExpr = postReplyCountExpr(posts);
|
|
10
12
|
export const postFilters = {
|
|
11
13
|
notDirect: () => pgSql(ne(posts.visibility, 'direct')),
|
|
12
14
|
isDirect: () => pgSql(eq(posts.visibility, 'direct')),
|
|
15
|
+
/** Original posts only — replies belong in the parent thread, not the feed. */
|
|
16
|
+
notReply: () => pgSql(sql `NOT EXISTS (SELECT 1 FROM ${replyTo} WHERE ${replyTo.fromId} = ${posts.id}::text)`),
|
|
17
|
+
/**
|
|
18
|
+
* Keyset for `ORDER BY last_activity_at DESC, id DESC`. A uuid-only cursor
|
|
19
|
+
* looks up the referenced row so older clients keep paginating.
|
|
20
|
+
*/
|
|
21
|
+
afterActivity: (cursor) => {
|
|
22
|
+
const activity = cursor.lastActivityAt
|
|
23
|
+
? sql `${cursor.lastActivityAt}::timestamptz`
|
|
24
|
+
: sql `(SELECT p2.last_activity_at FROM posts p2 WHERE p2.id = ${cursor.id}::uuid)`;
|
|
25
|
+
return pgSql(sql `(
|
|
26
|
+
${posts.lastActivityAt} < ${activity}
|
|
27
|
+
OR (
|
|
28
|
+
${posts.lastActivityAt} = ${activity}
|
|
29
|
+
AND ${posts.id} < ${cursor.id}::uuid
|
|
30
|
+
)
|
|
31
|
+
)`);
|
|
32
|
+
},
|
|
13
33
|
hasJam: () => pgSql(isNotNull(sql `${posts.body}->'jam'`)),
|
|
14
34
|
creatorId: (id) => pgSql(eq(posts.creatorId, id)),
|
|
35
|
+
notCreatorIn: (ids) => ids.length ? pgSql(notInArray(posts.creatorId, ids)) : undefined,
|
|
15
36
|
myFeed: (profileId, followedProfileIds, groupIds) => {
|
|
16
37
|
const followed = followedProfileIds.length
|
|
17
38
|
? inArray(posts.creatorId, followedProfileIds)
|
|
@@ -27,9 +48,12 @@ export const postFilters = {
|
|
|
27
48
|
replyCountPositive: () => postFilters.replyCount('>', 0),
|
|
28
49
|
isJamModerator: (profileId) => pgSql(sql `${posts.body}->'jam'->'moderators' ? ${profileId}`),
|
|
29
50
|
hasYesOrMaybeRsvp: (profileId) => pgSql(postHasYesOrMaybeRsvpExpr(posts, profileId)),
|
|
51
|
+
hasAnyHashtag: (hashtagIds) => hashtagIds.length
|
|
52
|
+
? pgSql(sql `EXISTS (SELECT 1 FROM ${postHashtags} WHERE ${postHashtags.fromId} = ${posts.id}::text AND ${inArray(postHashtags.toId, hashtagIds)})`)
|
|
53
|
+
: undefined,
|
|
30
54
|
};
|
|
31
55
|
export const eventTimeFilters = {
|
|
32
56
|
upcoming: (now = new Date().toISOString()) => pgSql(or(sql `${eventStart} > ${now}`, and(sql `${posts.body}->'end' IS NOT NULL`, sql `${eventEnd} > ${now}`))),
|
|
33
|
-
current: (now = new Date().toISOString()) => pgSql(and(sql `${eventStart} <= ${now}`,
|
|
34
|
-
past: (now = new Date().toISOString()) => pgSql(sql
|
|
57
|
+
current: (now = new Date().toISOString()) => pgSql(and(sql `${eventStart}::timestamptz <= ${now}::timestamptz`, sql `${eventEffectiveEnd} >= ${now}::timestamptz`)),
|
|
58
|
+
past: (now = new Date().toISOString()) => pgSql(sql `${eventEffectiveEnd} < ${now}::timestamptz`),
|
|
35
59
|
};
|
|
@@ -2,5 +2,6 @@ import { type SqlFilter } from './types';
|
|
|
2
2
|
export declare const profileFilters: {
|
|
3
3
|
notGuest: () => SqlFilter;
|
|
4
4
|
type: (type: string) => SqlFilter;
|
|
5
|
+
notIdIn: (ids: string[]) => SqlFilter | undefined;
|
|
5
6
|
activityScorePositive: (start?: Date, end?: Date) => SqlFilter;
|
|
6
7
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { eq, gt, ne } from 'drizzle-orm';
|
|
1
|
+
import { eq, gt, ne, notInArray } from 'drizzle-orm';
|
|
2
2
|
import { profiles } from '../schema/documents.js';
|
|
3
3
|
import { profileActivityScoreExpr } from '../queries/activity.js';
|
|
4
4
|
import { pgSql } from './types.js';
|
|
5
5
|
export const profileFilters = {
|
|
6
6
|
notGuest: () => pgSql(ne(profiles.type, 'guest')),
|
|
7
7
|
type: (type) => pgSql(eq(profiles.type, type)),
|
|
8
|
+
notIdIn: (ids) => ids.length ? pgSql(notInArray(profiles.id, ids)) : undefined,
|
|
8
9
|
activityScorePositive: (start, end) => pgSql(gt(profileActivityScoreExpr(profiles, { start, end }), 0)),
|
|
9
10
|
};
|
|
@@ -5,8 +5,24 @@ import { groupLastPostAtExpr, postActivityScoreExpr, postReplyCountExpr, postRep
|
|
|
5
5
|
import { asTable, edgeRegistry, getCollectionConfig, parseDocRef, } from './registry.js';
|
|
6
6
|
const SCALAR_COLUMNS = {
|
|
7
7
|
accounts: ['email', 'passwordHash', 'emailValidated', 'guest'],
|
|
8
|
-
profiles: [
|
|
9
|
-
|
|
8
|
+
profiles: [
|
|
9
|
+
'handle',
|
|
10
|
+
'type',
|
|
11
|
+
'activityPubDomain',
|
|
12
|
+
'uri',
|
|
13
|
+
'inboxUrl',
|
|
14
|
+
'sharedInboxUrl',
|
|
15
|
+
'keyId',
|
|
16
|
+
'fetchedAt',
|
|
17
|
+
],
|
|
18
|
+
posts: [
|
|
19
|
+
'type',
|
|
20
|
+
'visibility',
|
|
21
|
+
'creatorId',
|
|
22
|
+
'lastActivityAt',
|
|
23
|
+
'uri',
|
|
24
|
+
'inReplyToUri',
|
|
25
|
+
],
|
|
10
26
|
groups: ['handle'],
|
|
11
27
|
hashtags: ['name'],
|
|
12
28
|
roles: ['key', 'isDefault'],
|
|
@@ -92,6 +108,9 @@ const docFieldSql = (collection, table, fieldPath) => {
|
|
|
92
108
|
return sql `${t.createdAt}`;
|
|
93
109
|
if (fieldPath === 'updatedAt' && t.updatedAt)
|
|
94
110
|
return sql `${t.updatedAt}`;
|
|
111
|
+
if (fieldPath === 'lastActivityAt' && t.lastActivityAt) {
|
|
112
|
+
return sql `${t.lastActivityAt}`;
|
|
113
|
+
}
|
|
95
114
|
if (fieldPath === '_from' && t.fromId)
|
|
96
115
|
return sql `${t.fromId}`;
|
|
97
116
|
if (fieldPath === '_to' && t.toId)
|
|
@@ -399,6 +418,17 @@ const matchToSql = (collection, table, match) => {
|
|
|
399
418
|
const config = getCollectionConfig(collection);
|
|
400
419
|
if (!config)
|
|
401
420
|
continue;
|
|
421
|
+
if (collection === 'profiles' &&
|
|
422
|
+
key === 'activityPub' &&
|
|
423
|
+
value &&
|
|
424
|
+
typeof value === 'object' &&
|
|
425
|
+
!Array.isArray(value)) {
|
|
426
|
+
const domain = value.domain;
|
|
427
|
+
if (typeof domain === 'string') {
|
|
428
|
+
conditions.push(eq(t.activityPubDomain, domain));
|
|
429
|
+
}
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
402
432
|
if (config.kind === 'document') {
|
|
403
433
|
const scalars = SCALAR_COLUMNS[collection];
|
|
404
434
|
if (scalars === null || scalars === void 0 ? void 0 : scalars.includes(key)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eq } from 'drizzle-orm';
|
|
2
2
|
import { uuidv7 } from 'uuidv7';
|
|
3
3
|
import { nowIso } from '../mappers.js';
|
|
4
|
-
import { asTable, documentRegistry, getCollectionConfig, getTableForCollection, } from './registry.js';
|
|
4
|
+
import { asTable, documentIdColumn, documentRegistry, getCollectionConfig, getTableForCollection, } from './registry.js';
|
|
5
5
|
import { executeFind } from './relations.js';
|
|
6
6
|
const EDGE_PATCH_META_KEYS = new Set([
|
|
7
7
|
'id',
|
|
@@ -32,7 +32,9 @@ export const createDocument = async (db, mapData, data) => {
|
|
|
32
32
|
const id = (_a = data.id) !== null && _a !== void 0 ? _a : uuidv7();
|
|
33
33
|
const { scalars, body } = config.splitPatch(data);
|
|
34
34
|
const ts = nowIso();
|
|
35
|
-
await db.insert(config.table).values(Object.assign(Object.assign({ id }, scalars), { body, createdAt: ts, updatedAt: ts, deletedAt: null })
|
|
35
|
+
await db.insert(config.table).values(Object.assign(Object.assign(Object.assign({ id }, scalars), { body, createdAt: ts, updatedAt: ts, deletedAt: null }), (collection === 'posts' && scalars.lastActivityAt === undefined
|
|
36
|
+
? { lastActivityAt: ts }
|
|
37
|
+
: {})));
|
|
36
38
|
const created = await executeFind(db, collection, mapData, id, true);
|
|
37
39
|
if (!created) {
|
|
38
40
|
throw new Error(`create ${collection}`);
|
|
@@ -50,7 +52,7 @@ export const updateDocument = async (db, mapData, id, patch) => {
|
|
|
50
52
|
const existing = await db
|
|
51
53
|
.select()
|
|
52
54
|
.from(config.table)
|
|
53
|
-
.where(eq(table
|
|
55
|
+
.where(eq(documentIdColumn(collection, table), id))
|
|
54
56
|
.limit(1);
|
|
55
57
|
const row = existing[0];
|
|
56
58
|
if (!row) {
|
|
@@ -64,7 +66,7 @@ export const updateDocument = async (db, mapData, id, patch) => {
|
|
|
64
66
|
body: Object.assign(Object.assign({}, currentBody), edgeBodyPatch(patch)),
|
|
65
67
|
updatedAt: nowIso(),
|
|
66
68
|
})
|
|
67
|
-
.where(eq(table
|
|
69
|
+
.where(eq(documentIdColumn(collection, table), id));
|
|
68
70
|
}
|
|
69
71
|
else {
|
|
70
72
|
const merged = Object.assign(Object.assign({}, rowToPatchInput(collection, row)), patch);
|
|
@@ -72,7 +74,7 @@ export const updateDocument = async (db, mapData, id, patch) => {
|
|
|
72
74
|
await db
|
|
73
75
|
.update(table)
|
|
74
76
|
.set(Object.assign(Object.assign({}, scalars), { body, updatedAt: nowIso() }))
|
|
75
|
-
.where(eq(table
|
|
77
|
+
.where(eq(documentIdColumn(collection, table), id));
|
|
76
78
|
}
|
|
77
79
|
const updated = await executeFind(db, collection, mapData, id, true);
|
|
78
80
|
if (!updated) {
|
|
@@ -87,10 +89,13 @@ const rowToPatchInput = (collection, row) => {
|
|
|
87
89
|
type: row.type,
|
|
88
90
|
visibility: row.visibility,
|
|
89
91
|
creatorId: row.creatorId,
|
|
92
|
+
lastActivityAt: row.lastActivityAt,
|
|
93
|
+
uri: row.uri,
|
|
94
|
+
inReplyToUri: row.inReplyToUri,
|
|
90
95
|
data: row.body,
|
|
91
96
|
};
|
|
92
97
|
case 'profiles':
|
|
93
|
-
return Object.assign(Object.assign({ handle: row.handle, type: row.type }, (row.activityPubDomain
|
|
98
|
+
return Object.assign(Object.assign({ handle: row.handle, type: row.type, uri: row.uri, inboxUrl: row.inboxUrl, sharedInboxUrl: row.sharedInboxUrl, publicKeyPem: row.publicKeyPem, privateKeyPem: row.privateKeyPem, keyId: row.keyId, fetchedAt: row.fetchedAt }, (row.activityPubDomain
|
|
94
99
|
? { activityPub: { domain: row.activityPubDomain } }
|
|
95
100
|
: {})), row.body);
|
|
96
101
|
case 'groups':
|
|
@@ -126,10 +131,10 @@ export const deleteDocument = async (db, mapData, id) => {
|
|
|
126
131
|
await db
|
|
127
132
|
.update(getTableForCollection(mapData.collection))
|
|
128
133
|
.set({ deletedAt: nowIso(), updatedAt: nowIso() })
|
|
129
|
-
.where(eq(
|
|
134
|
+
.where(eq(documentIdColumn(mapData.collection, table), id));
|
|
130
135
|
return;
|
|
131
136
|
}
|
|
132
137
|
await db
|
|
133
138
|
.delete(getTableForCollection(mapData.collection))
|
|
134
|
-
.where(eq(
|
|
139
|
+
.where(eq(documentIdColumn(mapData.collection, table), id));
|
|
135
140
|
};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export type PgTable = unknown;
|
|
2
2
|
export declare const asTable: (table: PgTable) => Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Column the map layer treats as a document's id. Profile settings are
|
|
5
|
+
* addressed by profile id; legacy rows keep a different primary key.
|
|
6
|
+
*/
|
|
7
|
+
export declare const documentIdColumn: (collection: string, table: Record<string, unknown>) => unknown;
|
|
3
8
|
export type DocumentConfig = {
|
|
4
9
|
kind: 'document';
|
|
5
10
|
table: PgTable;
|
|
@@ -11,8 +11,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import * as documents from '../schema/documents.js';
|
|
13
13
|
import * as edges from '../schema/edges.js';
|
|
14
|
-
import { modelTimestampsFromRow, rowToModel, } from '../mappers.js';
|
|
14
|
+
import { modelTimestampsFromRow, normalizeIsoDatetime, rowToModel, } from '../mappers.js';
|
|
15
15
|
export const asTable = (table) => table;
|
|
16
|
+
/**
|
|
17
|
+
* Column the map layer treats as a document's id. Profile settings are
|
|
18
|
+
* addressed by profile id; legacy rows keep a different primary key.
|
|
19
|
+
*/
|
|
20
|
+
export const documentIdColumn = (collection, table) => (collection === 'profileSettings' ? table.profileId : table.id);
|
|
16
21
|
const bodyOnly = (data) => ({
|
|
17
22
|
scalars: {},
|
|
18
23
|
body: Object.assign({}, data),
|
|
@@ -29,7 +34,7 @@ const withScalars = (...scalarKeys) => (data) => {
|
|
|
29
34
|
return { scalars, body };
|
|
30
35
|
};
|
|
31
36
|
const postsSplit = (data) => {
|
|
32
|
-
const { type, visibility, creatorId, data: postBody } = data, rest = __rest(data, ["type", "visibility", "creatorId", "data"]);
|
|
37
|
+
const { type, visibility, creatorId, lastActivityAt, data: postBody, uri, inReplyToUri } = data, rest = __rest(data, ["type", "visibility", "creatorId", "lastActivityAt", "data", "uri", "inReplyToUri"]);
|
|
33
38
|
const scalars = {};
|
|
34
39
|
if (type !== undefined)
|
|
35
40
|
scalars.type = type;
|
|
@@ -37,14 +42,32 @@ const postsSplit = (data) => {
|
|
|
37
42
|
scalars.visibility = visibility;
|
|
38
43
|
if (creatorId !== undefined)
|
|
39
44
|
scalars.creatorId = creatorId;
|
|
45
|
+
if (lastActivityAt !== undefined)
|
|
46
|
+
scalars.lastActivityAt = lastActivityAt;
|
|
47
|
+
if (uri !== undefined)
|
|
48
|
+
scalars.uri = uri;
|
|
49
|
+
if (inReplyToUri !== undefined)
|
|
50
|
+
scalars.inReplyToUri = inReplyToUri;
|
|
40
51
|
const body = postBody !== undefined ? Object.assign({}, postBody) : Object.assign({}, rest);
|
|
41
52
|
if (postBody === undefined) {
|
|
42
53
|
delete body.type;
|
|
43
54
|
delete body.visibility;
|
|
44
55
|
delete body.creatorId;
|
|
56
|
+
delete body.lastActivityAt;
|
|
57
|
+
delete body.uri;
|
|
58
|
+
delete body.inReplyToUri;
|
|
45
59
|
}
|
|
46
60
|
return { scalars, body };
|
|
47
61
|
};
|
|
62
|
+
const ACTOR_SCALAR_KEYS = [
|
|
63
|
+
'uri',
|
|
64
|
+
'inboxUrl',
|
|
65
|
+
'sharedInboxUrl',
|
|
66
|
+
'publicKeyPem',
|
|
67
|
+
'privateKeyPem',
|
|
68
|
+
'keyId',
|
|
69
|
+
'fetchedAt',
|
|
70
|
+
];
|
|
48
71
|
const profilesSplit = (data) => {
|
|
49
72
|
const { handle, type, activityPub } = data, rest = __rest(data, ["handle", "type", "activityPub"]);
|
|
50
73
|
const scalars = {};
|
|
@@ -57,7 +80,14 @@ const profilesSplit = (data) => {
|
|
|
57
80
|
if (domain !== undefined)
|
|
58
81
|
scalars.activityPubDomain = domain;
|
|
59
82
|
}
|
|
60
|
-
|
|
83
|
+
const body = Object.assign({}, rest);
|
|
84
|
+
for (const key of ACTOR_SCALAR_KEYS) {
|
|
85
|
+
if (key in body) {
|
|
86
|
+
scalars[key] = body[key];
|
|
87
|
+
delete body[key];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { scalars, body };
|
|
61
91
|
};
|
|
62
92
|
/** App model uses `tag`; Postgres column is `name`. */
|
|
63
93
|
const hashtagsSplit = (data) => {
|
|
@@ -71,7 +101,7 @@ const hashtagsSplit = (data) => {
|
|
|
71
101
|
}
|
|
72
102
|
return withScalars('name')(normalized);
|
|
73
103
|
};
|
|
74
|
-
/**
|
|
104
|
+
/** Older jam events stored jamId; the column is post_id. */
|
|
75
105
|
const jamEventsSplit = (data) => {
|
|
76
106
|
const { postId, jamId } = data, rest = __rest(data, ["postId", "jamId"]);
|
|
77
107
|
const scalars = {};
|
|
@@ -177,11 +207,6 @@ export const documentRegistry = {
|
|
|
177
207
|
table: documents.i18nEntries,
|
|
178
208
|
splitPatch: withScalars('locale', 'namespace'),
|
|
179
209
|
},
|
|
180
|
-
dataMigrations: {
|
|
181
|
-
kind: 'document',
|
|
182
|
-
table: documents.dataMigrations,
|
|
183
|
-
splitPatch: bodyOnly,
|
|
184
|
-
},
|
|
185
210
|
};
|
|
186
211
|
export const edgeRegistry = {
|
|
187
212
|
follows: {
|
|
@@ -190,6 +215,12 @@ export const edgeRegistry = {
|
|
|
190
215
|
fromCollection: 'profiles',
|
|
191
216
|
toCollection: 'profiles',
|
|
192
217
|
},
|
|
218
|
+
blocks: {
|
|
219
|
+
kind: 'edge',
|
|
220
|
+
table: edges.blocks,
|
|
221
|
+
fromCollection: 'profiles',
|
|
222
|
+
toCollection: 'profiles',
|
|
223
|
+
},
|
|
193
224
|
requestsFollow: {
|
|
194
225
|
kind: 'edge',
|
|
195
226
|
table: edges.requestsFollow,
|
|
@@ -226,12 +257,6 @@ export const edgeRegistry = {
|
|
|
226
257
|
fromCollection: 'profiles',
|
|
227
258
|
toCollection: 'posts',
|
|
228
259
|
},
|
|
229
|
-
reactions: {
|
|
230
|
-
kind: 'edge',
|
|
231
|
-
table: edges.reactions,
|
|
232
|
-
fromCollection: 'profiles',
|
|
233
|
-
toCollection: 'posts',
|
|
234
|
-
},
|
|
235
260
|
replyTo: {
|
|
236
261
|
kind: 'edge',
|
|
237
262
|
table: edges.replyTo,
|
|
@@ -334,6 +359,12 @@ export const edgeRegistry = {
|
|
|
334
359
|
fromCollection: 'profiles',
|
|
335
360
|
toCollection: 'posts',
|
|
336
361
|
},
|
|
362
|
+
profileHashtags: {
|
|
363
|
+
kind: 'edge',
|
|
364
|
+
table: edges.profileHashtags,
|
|
365
|
+
fromCollection: 'profiles',
|
|
366
|
+
toCollection: 'hashtags',
|
|
367
|
+
},
|
|
337
368
|
};
|
|
338
369
|
export const getCollectionConfig = (collection) => { var _a; return (_a = documentRegistry[collection]) !== null && _a !== void 0 ? _a : edgeRegistry[collection]; };
|
|
339
370
|
export const getTableForCollection = (collection) => {
|
|
@@ -376,16 +407,25 @@ export const rowToDocument = (collection, row, keepMetadata = false) => {
|
|
|
376
407
|
guest: (_b = row.guest) !== null && _b !== void 0 ? _b : undefined,
|
|
377
408
|
}, timestamps);
|
|
378
409
|
case 'profiles':
|
|
379
|
-
return rowToModel(row.id, Object.assign(Object.assign({ handle: row.handle, type: row.type }, (row.activityPubDomain
|
|
410
|
+
return rowToModel(row.id, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ handle: row.handle, type: row.type }, (row.activityPubDomain
|
|
380
411
|
? { activityPub: { domain: row.activityPubDomain } }
|
|
381
|
-
: {})), ((_c = row.body) !== null && _c !== void 0 ? _c : {})),
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
412
|
+
: {})), ((_c = row.body) !== null && _c !== void 0 ? _c : {})), (typeof row.uri === 'string' ? { uri: row.uri } : {})), (typeof row.inboxUrl === 'string'
|
|
413
|
+
? { inboxUrl: row.inboxUrl }
|
|
414
|
+
: {})), (typeof row.sharedInboxUrl === 'string'
|
|
415
|
+
? { sharedInboxUrl: row.sharedInboxUrl }
|
|
416
|
+
: {})), (typeof row.publicKeyPem === 'string'
|
|
417
|
+
? { publicKeyPem: row.publicKeyPem }
|
|
418
|
+
: {})), (typeof row.keyId === 'string' ? { keyId: row.keyId } : {})), (typeof row.fetchedAt === 'string'
|
|
419
|
+
? { fetchedAt: normalizeIsoDatetime(row.fetchedAt) }
|
|
420
|
+
: {})), timestamps);
|
|
421
|
+
case 'posts': {
|
|
422
|
+
const lastActivityAt = row.lastActivityAt
|
|
423
|
+
? normalizeIsoDatetime(row.lastActivityAt)
|
|
424
|
+
: timestamps.createdAt;
|
|
425
|
+
return Object.assign(Object.assign({}, rowToModel(row.id, Object.assign(Object.assign(Object.assign({ type: row.type, visibility: row.visibility, creatorId: row.creatorId }, (typeof row.uri === 'string' ? { uri: row.uri } : {})), (typeof row.inReplyToUri === 'string'
|
|
426
|
+
? { inReplyToUri: row.inReplyToUri }
|
|
427
|
+
: {})), { data: (_d = row.body) !== null && _d !== void 0 ? _d : {} }), timestamps)), { lastActivityAt });
|
|
428
|
+
}
|
|
389
429
|
case 'groups':
|
|
390
430
|
return rowToModel(row.id, Object.assign({ handle: row.handle }, ((_e = row.body) !== null && _e !== void 0 ? _e : {})), timestamps);
|
|
391
431
|
case 'hashtags':
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { and, eq, getTableColumns, inArray, sql, } from 'drizzle-orm';
|
|
2
2
|
import { applyDateRangeToEdgeSql, applyLimit, applyPostFilters, applySqlLimit, applySort, partitionFilters, sortToSqlOrderBy, getEdgeTable, } from './filters.js';
|
|
3
3
|
import { isSqlFilter } from '../filters/index.js';
|
|
4
|
-
import { asTable, edgeRegistry, getTableForCollection, rowToDocument, } from './registry.js';
|
|
4
|
+
import { asTable, documentIdColumn, edgeRegistry, getTableForCollection, rowToDocument, } from './registry.js';
|
|
5
5
|
import { normalizeComputedDatetime } from '../mappers.js';
|
|
6
6
|
const buildComputedSelect = (mapData, tableRef) => {
|
|
7
7
|
var _a;
|
|
@@ -40,7 +40,9 @@ export const fetchRowsByIds = async (db, collection, ids, softDelete) => {
|
|
|
40
40
|
if (!ids.length)
|
|
41
41
|
return [];
|
|
42
42
|
const table = asTable(getTableForCollection(collection));
|
|
43
|
-
const conditions = [
|
|
43
|
+
const conditions = [
|
|
44
|
+
inArray(documentIdColumn(collection, table), ids),
|
|
45
|
+
];
|
|
44
46
|
if (softDelete !== false && table.deletedAt) {
|
|
45
47
|
conditions.push(sql `${table.deletedAt} IS NULL`);
|
|
46
48
|
}
|
|
@@ -61,7 +63,9 @@ export const fetchFilteredRowsByIds = async (db, mapData, ids) => {
|
|
|
61
63
|
const tableRef = getTableForCollection(mapData.collection);
|
|
62
64
|
const table = asTable(tableRef);
|
|
63
65
|
const { sqlWhere, postFilters } = partitionFilters(mapData.collection, table, mapData.filters, mapData.defaultFilter, mapData.softDelete);
|
|
64
|
-
const conditions = [
|
|
66
|
+
const conditions = [
|
|
67
|
+
inArray(documentIdColumn(mapData.collection, table), ids),
|
|
68
|
+
];
|
|
65
69
|
if (sqlWhere) {
|
|
66
70
|
conditions.push(sqlWhere);
|
|
67
71
|
}
|
|
@@ -320,7 +324,7 @@ export const executeFind = async (db, collection, mapData, id, ignoreSoftDelete
|
|
|
320
324
|
const table = asTable(tableRef);
|
|
321
325
|
const columns = getTableColumns(tableRef);
|
|
322
326
|
const computedSelect = buildComputedSelect(mapData, tableRef);
|
|
323
|
-
const conditions = [eq(table
|
|
327
|
+
const conditions = [eq(documentIdColumn(collection, table), id)];
|
|
324
328
|
if (!ignoreSoftDelete && mapData.softDelete !== false && table.deletedAt) {
|
|
325
329
|
conditions.push(sql `${table.deletedAt} IS NULL`);
|
|
326
330
|
}
|
|
@@ -438,7 +442,7 @@ export const deleteRelationsFor = async (db, startId, relation) => {
|
|
|
438
442
|
const vertexTable = asTable(vertexTableRef);
|
|
439
443
|
await db
|
|
440
444
|
.delete(vertexTableRef)
|
|
441
|
-
.where(eq(
|
|
445
|
+
.where(eq(documentIdColumn(relation.mapping.collection, vertexTable), vertexId));
|
|
442
446
|
}
|
|
443
447
|
await db
|
|
444
448
|
.delete(edgeTableRef)
|
package/dist/db/pg/migrate.d.ts
CHANGED
|
@@ -9,11 +9,10 @@ export declare const getLatestSchemaVersion: () => string;
|
|
|
9
9
|
export declare const LEGACY_POSTGRES_BACKUP_SCHEMA_VERSION = "0007_shallow_oracle";
|
|
10
10
|
/**
|
|
11
11
|
* Schema to apply before JSONL import on restore.
|
|
12
|
-
* - Arango → first journal tag so later SQL data migrations see restored rows.
|
|
13
12
|
* - Postgres with `schemaVersion` → that tag (must still exist in this binary).
|
|
14
13
|
* - Postgres without → `0007_shallow_oracle` (pre-stamping baseline).
|
|
15
14
|
*/
|
|
16
|
-
export declare const resolveRestoreSchemaVersion: (
|
|
15
|
+
export declare const resolveRestoreSchemaVersion: (schemaVersion?: string) => string;
|
|
17
16
|
/** Apply Drizzle migrations only through `tag` (inclusive). */
|
|
18
17
|
export declare const migrateToSchemaVersion: (tag: string) => Promise<void>;
|
|
19
18
|
/**
|
package/dist/db/pg/migrate.js
CHANGED
|
@@ -54,14 +54,10 @@ const assertKnownSchemaVersion = (tag) => {
|
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
56
|
* Schema to apply before JSONL import on restore.
|
|
57
|
-
* - Arango → first journal tag so later SQL data migrations see restored rows.
|
|
58
57
|
* - Postgres with `schemaVersion` → that tag (must still exist in this binary).
|
|
59
58
|
* - Postgres without → `0007_shallow_oracle` (pre-stamping baseline).
|
|
60
59
|
*/
|
|
61
|
-
export const resolveRestoreSchemaVersion = (
|
|
62
|
-
if (databaseType === 'arango') {
|
|
63
|
-
return getFirstSchemaVersion();
|
|
64
|
-
}
|
|
60
|
+
export const resolveRestoreSchemaVersion = (schemaVersion) => {
|
|
65
61
|
if (schemaVersion) {
|
|
66
62
|
return assertKnownSchemaVersion(schemaVersion);
|
|
67
63
|
}
|
|
@@ -144,8 +140,12 @@ const isSchemaConflictError = (err) => {
|
|
|
144
140
|
const code = candidate.code;
|
|
145
141
|
// 23505 unique_violation (e.g. orphan composite type in pg_type)
|
|
146
142
|
// 42P07 duplicate_table
|
|
143
|
+
// 42701 duplicate_column (partial migrate left a column, journal did not)
|
|
147
144
|
// 3F000 invalid_schema_name (stale search_path after DROP public)
|
|
148
|
-
return code === '23505' ||
|
|
145
|
+
return (code === '23505' ||
|
|
146
|
+
code === '42P07' ||
|
|
147
|
+
code === '42701' ||
|
|
148
|
+
code === '3F000');
|
|
149
149
|
});
|
|
150
150
|
};
|
|
151
151
|
const applyMigrations = async () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { and, count, eq, exists, gte, isNull, lt, sql, } from 'drizzle-orm';
|
|
2
2
|
import { alias, QueryBuilder } from 'drizzle-orm/pg-core';
|
|
3
3
|
import { posts } from '../schema/documents.js';
|
|
4
|
-
import { entries, follows, postGroups,
|
|
4
|
+
import { entries, follows, postGroups, repost, replyTo } from '../schema/edges.js';
|
|
5
5
|
import { asTable } from '../map/registry.js';
|
|
6
6
|
const queryBuilder = new QueryBuilder();
|
|
7
7
|
const outerIdText = (table) => sql `${asTable(table).id}::text`;
|
|
@@ -17,10 +17,10 @@ const edgeOutboundCount = (edgeTable, outerTable, window) => {
|
|
|
17
17
|
}
|
|
18
18
|
return sql `(SELECT count(*)::int FROM ${edgeTable} WHERE ${and(...conditions)})`;
|
|
19
19
|
};
|
|
20
|
-
export const profileActivityScoreExpr = (outerTable, window) => sql `COALESCE(${edgeOutboundCount(entries, outerTable, window)}, 0) + COALESCE(${edgeOutboundCount(
|
|
20
|
+
export const profileActivityScoreExpr = (outerTable, window) => sql `COALESCE(${edgeOutboundCount(entries, outerTable, window)}, 0) + COALESCE(${edgeOutboundCount(follows, outerTable, window)}, 0)`;
|
|
21
21
|
export const postActivityScoreExpr = (outerTable) => {
|
|
22
22
|
const postId = outerIdText(outerTable);
|
|
23
|
-
return sql `(SELECT count(*)::int FROM ${
|
|
23
|
+
return sql `(SELECT count(*)::int FROM ${entries} WHERE ${entries.toId} = ${postId}) + (SELECT count(*)::int FROM ${replyTo} rt INNER JOIN ${posts} p ON p.id::text = rt.from_id WHERE rt.to_id = ${postId} AND p.deleted_at IS NULL) + (SELECT count(*)::int FROM ${repost} WHERE ${repost.toId} = ${postId})`;
|
|
24
24
|
};
|
|
25
25
|
export const postReplyCountExpr = (outerTable) => {
|
|
26
26
|
const replyPosts = alias(posts, 'reply_posts');
|