@openpeepshq/core 0.1.31 → 0.1.33

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.
Files changed (167) hide show
  1. package/dist/accessTokens/helpers.d.ts +2 -2
  2. package/dist/accessTokens/tokens.js +14 -7
  3. package/dist/accounts/mutations.d.ts +2 -2
  4. package/dist/analytics/cache.js +12 -7
  5. package/dist/analytics/clicks.d.ts +20 -0
  6. package/dist/analytics/clicks.js +194 -0
  7. package/dist/analytics/index.d.ts +1 -0
  8. package/dist/analytics/index.js +1 -0
  9. package/dist/analytics/metrics.d.ts +1 -0
  10. package/dist/analytics/metrics.js +5 -0
  11. package/dist/analytics/pdfReport.d.ts +1 -0
  12. package/dist/analytics/pdfReport.js +7 -5
  13. package/dist/analytics/privacy.d.ts +18 -0
  14. package/dist/analytics/privacy.js +10 -0
  15. package/dist/analytics/read.js +74 -16
  16. package/dist/analytics/report.d.ts +32 -1
  17. package/dist/analytics/report.js +9 -2
  18. package/dist/backups/index.js +13 -5
  19. package/dist/backups/metadata.d.ts +7 -0
  20. package/dist/config/defaults/community.js +0 -6
  21. package/dist/config/defaults/core.js +1 -0
  22. package/dist/config/defaults/db.d.ts +0 -2
  23. package/dist/config/defaults/db.js +0 -2
  24. package/dist/config/index.d.ts +20 -9
  25. package/dist/db/helpers.d.ts +6 -28
  26. package/dist/db/helpers.js +19 -149
  27. package/dist/db/index.d.ts +2 -0
  28. package/dist/db/index.js +4 -0
  29. package/dist/db/init.js +3 -2
  30. package/dist/db/migration/detect.d.ts +0 -3
  31. package/dist/db/migration/detect.js +0 -54
  32. package/dist/db/migration/importCollections.d.ts +1 -1
  33. package/dist/db/migration/importCollections.js +22 -6
  34. package/dist/db/migration/shared.d.ts +0 -4
  35. package/dist/db/migration/shared.js +0 -7
  36. package/dist/db/migration/transform.d.ts +2 -0
  37. package/dist/db/migration/transform.js +23 -0
  38. package/dist/db/pg/client.js +4 -0
  39. package/dist/db/pg/filters/edges.d.ts +1 -1
  40. package/dist/db/pg/filters/edges.js +1 -1
  41. package/dist/db/pg/filters/posts.d.ts +1 -0
  42. package/dist/db/pg/filters/posts.js +11 -1
  43. package/dist/db/pg/map/filters.js +5 -0
  44. package/dist/db/pg/map/relations.d.ts +1 -1
  45. package/dist/db/pg/map/relations.js +89 -41
  46. package/dist/db/pg/migrate.d.ts +23 -0
  47. package/dist/db/pg/migrate.js +87 -1
  48. package/dist/db/pg/queries/derived.d.ts +5 -0
  49. package/dist/db/pg/queries/derived.js +21 -0
  50. package/dist/db/pg/schema/analytics.d.ts +76 -0
  51. package/dist/db/pg/schema/analytics.js +11 -1
  52. package/dist/db/pg/schema/documents.d.ts +143 -0
  53. package/dist/db/pg/schema/documents.js +22 -1
  54. package/dist/db/pg/schema/edges.d.ts +1 -0
  55. package/dist/db/pg/schema/edges.js +1 -0
  56. package/dist/db/pg/schema/index.d.ts +218 -0
  57. package/dist/db/pg/sql/0005_open_power_man.sql +9 -0
  58. package/dist/db/pg/sql/0006_fine_trish_tilby.sql +8 -0
  59. package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
  60. package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
  61. package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
  62. package/dist/db/pg/sql/meta/0004_snapshot.json +1 -1
  63. package/dist/db/pg/sql/meta/0005_snapshot.json +4179 -0
  64. package/dist/db/pg/sql/meta/0006_snapshot.json +4200 -0
  65. package/dist/db/pg/sql/meta/0007_snapshot.json +4179 -0
  66. package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
  67. package/dist/db/pg/sql/meta/_journal.json +35 -0
  68. package/dist/db/replaceOrigin.d.ts +11 -0
  69. package/dist/db/replaceOrigin.js +116 -0
  70. package/dist/db/types.d.ts +0 -4
  71. package/dist/events/index.d.ts +2 -1
  72. package/dist/events/index.js +54 -33
  73. package/dist/groups/finders.d.ts +2 -2
  74. package/dist/groups/helpers.d.ts +6 -6
  75. package/dist/groups/mapping.d.ts +4 -4
  76. package/dist/groups/mapping.js +2 -2
  77. package/dist/groups/mutations.js +1 -1
  78. package/dist/inviteLinks/helpers.d.ts +4 -4
  79. package/dist/jams/cache.d.ts +1 -1
  80. package/dist/jams/cache.js +2 -1
  81. package/dist/jams/finders.d.ts +2 -1
  82. package/dist/jams/finders.js +18 -7
  83. package/dist/jams/helpers.d.ts +8 -4
  84. package/dist/jams/index.d.ts +4 -3
  85. package/dist/jams/index.js +23 -12
  86. package/dist/jams/livekit.d.ts +46 -8
  87. package/dist/jams/livekit.js +103 -21
  88. package/dist/jams/mapping.d.ts +14 -4
  89. package/dist/jams/mutations.d.ts +2 -0
  90. package/dist/jams/rtmp.d.ts +5 -0
  91. package/dist/jams/rtmp.js +8 -0
  92. package/dist/jams/token.d.ts +3 -3
  93. package/dist/jams/token.js +15 -12
  94. package/dist/jams/waitingRoom.d.ts +6 -4
  95. package/dist/jams/waitingRoom.js +33 -24
  96. package/dist/migration/index.d.ts +4 -0
  97. package/dist/migration/index.js +4 -0
  98. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
  99. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
  100. package/dist/notifications/helpers.js +6 -2
  101. package/dist/notifications/jobs.js +13 -2
  102. package/dist/notifications/push.js +11 -4
  103. package/dist/plugins/helpers.d.ts +6 -2
  104. package/dist/plugins/helpers.js +22 -10
  105. package/dist/plugins/index.d.ts +6 -1
  106. package/dist/plugins/index.js +54 -13
  107. package/dist/plugins/install.d.ts +20 -0
  108. package/dist/plugins/install.js +223 -0
  109. package/dist/plugins/state.d.ts +4 -0
  110. package/dist/plugins/state.js +29 -0
  111. package/dist/posts/contextClosure.d.ts +2 -1
  112. package/dist/posts/contextClosure.js +6 -1
  113. package/dist/posts/conversationQueries.d.ts +23 -0
  114. package/dist/posts/conversationQueries.js +135 -0
  115. package/dist/posts/eventAgenda.d.ts +165 -0
  116. package/dist/posts/eventAgenda.js +120 -0
  117. package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
  118. package/dist/posts/eventOccurrenceJobs.js +23 -0
  119. package/dist/posts/eventOccurrences.d.ts +4 -0
  120. package/dist/posts/eventOccurrences.js +40 -0
  121. package/dist/posts/finders.d.ts +39 -13
  122. package/dist/posts/finders.js +51 -66
  123. package/dist/posts/helpers/filters.js +1 -1
  124. package/dist/posts/helpers/index.d.ts +120 -34
  125. package/dist/posts/helpers/index.js +34 -21
  126. package/dist/posts/index.d.ts +4 -0
  127. package/dist/posts/index.js +4 -0
  128. package/dist/posts/mapping.d.ts +454 -0
  129. package/dist/posts/mapping.js +43 -9
  130. package/dist/posts/mutations.d.ts +4 -2
  131. package/dist/posts/mutations.js +49 -16
  132. package/dist/posts/rsvpConfirmationEmail.js +2 -1
  133. package/dist/posts/unseenCounts.d.ts +12 -0
  134. package/dist/posts/unseenCounts.js +98 -0
  135. package/dist/profiles/cache.d.ts +5 -1
  136. package/dist/profiles/cache.js +27 -1
  137. package/dist/profiles/helpers.d.ts +5 -5
  138. package/dist/profiles/index.d.ts +1 -0
  139. package/dist/profiles/index.js +1 -0
  140. package/dist/profiles/mapping.d.ts +45 -4
  141. package/dist/profiles/mapping.js +24 -0
  142. package/dist/profiles/mutations.js +12 -14
  143. package/dist/pushSubscriptions/helpers.d.ts +2 -2
  144. package/dist/pushSubscriptions/mutations.js +13 -1
  145. package/dist/reports/helpers.d.ts +6 -6
  146. package/dist/reports/helpers.js +2 -1
  147. package/dist/reports/mapping.js +6 -2
  148. package/dist/roles/defaults.js +1 -0
  149. package/dist/roles/mutations.d.ts +3 -3
  150. package/dist/roles/mutations.js +5 -3
  151. package/dist/server/index.d.ts +15 -7
  152. package/dist/server/index.js +15 -8
  153. package/dist/session/index.d.ts +28 -0
  154. package/dist/session/index.js +79 -0
  155. package/dist/stats/finders.d.ts +1912 -362
  156. package/dist/stats/mapping.d.ts +26 -5
  157. package/package.json +7 -12
  158. package/dist/db/arango.d.ts +0 -2
  159. package/dist/db/arango.js +0 -110
  160. package/dist/db/migration/autoMigrate.d.ts +0 -2
  161. package/dist/db/migration/autoMigrate.js +0 -111
  162. package/dist/db/migration/cli.d.ts +0 -1
  163. package/dist/db/migration/cli.js +0 -56
  164. package/dist/db/migration/exportArango.d.ts +0 -4
  165. package/dist/db/migration/exportArango.js +0 -80
  166. package/dist/db/replaceHostname.d.ts +0 -1
  167. package/dist/db/replaceHostname.js +0 -88
@@ -0,0 +1,120 @@
1
+ import { and, asc, desc, eq, gt, gte, isNotNull, isNull, lte, or, sql, } from 'drizzle-orm';
2
+ import { canReadPost } from './helpers/filters.js';
3
+ import { transformPost } from './helpers/index.js';
4
+ import { allpeepDb } from '../db/index.js';
5
+ import { capabilitiesConfig } from '../config/index.js';
6
+ import { normalizeComputedDatetime } from '../db/pg/mappers.js';
7
+ import { eventOccurrences, posts } from '../db/pg/schema/index.js';
8
+ import { postGroups } from '../db/pg/schema/edges.js';
9
+ import { postHasYesOrMaybeRsvpExpr } from '../db/pg/queries/index.js';
10
+ import { postFilters } from '../db/pg/filters/index.js';
11
+ import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
12
+ import { postsMappingForProfile } from './mapping.js';
13
+ const occurrenceTimeFilter = (window, now) => {
14
+ const start = eventOccurrences.start;
15
+ const end = eventOccurrences.end;
16
+ if (window === 'upcoming') {
17
+ return or(gt(start, now), and(isNotNull(end), gt(end, now)));
18
+ }
19
+ if (window === 'current') {
20
+ return and(lte(start, now), or(isNull(end), gte(end, now)));
21
+ }
22
+ return sql `COALESCE(${end}, ${start}) < ${now}`;
23
+ };
24
+ const eventAgendaConditions = ({ window, now, jamOnly, mine, groupId, profileId, }) => {
25
+ const conditions = [
26
+ isNull(posts.deletedAt),
27
+ eq(posts.type, 'event'),
28
+ eq(eventOccurrences.cancelled, false),
29
+ occurrenceTimeFilter(window, now),
30
+ ];
31
+ if (jamOnly) {
32
+ conditions.push(isNotNull(sql `${posts.body}->'jam'`));
33
+ }
34
+ if (mine && profileId) {
35
+ conditions.push(or(eq(posts.creatorId, profileId), postFilters.isJamModerator(profileId).where, postHasYesOrMaybeRsvpExpr(posts, profileId)));
36
+ }
37
+ if (groupId) {
38
+ conditions.push(sql `EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text AND ${postGroups.toId} = ${groupId})`);
39
+ }
40
+ return conditions;
41
+ };
42
+ // One row per event: a daily series would otherwise fill the first page.
43
+ export const eventAgendaOccurrenceQuery = (db, args) => {
44
+ const pickOrder = args.window === 'past'
45
+ ? desc(eventOccurrences.start)
46
+ : asc(eventOccurrences.start);
47
+ const distinctOccurrences = db
48
+ .selectDistinctOn([eventOccurrences.postId], {
49
+ postId: eventOccurrences.postId,
50
+ recurrenceId: eventOccurrences.recurrenceId,
51
+ start: eventOccurrences.start,
52
+ end: eventOccurrences.end,
53
+ })
54
+ .from(eventOccurrences)
55
+ .innerJoin(posts, eq(posts.id, eventOccurrences.postId))
56
+ .where(and(...eventAgendaConditions(args)))
57
+ .orderBy(eventOccurrences.postId, pickOrder)
58
+ .as('event_agenda');
59
+ return db
60
+ .select({
61
+ postId: distinctOccurrences.postId,
62
+ recurrenceId: distinctOccurrences.recurrenceId,
63
+ start: distinctOccurrences.start,
64
+ end: distinctOccurrences.end,
65
+ })
66
+ .from(distinctOccurrences)
67
+ .orderBy(args.window === 'past'
68
+ ? desc(distinctOccurrences.start)
69
+ : asc(distinctOccurrences.start))
70
+ .limit(args.limit)
71
+ .offset(args.offset);
72
+ };
73
+ const loadPostsByIds = async (ids, authData) => {
74
+ if (ids.length === 0)
75
+ return new Map();
76
+ const profile = authData.profile;
77
+ const { db } = await allpeepDb();
78
+ const mapData = postsMappingForProfile(profile).data();
79
+ const rows = await fetchRowsByIds(db, mapData.collection, ids, mapData.softDelete);
80
+ const hydrated = (await hydrateMapData(db, mapData, rows));
81
+ const config = await capabilitiesConfig();
82
+ const readable = canReadPost(config, authData);
83
+ const entries = await Promise.all(hydrated.map(async (post) => {
84
+ const transformed = await transformPost(post, profile);
85
+ return readable(transformed) ? transformed : undefined;
86
+ }));
87
+ return new Map(entries
88
+ .filter((post) => !!post)
89
+ .map((post) => [post.id, post]));
90
+ };
91
+ export const listEventAgenda = async (authData, window, { offset = 0, limit = 100, jamOnly = false, mine = false, groupId, } = {}) => {
92
+ var _a;
93
+ const { db } = await allpeepDb();
94
+ const now = new Date().toISOString();
95
+ const rows = await eventAgendaOccurrenceQuery(db, {
96
+ window,
97
+ now,
98
+ offset,
99
+ limit,
100
+ jamOnly,
101
+ mine,
102
+ groupId,
103
+ profileId: (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.id,
104
+ });
105
+ const postsById = await loadPostsByIds([...new Set(rows.map((row) => row.postId))], authData);
106
+ return rows.flatMap((row) => {
107
+ const post = postsById.get(row.postId);
108
+ if (!post)
109
+ return [];
110
+ const occurrenceRecurrenceId = normalizeComputedDatetime(row.recurrenceId);
111
+ const occurrenceStart = normalizeComputedDatetime(row.start);
112
+ const occurrenceEnd = normalizeComputedDatetime(row.end);
113
+ if (!occurrenceRecurrenceId || !occurrenceStart)
114
+ return [];
115
+ return [
116
+ Object.assign(Object.assign(Object.assign({}, post), { occurrenceRecurrenceId,
117
+ occurrenceStart }), (occurrenceEnd ? { occurrenceEnd } : {})),
118
+ ];
119
+ });
120
+ };
@@ -0,0 +1,4 @@
1
+ export declare const EVENT_OCCURRENCE_CRON = "0 4 * * *";
2
+ declare const eventOccurrenceQueue: () => import("bullmq").Queue, eventOccurrenceWorker: () => import("bullmq").Worker;
3
+ export declare const ensureEventOccurrenceSchedule: () => Promise<void>;
4
+ export { eventOccurrenceQueue, eventOccurrenceWorker };
@@ -0,0 +1,23 @@
1
+ import { queueAndWorker } from '../jobs/index.js';
2
+ import { logger } from '../log/index.js';
3
+ import { rebuildRecurringEventOccurrences } from './eventOccurrences.js';
4
+ const log = logger('app:posts:eventOccurrences');
5
+ const QUEUE_NAME = 'event-occurrences';
6
+ const SCHEDULER_ID = 'event-occurrences-daily';
7
+ const JOB_NAME = 'rebuild-recurring';
8
+ export const EVENT_OCCURRENCE_CRON = '0 4 * * *';
9
+ const [eventOccurrenceQueue, eventOccurrenceWorker] = queueAndWorker(QUEUE_NAME, async () => {
10
+ const rebuilt = await rebuildRecurringEventOccurrences();
11
+ log.info(`Rebuilt occurrence index for ${rebuilt} recurring events`);
12
+ }, {
13
+ defaultJobOptions: {
14
+ removeOnComplete: { count: 10 },
15
+ removeOnFail: { age: 86400 * 14, count: 50 },
16
+ },
17
+ });
18
+ export const ensureEventOccurrenceSchedule = async () => {
19
+ const queue = eventOccurrenceQueue();
20
+ await queue.upsertJobScheduler(SCHEDULER_ID, { pattern: EVENT_OCCURRENCE_CRON }, { name: JOB_NAME, data: { type: 'rebuild' } });
21
+ log.info(`Event occurrence schedule registered: cron="${EVENT_OCCURRENCE_CRON}"`);
22
+ };
23
+ export { eventOccurrenceQueue, eventOccurrenceWorker };
@@ -0,0 +1,4 @@
1
+ import type { Event } from '@openpeepshq/common/types';
2
+ export declare const rebuildEventOccurrences: (postId: string, event: Event) => Promise<void>;
3
+ export declare const clearEventOccurrences: (postId: string) => Promise<void>;
4
+ export declare const rebuildRecurringEventOccurrences: () => Promise<number>;
@@ -0,0 +1,40 @@
1
+ import { and, eq, isNotNull, isNull, sql } from 'drizzle-orm';
2
+ import { uuidv7 } from 'uuidv7';
3
+ import { occurrencesForIndex } from '@openpeepshq/common/lib';
4
+ import { database } from '../db/index.js';
5
+ import { eventOccurrences, posts } from '../db/pg/schema/index.js';
6
+ export const rebuildEventOccurrences = async (postId, event) => {
7
+ const db = await database();
8
+ await db.delete(eventOccurrences).where(eq(eventOccurrences.postId, postId));
9
+ const rows = occurrencesForIndex(event);
10
+ if (rows.length === 0)
11
+ return;
12
+ await db.insert(eventOccurrences).values(rows.map((row) => ({
13
+ id: uuidv7(),
14
+ postId,
15
+ recurrenceId: row.recurrenceId,
16
+ start: row.start,
17
+ end: row.end,
18
+ cancelled: row.cancelled,
19
+ })));
20
+ };
21
+ export const clearEventOccurrences = async (postId) => {
22
+ const db = await database();
23
+ await db.delete(eventOccurrences).where(eq(eventOccurrences.postId, postId));
24
+ };
25
+ export const rebuildRecurringEventOccurrences = async () => {
26
+ const db = await database();
27
+ const rows = await db
28
+ .select({ id: posts.id, body: posts.body })
29
+ .from(posts)
30
+ .where(and(eq(posts.type, 'event'), isNull(posts.deletedAt), isNotNull(sql `${posts.body}->'recurrence'`)));
31
+ let rebuilt = 0;
32
+ for (const row of rows) {
33
+ const event = row.body;
34
+ if ((event === null || event === void 0 ? void 0 : event.type) !== 'event' || !event.start)
35
+ continue;
36
+ await rebuildEventOccurrences(row.id, event);
37
+ rebuilt += 1;
38
+ }
39
+ return rebuilt;
40
+ };
@@ -2,6 +2,8 @@ import { AuthorizationData, PostWithMeta, Post, PostType, Profile, DbPost, DbBas
2
2
  import { ProfileWithMeta } from '@openpeepshq/common/types';
3
3
  import type { Mapping, ObjectSort, PgFilter } from '../db/pg/map';
4
4
  export declare const findPost: (id: string, authData?: AuthorizationData) => Promise<PostWithMeta | undefined>;
5
+ /** Lean post load for capability checks (no nested reply/repost). */
6
+ export declare const findPostsForAuth: (ids: string[], authData?: AuthorizationData) => Promise<PostWithMeta[]>;
5
7
  export declare const postContext: (authData: AuthorizationData, id: string, depth: number, direction: "ancestors" | "descendents", contextMapping?: Mapping<DbPost>) => Promise<PostWithMeta[]>;
6
8
  export declare const descendents: (authData: AuthorizationData, post: PostWithMeta, depth: number, contextMapping?: Mapping<DbPost>) => Promise<PostWithMeta[]>;
7
9
  export declare const ancestors: (authData: AuthorizationData, post: PostWithMeta, depth: number, contextMapping?: Mapping<DbPost>) => Promise<PostWithMeta[]>;
@@ -17,7 +19,7 @@ export declare const baseFeed: ({ start, sort, profile, }: {
17
19
  }) => Mapping<DbPost>;
18
20
  export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
19
21
  type: "note" | "question" | "event" | "article";
20
- visibility: "direct" | "group" | "local" | "report" | "public" | "unlisted" | "private";
22
+ visibility: "local" | "group" | "report" | "public" | "unlisted" | "private" | "direct";
21
23
  creatorId: string;
22
24
  capabilitiesNeeded?: string[] | undefined;
23
25
  data?: {
@@ -42,7 +44,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
42
44
  };
43
45
  description?: string | undefined;
44
46
  blurhash?: string | undefined;
45
- status?: "ready" | "failed" | "processing" | undefined;
47
+ status?: "failed" | "processing" | "ready" | undefined;
46
48
  error?: string | undefined;
47
49
  }[] | undefined;
48
50
  customEmojis?: {
@@ -79,7 +81,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
79
81
  };
80
82
  description?: string | undefined;
81
83
  blurhash?: string | undefined;
82
- status?: "ready" | "failed" | "processing" | undefined;
84
+ status?: "failed" | "processing" | "ready" | undefined;
83
85
  error?: string | undefined;
84
86
  }[] | undefined;
85
87
  customEmojis?: {
@@ -117,7 +119,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
117
119
  };
118
120
  description?: string | undefined;
119
121
  blurhash?: string | undefined;
120
- status?: "ready" | "failed" | "processing" | undefined;
122
+ status?: "failed" | "processing" | "ready" | undefined;
121
123
  error?: string | undefined;
122
124
  }[] | undefined;
123
125
  customEmojis?: {
@@ -156,6 +158,27 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
156
158
  } | undefined;
157
159
  } | undefined;
158
160
  url?: string | undefined;
161
+ recurrence?: {
162
+ freq: "DAILY" | "WEEKLY" | "MONTHLY";
163
+ interval?: number | undefined;
164
+ byDay?: ("MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU")[] | undefined;
165
+ until?: string | undefined;
166
+ count?: number | undefined;
167
+ } | undefined;
168
+ exceptions?: {
169
+ recurrenceId: string;
170
+ cancelled?: boolean | undefined;
171
+ start?: string | undefined;
172
+ end?: string | undefined;
173
+ physicalLocation?: {
174
+ text: string;
175
+ coordinates?: {
176
+ lat: number;
177
+ lng: number;
178
+ alt?: number | undefined;
179
+ } | undefined;
180
+ } | undefined;
181
+ }[] | undefined;
159
182
  } | {
160
183
  type: "article";
161
184
  content?: string | undefined;
@@ -178,7 +201,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
178
201
  };
179
202
  description?: string | undefined;
180
203
  blurhash?: string | undefined;
181
- status?: "ready" | "failed" | "processing" | undefined;
204
+ status?: "failed" | "processing" | "ready" | undefined;
182
205
  error?: string | undefined;
183
206
  }[] | undefined;
184
207
  customEmojis?: {
@@ -235,20 +258,23 @@ export declare const listMyFeed: (authData: AuthorizationData, { start, limit }?
235
258
  start?: string;
236
259
  limit?: number;
237
260
  }) => Promise<PostWithMeta[]>;
238
- export declare const listUpcomingEventsFeed: (authData: AuthorizationData, { offset, limit, filter, }?: {
261
+ export declare const listUpcomingEventsFeed: (authData: AuthorizationData, { offset, limit, jamOnly, mine, }?: {
239
262
  offset?: number;
240
263
  limit?: number;
241
- filter?: PgFilter<DbBasePost>;
264
+ jamOnly?: boolean;
265
+ mine?: boolean;
242
266
  }) => Promise<PostWithMeta[]>;
243
- export declare const listCurrentEventsFeed: (authData: AuthorizationData, { offset, limit, filter, }?: {
267
+ export declare const listCurrentEventsFeed: (authData: AuthorizationData, { offset, limit, jamOnly, mine, }?: {
244
268
  offset?: number;
245
269
  limit?: number;
246
- filter?: PgFilter<DbBasePost>;
270
+ jamOnly?: boolean;
271
+ mine?: boolean;
247
272
  }) => Promise<PostWithMeta[]>;
248
- export declare const listPastEventsFeed: (authData: AuthorizationData, { offset, limit, filter, }?: {
273
+ export declare const listPastEventsFeed: (authData: AuthorizationData, { offset, limit, jamOnly, mine, }?: {
249
274
  offset?: number;
250
275
  limit?: number;
251
- filter?: PgFilter<DbBasePost>;
276
+ jamOnly?: boolean;
277
+ mine?: boolean;
252
278
  }) => Promise<PostWithMeta[]>;
253
279
  export declare const listMyUpcomingEventsFeed: (authData: AuthorizationData, { offset, limit }?: {
254
280
  offset?: number;
@@ -294,5 +320,5 @@ export declare const getPostContext: (post: PostWithMeta, authData: Authorizatio
294
320
  ancestors: PostWithMeta[];
295
321
  descendants: PostWithMeta[];
296
322
  }>;
297
- export declare const mentions: (post: Post, profile: Profile) => Promise<{} | undefined>;
298
- export declare const audience: (post: Post, profile: Profile) => Promise<{} | undefined>;
323
+ export declare const mentions: (post: Post, profile: Profile) => Promise<Record<string, unknown> | undefined>;
324
+ export declare const audience: (post: Post, profile: Profile) => Promise<Record<string, unknown> | undefined>;
@@ -1,7 +1,7 @@
1
1
  import { allpeepDb, collectionInfos } from '../db/index.js';
2
2
  import { edgeFilters, postFilters } from '../db/pg/filters/index.js';
3
- import { contextRelation, conversationLeavesMappingForProfile, postContextMappingForProfile, postsMappingForProfile, repostsOfPostRelationForProfile, postIdsMapping, } from './mapping.js';
4
- import { audienceConnectionFinder, currentEventsFilter, jamFilter, localFeedFilter, mentionsConnectionFinder, myEventsFilter, myFeedFilter, myFeedGroupMembershipFilter, pastEventsFilter, toFilteredPostsList, transformPost, upcomingEventsFilter, } from './helpers/index.js';
3
+ import { contextRelation, conversationLeavesMappingForProfile, postContextMappingForProfile, postsAuthMapping, postsMappingForProfile, repostsOfPostRelationForProfile, postIdsMapping, } from './mapping.js';
4
+ import { audienceConnectionFinder, localFeedFilter, mentionsConnectionFinder, myFeedFilter, myFeedGroupMembershipFilter, toFilteredPostsList, transformPost, } from './helpers/index.js';
5
5
  import { addQuerySort, addStart, sortOldestFirst } from '../db/helpers.js';
6
6
  import { sorts } from '../db/pg/queries/index.js';
7
7
  import { findHashtagByTag, hashtagsMapping } from '../hashtags/index.js';
@@ -10,6 +10,10 @@ import { groupsMapping } from '../groups/mapping.js';
10
10
  import { profilesMapping } from '../profiles/mapping.js';
11
11
  import { CONTEXT_NODE_CAP, loadReplyContextPosts } from './contextClosure.js';
12
12
  import { withSpan } from '../performance/index.js';
13
+ import { queryUnseenPostCounts } from './unseenCounts.js';
14
+ import { getConversationThread } from './conversationQueries.js';
15
+ import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
16
+ import { listEventAgenda } from './eventAgenda.js';
13
17
  /**
14
18
  * Throws if the given `authData` does not include a profile.
15
19
  *
@@ -29,6 +33,23 @@ export const findPost = async (id, authData) => {
29
33
  .then(({ db }) => postsMappingForProfile(profile).find(db, id))
30
34
  .then((post) => (post ? transformPost(post, profile) : undefined));
31
35
  };
36
+ /** Lean post load for capability checks (no nested reply/repost). */
37
+ export const findPostsForAuth = async (ids, authData) => {
38
+ if (ids.length === 0)
39
+ return [];
40
+ const profile = authData === null || authData === void 0 ? void 0 : authData.profile;
41
+ const { db } = await allpeepDb();
42
+ const mapData = postsAuthMapping.data();
43
+ const rows = await fetchRowsByIds(db, mapData.collection, ids, mapData.softDelete);
44
+ const hydrated = (await hydrateMapData(db, mapData, rows));
45
+ const byId = new Map(await Promise.all(hydrated.map(async (post) => {
46
+ const transformed = await transformPost(post, profile);
47
+ return [transformed.id, transformed];
48
+ })));
49
+ return ids
50
+ .map((id) => byId.get(id))
51
+ .filter((post) => !!post);
52
+ };
32
53
  export const postContext = async (authData, id, depth, direction, contextMapping) => {
33
54
  const profile = authData.profile;
34
55
  const mapping = postsMappingForProfile(profile);
@@ -102,25 +123,8 @@ export const getUnseenPostCounts = async (authData) => withSpan('unseen.counts',
102
123
  const groupIds = profile.memberships
103
124
  .map((membership) => membership.group.id)
104
125
  .filter((groupId) => typeof groupId === 'string');
105
- const groupCounts = Object.fromEntries(groupIds.map((groupId) => [groupId, 0]));
106
- await Promise.all(groupIds.map(async (groupId) => {
107
- const posts = await listPostsByGroup(authData, groupId, {
108
- limit: 9999,
109
- });
110
- groupCounts[groupId] = posts.filter((post) => post.seen === false && post.profile.id !== profile.id).length;
111
- }));
112
- const conversations = await Promise.all((await listConversationLeaves(authData)).map((post) => getConversationByEnd(post, authData)));
113
- const uniqueConversations = Array.from(new Map(conversations
114
- .filter((conversation) => conversation[0])
115
- .map((conversation) => [conversation[0].id, conversation])).values());
116
- const direct = Object.fromEntries(uniqueConversations
117
- .map((conversation) => {
118
- const conversationId = conversation[0].id;
119
- const unread = conversation.filter((post) => post.seen === false && post.profile.id !== profile.id).length;
120
- return [conversationId, unread];
121
- })
122
- .filter(([, unread]) => unread > 0));
123
- return { groups: groupCounts, direct };
126
+ const { db } = await allpeepDb();
127
+ return queryUnseenPostCounts(db, profile.id, groupIds);
124
128
  });
125
129
  export const listPostsByType = async (authData, type, { start, limit = 100, filter, } = {
126
130
  limit: 100,
@@ -161,85 +165,66 @@ export const listPostsByGroup = async (authData, groupId, { start, limit = 100,
161
165
  .data(),
162
166
  }), { authData, limit });
163
167
  });
164
- export const listLocalFeed = async (authData, { start, limit = 100 } = { limit: 100 }) => withSpan('feed.local', () => toFilteredPostsList(baseFeed({ start, profile: authData.profile }).filter(localFeedFilter(authData.profile)), { authData, limit }));
168
+ export const listLocalFeed = async (authData, { start, limit = 100 } = { limit: 100 }) => withSpan('feed.local', () => toFilteredPostsList(baseFeed({ start, profile: authData.profile }).filter(localFeedFilter()), { authData, limit }));
165
169
  export const listMyFeed = async (authData, { start, limit = 100 } = { limit: 100 }) => {
166
170
  const profile = requireProfile(authData);
167
171
  return withSpan('feed.my', () => toFilteredPostsList(baseFeed({ start, profile }).filter(myFeedFilter(profile)), { authData, limit, filters: [myFeedGroupMembershipFilter(profile)] }));
168
172
  };
169
- export const listUpcomingEventsFeed = async (authData, { offset, limit = 100, filter, } = {
173
+ export const listUpcomingEventsFeed = async (authData, { offset, limit = 100, jamOnly, mine, } = {
170
174
  limit: 100,
171
- }) => toFilteredPostsList(baseEventsFeed(authData.profile)
172
- .filter(upcomingEventsFilter())
173
- .filter(filter), { authData, limit, offset });
174
- export const listCurrentEventsFeed = async (authData, { offset, limit = 100, filter, } = {
175
+ }) => listEventAgenda(authData, 'upcoming', { offset, limit, jamOnly, mine });
176
+ export const listCurrentEventsFeed = async (authData, { offset, limit = 100, jamOnly, mine, } = {
175
177
  limit: 100,
176
- }) => toFilteredPostsList(baseEventsFeed(authData.profile)
177
- .filter(currentEventsFilter())
178
- .filter(filter), { authData, limit, offset });
179
- export const listPastEventsFeed = async (authData, { offset, limit = 100, filter, } = {
178
+ }) => listEventAgenda(authData, 'current', { offset, limit, jamOnly, mine });
179
+ export const listPastEventsFeed = async (authData, { offset, limit = 100, jamOnly, mine, } = {
180
180
  limit: 100,
181
- }) => toFilteredPostsList(baseEventsFeed(authData.profile)
182
- .sort(sorts.eventStartDesc)
183
- .filter(pastEventsFilter())
184
- .filter(filter), { authData, limit, offset });
181
+ }) => listEventAgenda(authData, 'past', { offset, limit, jamOnly, mine });
185
182
  export const listMyUpcomingEventsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listUpcomingEventsFeed(authData, {
186
183
  offset,
187
- filter: myEventsFilter(requireProfile(authData)),
184
+ mine: true,
188
185
  limit,
189
186
  });
190
187
  export const listMyCurrentEventsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listCurrentEventsFeed(authData, {
191
188
  offset,
192
- filter: myEventsFilter(requireProfile(authData)),
189
+ mine: true,
193
190
  limit,
194
191
  });
195
192
  export const listMyPastEventsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listPastEventsFeed(authData, {
196
193
  offset,
197
- filter: myEventsFilter(requireProfile(authData)),
194
+ mine: true,
198
195
  limit,
199
196
  });
200
- export const listUpcomingJamsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listUpcomingEventsFeed(authData, { offset, filter: jamFilter, limit });
201
- export const listPastJamsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listPastEventsFeed(authData, { offset, filter: jamFilter, limit });
197
+ export const listUpcomingJamsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listUpcomingEventsFeed(authData, { offset, jamOnly: true, limit });
198
+ export const listPastJamsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listPastEventsFeed(authData, { offset, jamOnly: true, limit });
202
199
  export const listMyPastJamsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listPastEventsFeed(authData, {
203
200
  offset,
204
- filter: {
205
- operator: '&&',
206
- predicates: [myEventsFilter(requireProfile(authData)), jamFilter],
207
- },
201
+ jamOnly: true,
202
+ mine: true,
208
203
  limit,
209
204
  });
210
205
  export const listMyUpcomingJamsFeed = async (authData, { offset, limit = 100 } = { limit: 100 }) => listUpcomingEventsFeed(authData, {
211
206
  offset,
212
- filter: {
213
- operator: '&&',
214
- predicates: [myEventsFilter(requireProfile(authData)), jamFilter],
215
- },
207
+ jamOnly: true,
208
+ mine: true,
216
209
  limit,
217
210
  });
218
- const baseGroupEventsFeed = async (authData, groupId, { filter, sort } = {}) => {
211
+ export const listUpcomingGroupEventsFeed = async (authData, groupId, { offset, limit = 100 } = { limit: 100 }) => {
219
212
  const group = await findGroup(groupId);
220
213
  if (!group) {
221
214
  throw new Error(`Group ${groupId} not found`);
222
215
  }
223
- const profile = authData.profile;
224
- return groupsMapping.relationsFrom(group, {
225
- alias: 'posts',
226
- edgeCollection: collectionInfos.postGroupsCollection.name,
227
- direction: 'INBOUND',
228
- skipEdge: true,
229
- cardinality: 'many',
230
- mapping: baseEventsFeed(profile).filter(filter).sort(sort).data(),
231
- });
216
+ return listEventAgenda(authData, 'upcoming', { offset, limit, groupId });
217
+ };
218
+ export const listPastGroupEventsFeed = async (authData, groupId, { offset, limit = 100 } = { limit: 100 }) => {
219
+ const group = await findGroup(groupId);
220
+ if (!group) {
221
+ throw new Error(`Group ${groupId} not found`);
222
+ }
223
+ return listEventAgenda(authData, 'past', { offset, limit, groupId });
232
224
  };
233
- export const listUpcomingGroupEventsFeed = async (authData, groupId, { offset, limit = 100 } = { limit: 100 }) => toFilteredPostsList(await baseGroupEventsFeed(authData, groupId, {
234
- filter: upcomingEventsFilter(),
235
- }), { authData, limit, offset });
236
- export const listPastGroupEventsFeed = async (authData, groupId, { offset, limit = 100 } = { limit: 100 }) => toFilteredPostsList(await baseGroupEventsFeed(authData, groupId, {
237
- filter: pastEventsFilter(),
238
- sort: sorts.eventStartDesc,
239
- }), { authData, limit, offset });
240
225
  export const reposts = async (post, authData) => toFilteredPostsList(postsMappingForProfile(authData.profile).relationsFrom(post, repostsOfPostRelationForProfile(authData.profile)), { authData });
241
226
  export const getConversationByEnd = async (post, authData) => ancestors(authData, post, 9999, sortOldestFirst(postsMappingForProfile(authData.profile))).then((conversation) => [...conversation, post]);
242
- export const getConversationByStart = async (post, authData) => descendents(authData, post, 9999, sortOldestFirst(postsMappingForProfile(authData.profile))).then((conversation) => [post, ...conversation]);
227
+ export const getConversationByStart = async (post, authData) => getConversationThread(post, authData);
243
228
  /** Full ancestor/descendant trees for post detail (CTE + lean mapping). */
244
229
  export const getPostContext = async (post, authData) => {
245
230
  const mapping = sortOldestFirst(postContextMappingForProfile(authData.profile));
@@ -1,6 +1,6 @@
1
1
  import { postWithMetaSchema, } from '@openpeepshq/common/types';
2
2
  import { combine, eventTimeFilters, postFilters } from '../../db/pg/filters/index.js';
3
- import { checkCapabilities, getPostCapabilities } from '@openpeepshq/common/lib';
3
+ import { checkCapabilities, getPostCapabilities, } from '@openpeepshq/common/lib';
4
4
  export const ownPostsFilter = (profile) => ({
5
5
  matches: {
6
6
  creatorId: profile.id,