@openpeepshq/core 0.1.33 → 0.1.35

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 (297) hide show
  1. package/dist/accessTokens/finders.js +5 -6
  2. package/dist/accessTokens/mutations.js +1 -1
  3. package/dist/accessTokens/tokens.js +8 -11
  4. package/dist/accounts/helpers.js +6 -2
  5. package/dist/accounts/mutations.js +36 -33
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +17 -12
  9. package/dist/analytics/dateRange.js +3 -5
  10. package/dist/analytics/jobs.js +3 -4
  11. package/dist/analytics/pdfReport.js +45 -61
  12. package/dist/analytics/privacy.js +1 -1
  13. package/dist/analytics/read.js +164 -140
  14. package/dist/analytics/report.d.ts +22 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +82 -25
  18. package/dist/backups/metadata.d.ts +2 -3
  19. package/dist/backups/metadata.js +6 -2
  20. package/dist/config/db.js +2 -4
  21. package/dist/config/defaults/capabilities.js +13 -2
  22. package/dist/config/defaults/community.js +8 -3
  23. package/dist/config/defaults/core.d.ts +1 -1
  24. package/dist/config/defaults/core.js +16 -8
  25. package/dist/config/index.d.ts +22 -0
  26. package/dist/config/index.js +15 -11
  27. package/dist/db/explorer/query.js +9 -8
  28. package/dist/db/explorer/sql.js +8 -8
  29. package/dist/db/helpers.d.ts +1 -0
  30. package/dist/db/helpers.js +25 -7
  31. package/dist/db/index.d.ts +1 -1
  32. package/dist/db/index.js +1 -0
  33. package/dist/db/init.js +2 -3
  34. package/dist/db/migration/importCollections.d.ts +14 -9
  35. package/dist/db/migration/importCollections.js +121 -174
  36. package/dist/db/migration/shared.d.ts +2 -33
  37. package/dist/db/migration/shared.js +17 -87
  38. package/dist/db/pg/client.js +4 -7
  39. package/dist/db/pg/collections.d.ts +2 -2
  40. package/dist/db/pg/collections.js +2 -2
  41. package/dist/db/pg/filters/index.js +1 -1
  42. package/dist/db/pg/filters/posts.d.ts +12 -0
  43. package/dist/db/pg/filters/posts.js +30 -4
  44. package/dist/db/pg/filters/profiles.d.ts +1 -0
  45. package/dist/db/pg/filters/profiles.js +2 -1
  46. package/dist/db/pg/helpers.js +2 -14
  47. package/dist/db/pg/map/filters.js +40 -10
  48. package/dist/db/pg/map/helpers.js +5 -1
  49. package/dist/db/pg/map/index.js +46 -51
  50. package/dist/db/pg/map/mutations.js +65 -25
  51. package/dist/db/pg/map/registry.d.ts +5 -0
  52. package/dist/db/pg/map/registry.js +133 -56
  53. package/dist/db/pg/map/relations.js +76 -68
  54. package/dist/db/pg/map/search.js +15 -37
  55. package/dist/db/pg/mappers.js +13 -7
  56. package/dist/db/pg/migrate.d.ts +1 -2
  57. package/dist/db/pg/migrate.js +8 -9
  58. package/dist/db/pg/queries/activity.js +5 -5
  59. package/dist/db/pg/queries/derived.js +8 -12
  60. package/dist/db/pg/queries/sorts.d.ts +1 -0
  61. package/dist/db/pg/queries/sorts.js +4 -0
  62. package/dist/db/pg/schema/documents.d.ts +279 -41
  63. package/dist/db/pg/schema/documents.js +136 -22
  64. package/dist/db/pg/schema/edges.d.ts +116 -7
  65. package/dist/db/pg/schema/edges.js +9 -2
  66. package/dist/db/pg/schema/index.d.ts +362 -15
  67. package/dist/db/pg/schema/index.js +5 -1
  68. package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
  69. package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
  70. package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
  71. package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
  72. package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
  73. package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
  74. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  75. package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
  76. package/dist/db/pg/sql/meta/_journal.json +49 -0
  77. package/dist/db/replaceOrigin.js +1 -1
  78. package/dist/email/queueStats.js +8 -11
  79. package/dist/email/render.js +14 -3
  80. package/dist/email/send.js +19 -17
  81. package/dist/email/smtpTest.js +10 -6
  82. package/dist/errors/index.js +1 -1
  83. package/dist/events/index.d.ts +4 -0
  84. package/dist/events/index.js +1 -0
  85. package/dist/events/once.js +2 -4
  86. package/dist/federation/activities.d.ts +17 -0
  87. package/dist/federation/activities.js +25 -0
  88. package/dist/federation/identity.d.ts +16 -0
  89. package/dist/federation/identity.js +52 -0
  90. package/dist/federation/index.d.ts +4 -0
  91. package/dist/federation/index.js +3 -0
  92. package/dist/federation/profiles.d.ts +3 -0
  93. package/dist/federation/profiles.js +14 -0
  94. package/dist/groups/finders.d.ts +2 -1
  95. package/dist/groups/helpers.d.ts +18 -0
  96. package/dist/groups/helpers.js +1 -2
  97. package/dist/groups/mapping.d.ts +4 -2
  98. package/dist/groups/mutations.js +1 -1
  99. package/dist/hashtags/finders.d.ts +6 -3
  100. package/dist/hashtags/finders.js +2 -0
  101. package/dist/hashtags/helpers.d.ts +8 -0
  102. package/dist/hashtags/helpers.js +4 -0
  103. package/dist/hashtags/index.d.ts +2 -0
  104. package/dist/hashtags/index.js +2 -0
  105. package/dist/hashtags/mutations.d.ts +3 -0
  106. package/dist/hashtags/mutations.js +13 -1
  107. package/dist/i18n/index.d.ts +1 -1
  108. package/dist/i18n/index.js +3 -1
  109. package/dist/i18n/pluginLocales.d.ts +6 -0
  110. package/dist/i18n/pluginLocales.js +15 -0
  111. package/dist/inviteLinks/mutations.js +2 -3
  112. package/dist/jams/export.d.ts +19 -0
  113. package/dist/jams/export.js +58 -0
  114. package/dist/jams/finders.js +4 -1
  115. package/dist/jams/health.d.ts +10 -0
  116. package/dist/jams/health.js +50 -0
  117. package/dist/jams/helpers.d.ts +2 -2
  118. package/dist/jams/helpers.js +6 -2
  119. package/dist/jams/index.d.ts +2 -0
  120. package/dist/jams/index.js +25 -18
  121. package/dist/jams/jobs.js +2 -3
  122. package/dist/jams/livekit.d.ts +49 -4
  123. package/dist/jams/livekit.js +62 -45
  124. package/dist/jams/mapping.d.ts +3 -3
  125. package/dist/jams/mutations.d.ts +1 -1
  126. package/dist/jams/recording.d.ts +10 -0
  127. package/dist/jams/recording.js +33 -1
  128. package/dist/jams/token.d.ts +13 -1
  129. package/dist/jams/token.js +25 -18
  130. package/dist/jams/waitingRoom.js +1 -1
  131. package/dist/jobs/index.d.ts +1 -0
  132. package/dist/jobs/index.js +9 -3
  133. package/dist/jobs/jobDetail.js +6 -12
  134. package/dist/jobs/jobLog.js +2 -3
  135. package/dist/lib/streams.js +4 -39
  136. package/dist/lib/zodDeepPartial.d.ts +1 -1
  137. package/dist/lib/zodDeepPartial.js +1 -1
  138. package/dist/log/index.js +13 -29
  139. package/dist/media/index.d.ts +1 -1
  140. package/dist/media/index.js +73 -12
  141. package/dist/media/jobs.js +1 -2
  142. package/dist/media/openpeeps/index.js +11 -46
  143. package/dist/media/processing.js +25 -11
  144. package/dist/media/streaming.js +5 -5
  145. package/dist/media/streamingCleanupJobs.js +1 -2
  146. package/dist/media/streamingJobs.js +3 -4
  147. package/dist/media/streamingPrewarm.js +7 -11
  148. package/dist/mediaAttachments/index.js +6 -2
  149. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  150. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  151. package/dist/notifications/defaultNotifications/follow/index.js +15 -18
  152. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  153. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  154. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  155. package/dist/notifications/defaultNotifications/index.js +4 -0
  156. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  157. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  158. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  159. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  160. package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
  161. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  162. package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
  163. package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
  164. package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
  165. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
  166. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  167. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  168. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  169. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  170. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
  171. package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
  172. package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
  173. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
  174. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
  175. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
  176. package/dist/notifications/fcmCredential.js +1 -1
  177. package/dist/notifications/finders.js +1 -1
  178. package/dist/notifications/helpers.js +13 -10
  179. package/dist/notifications/jobs.js +10 -5
  180. package/dist/notifications/mutations.js +8 -1
  181. package/dist/notifications/push.js +11 -16
  182. package/dist/performance/index.js +3 -3
  183. package/dist/plugins/helpers.js +3 -6
  184. package/dist/plugins/index.js +39 -4
  185. package/dist/plugins/install.d.ts +28 -9
  186. package/dist/plugins/install.js +302 -56
  187. package/dist/plugins/pluginAuth.d.ts +1 -1
  188. package/dist/plugins/pluginAuth.js +13 -10
  189. package/dist/plugins/state.js +2 -3
  190. package/dist/posts/activity.d.ts +9 -0
  191. package/dist/posts/activity.js +34 -0
  192. package/dist/posts/contextClosure.d.ts +1 -9
  193. package/dist/posts/contextClosure.js +14 -44
  194. package/dist/posts/conversationQueries.d.ts +7 -0
  195. package/dist/posts/conversationQueries.js +76 -4
  196. package/dist/posts/eventAgenda.d.ts +1 -0
  197. package/dist/posts/eventAgenda.js +17 -8
  198. package/dist/posts/eventOccurrenceJobs.js +7 -2
  199. package/dist/posts/eventOccurrences.d.ts +6 -0
  200. package/dist/posts/eventOccurrences.js +22 -1
  201. package/dist/posts/finders.d.ts +56 -9
  202. package/dist/posts/finders.js +84 -23
  203. package/dist/posts/helpers/filters.js +13 -9
  204. package/dist/posts/helpers/index.d.ts +179 -14
  205. package/dist/posts/helpers/index.js +70 -34
  206. package/dist/posts/index.d.ts +5 -2
  207. package/dist/posts/index.js +5 -2
  208. package/dist/posts/mapping.d.ts +765 -30
  209. package/dist/posts/mapping.js +74 -31
  210. package/dist/posts/mutations.d.ts +516 -3
  211. package/dist/posts/mutations.js +179 -41
  212. package/dist/posts/pollEnd.d.ts +3 -0
  213. package/dist/posts/pollEnd.js +4 -0
  214. package/dist/posts/pollEndJobs.d.ts +8 -0
  215. package/dist/posts/pollEndJobs.js +49 -0
  216. package/dist/posts/replyClosure.d.ts +10 -0
  217. package/dist/posts/replyClosure.js +43 -0
  218. package/dist/posts/rsvpConfirmationEmail.js +23 -15
  219. package/dist/posts/threadPreview.d.ts +8 -0
  220. package/dist/posts/threadPreview.js +44 -0
  221. package/dist/posts/unseenCounts.js +4 -1
  222. package/dist/processingStats/queries.js +6 -7
  223. package/dist/profileSettings/cache.js +21 -5
  224. package/dist/profileSettings/mapping.d.ts +2 -0
  225. package/dist/profiles/activityQueries.d.ts +5 -0
  226. package/dist/profiles/activityQueries.js +85 -0
  227. package/dist/profiles/activitySummary.d.ts +3 -0
  228. package/dist/profiles/activitySummary.js +82 -0
  229. package/dist/profiles/blocks.d.ts +12 -0
  230. package/dist/profiles/blocks.js +73 -0
  231. package/dist/profiles/cache.d.ts +1 -0
  232. package/dist/profiles/cache.js +30 -10
  233. package/dist/profiles/export.js +30 -39
  234. package/dist/profiles/finders.d.ts +2 -1
  235. package/dist/profiles/finders.js +15 -8
  236. package/dist/profiles/helpers.d.ts +2 -0
  237. package/dist/profiles/index.d.ts +2 -0
  238. package/dist/profiles/index.js +2 -0
  239. package/dist/profiles/mapping.d.ts +10 -5
  240. package/dist/profiles/mapping.js +13 -1
  241. package/dist/profiles/mutations.d.ts +8 -4
  242. package/dist/profiles/mutations.js +31 -4
  243. package/dist/redis/connection.d.ts +2 -0
  244. package/dist/redis/connection.js +25 -6
  245. package/dist/reports/helpers.js +7 -3
  246. package/dist/roles/index.d.ts +1 -1
  247. package/dist/roles/index.js +1 -1
  248. package/dist/roles/mapping.d.ts +1 -0
  249. package/dist/roles/mutations.js +85 -3
  250. package/dist/search/finders.js +15 -3
  251. package/dist/search/helpers.js +1 -1
  252. package/dist/search/mapping.d.ts +1 -1
  253. package/dist/search/mapping.js +6 -2
  254. package/dist/sentry/index.js +9 -11
  255. package/dist/seo/index.d.ts +50 -0
  256. package/dist/seo/index.js +145 -0
  257. package/dist/seo/route.d.ts +18 -0
  258. package/dist/seo/route.js +19 -0
  259. package/dist/server/index.d.ts +19 -0
  260. package/dist/server/index.js +31 -14
  261. package/dist/server/stablePublicServerInfo.d.ts +17 -0
  262. package/dist/server/stablePublicServerInfo.js +37 -0
  263. package/dist/server/status.d.ts +25 -0
  264. package/dist/server/status.js +97 -0
  265. package/dist/session/index.js +2 -2
  266. package/dist/stats/finders.d.ts +1 -17681
  267. package/dist/stats/finders.js +22 -9
  268. package/dist/stats/helpers.js +4 -1
  269. package/dist/stats/mapping.d.ts +39 -2
  270. package/dist/stats/mapping.js +8 -4
  271. package/dist/stripe/cache.js +5 -6
  272. package/dist/stripe/connection.js +3 -4
  273. package/dist/stripe/helpers.js +15 -20
  274. package/package.json +5 -7
  275. package/dist/db/migration/detect.d.ts +0 -3
  276. package/dist/db/migration/detect.js +0 -33
  277. package/dist/db/migration/importPostgres.d.ts +0 -3
  278. package/dist/db/migration/importPostgres.js +0 -18
  279. package/dist/db/migration/transform.d.ts +0 -20
  280. package/dist/db/migration/transform.js +0 -232
  281. package/dist/db/migration/validate.d.ts +0 -18
  282. package/dist/db/migration/validate.js +0 -69
  283. package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
  284. package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
  285. package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
  286. package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
  287. package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
  288. package/dist/mastodon/index.d.ts +0 -4
  289. package/dist/mastodon/index.js +0 -51
  290. package/dist/mastodon/types.d.ts +0 -7579
  291. package/dist/mastodon/types.js +0 -523
  292. package/dist/mastodon/typescript.d.ts +0 -1578
  293. package/dist/mastodon/typescript.js +0 -1
  294. package/dist/migration/index.d.ts +0 -4
  295. package/dist/migration/index.js +0 -4
  296. package/dist/roles/defaults.d.ts +0 -2
  297. package/dist/roles/defaults.js +0 -95
@@ -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',
@@ -23,16 +23,25 @@ const edgeBodyPatch = (patch) => {
23
23
  return body;
24
24
  };
25
25
  export const createDocument = async (db, mapData, data) => {
26
- var _a;
27
26
  const collection = mapData.collection;
28
27
  const config = documentRegistry[collection];
29
28
  if (!config) {
30
29
  throw new Error(`Cannot create in collection: ${collection}`);
31
30
  }
32
- const id = (_a = data.id) !== null && _a !== void 0 ? _a : uuidv7();
31
+ const id = data.id ?? uuidv7();
33
32
  const { scalars, body } = config.splitPatch(data);
34
33
  const ts = nowIso();
35
- await db.insert(config.table).values(Object.assign(Object.assign({ id }, scalars), { body, createdAt: ts, updatedAt: ts, deletedAt: null }));
34
+ await db.insert(config.table).values({
35
+ id,
36
+ ...scalars,
37
+ body,
38
+ createdAt: ts,
39
+ updatedAt: ts,
40
+ deletedAt: null,
41
+ ...(collection === 'posts' && scalars.lastActivityAt === undefined
42
+ ? { lastActivityAt: ts }
43
+ : {}),
44
+ });
36
45
  const created = await executeFind(db, collection, mapData, id, true);
37
46
  if (!created) {
38
47
  throw new Error(`create ${collection}`);
@@ -40,7 +49,6 @@ export const createDocument = async (db, mapData, data) => {
40
49
  return created;
41
50
  };
42
51
  export const updateDocument = async (db, mapData, id, patch) => {
43
- var _a;
44
52
  const collection = mapData.collection;
45
53
  const config = getCollectionConfig(collection);
46
54
  if (!config) {
@@ -50,29 +58,38 @@ export const updateDocument = async (db, mapData, id, patch) => {
50
58
  const existing = await db
51
59
  .select()
52
60
  .from(config.table)
53
- .where(eq(table.id, id))
61
+ .where(eq(documentIdColumn(collection, table), id))
54
62
  .limit(1);
55
63
  const row = existing[0];
56
64
  if (!row) {
57
65
  throw new Error(`update ${collection} ${id}`);
58
66
  }
59
67
  if (config.kind === 'edge') {
60
- const currentBody = Object.assign({}, ((_a = row.body) !== null && _a !== void 0 ? _a : {}));
68
+ const currentBody = {
69
+ ...(row.body ?? {}),
70
+ };
61
71
  await db
62
72
  .update(table)
63
73
  .set({
64
- body: Object.assign(Object.assign({}, currentBody), edgeBodyPatch(patch)),
74
+ body: { ...currentBody, ...edgeBodyPatch(patch) },
65
75
  updatedAt: nowIso(),
66
76
  })
67
- .where(eq(table.id, id));
77
+ .where(eq(documentIdColumn(collection, table), id));
68
78
  }
69
79
  else {
70
- const merged = Object.assign(Object.assign({}, rowToPatchInput(collection, row)), patch);
80
+ const merged = {
81
+ ...rowToPatchInput(collection, row),
82
+ ...patch,
83
+ };
71
84
  const { scalars, body } = config.splitPatch(merged);
72
85
  await db
73
86
  .update(table)
74
- .set(Object.assign(Object.assign({}, scalars), { body, updatedAt: nowIso() }))
75
- .where(eq(table.id, id));
87
+ .set({
88
+ ...scalars,
89
+ body,
90
+ updatedAt: nowIso(),
91
+ })
92
+ .where(eq(documentIdColumn(collection, table), id));
76
93
  }
77
94
  const updated = await executeFind(db, collection, mapData, id, true);
78
95
  if (!updated) {
@@ -87,26 +104,49 @@ const rowToPatchInput = (collection, row) => {
87
104
  type: row.type,
88
105
  visibility: row.visibility,
89
106
  creatorId: row.creatorId,
107
+ lastActivityAt: row.lastActivityAt,
108
+ uri: row.uri,
109
+ inReplyToUri: row.inReplyToUri,
90
110
  data: row.body,
91
111
  };
92
112
  case 'profiles':
93
- return Object.assign(Object.assign({ handle: row.handle, type: row.type }, (row.activityPubDomain
94
- ? { activityPub: { domain: row.activityPubDomain } }
95
- : {})), row.body);
113
+ return {
114
+ handle: row.handle,
115
+ type: row.type,
116
+ uri: row.uri,
117
+ inboxUrl: row.inboxUrl,
118
+ sharedInboxUrl: row.sharedInboxUrl,
119
+ publicKeyPem: row.publicKeyPem,
120
+ privateKeyPem: row.privateKeyPem,
121
+ keyId: row.keyId,
122
+ fetchedAt: row.fetchedAt,
123
+ ...(row.activityPubDomain
124
+ ? { activityPub: { domain: row.activityPubDomain } }
125
+ : {}),
126
+ ...row.body,
127
+ };
96
128
  case 'groups':
97
- return Object.assign({ handle: row.handle }, row.body);
129
+ return { handle: row.handle, ...row.body };
98
130
  case 'roles':
99
- return Object.assign({ key: row.key, isDefault: row.isDefault }, row.body);
131
+ return {
132
+ key: row.key,
133
+ isDefault: row.isDefault,
134
+ ...row.body,
135
+ };
100
136
  case 'notifications':
101
- return Object.assign({ profileId: row.profileId }, row.body);
137
+ return { profileId: row.profileId, ...row.body };
102
138
  case 'jamEvents':
103
- return Object.assign({ jamId: row.postId }, row.body);
139
+ return { jamId: row.postId, ...row.body };
104
140
  case 'processingStats':
105
- return Object.assign({ filetype: row.filetype, filesize: row.filesize }, row.body);
141
+ return {
142
+ filetype: row.filetype,
143
+ filesize: row.filesize,
144
+ ...row.body,
145
+ };
106
146
  case 'profileSettings':
107
- return Object.assign({ id: row.profileId }, row.body);
147
+ return { id: row.profileId, ...row.body };
108
148
  case 'inviteLinks':
109
- return Object.assign({ slug: row.slug }, row.body);
149
+ return { slug: row.slug, ...row.body };
110
150
  case 'accounts':
111
151
  return {
112
152
  email: row.email,
@@ -117,7 +157,7 @@ const rowToPatchInput = (collection, row) => {
117
157
  case 'hashtags':
118
158
  return { tag: row.name };
119
159
  default:
120
- return Object.assign({}, row.body);
160
+ return { ...row.body };
121
161
  }
122
162
  };
123
163
  export const deleteDocument = async (db, mapData, id) => {
@@ -126,10 +166,10 @@ export const deleteDocument = async (db, mapData, id) => {
126
166
  await db
127
167
  .update(getTableForCollection(mapData.collection))
128
168
  .set({ deletedAt: nowIso(), updatedAt: nowIso() })
129
- .where(eq(table.id, id));
169
+ .where(eq(documentIdColumn(mapData.collection, table), id));
130
170
  return;
131
171
  }
132
172
  await db
133
173
  .delete(getTableForCollection(mapData.collection))
134
- .where(eq(table.id, id));
174
+ .where(eq(documentIdColumn(mapData.collection, table), id));
135
175
  };
@@ -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;
@@ -1,25 +1,19 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
1
  import * as documents from '../schema/documents.js';
13
2
  import * as edges from '../schema/edges.js';
14
- import { modelTimestampsFromRow, rowToModel, } from '../mappers.js';
3
+ import { modelTimestampsFromRow, normalizeIsoDatetime, rowToModel, } from '../mappers.js';
15
4
  export const asTable = (table) => table;
5
+ /**
6
+ * Column the map layer treats as a document's id. Profile settings are
7
+ * addressed by profile id; legacy rows keep a different primary key.
8
+ */
9
+ export const documentIdColumn = (collection, table) => (collection === 'profileSettings' ? table.profileId : table.id);
16
10
  const bodyOnly = (data) => ({
17
11
  scalars: {},
18
- body: Object.assign({}, data),
12
+ body: { ...data },
19
13
  });
20
14
  const withScalars = (...scalarKeys) => (data) => {
21
15
  const scalars = {};
22
- const body = Object.assign({}, data);
16
+ const body = { ...data };
23
17
  for (const key of scalarKeys) {
24
18
  if (key in body) {
25
19
  scalars[key] = body[key];
@@ -29,7 +23,7 @@ const withScalars = (...scalarKeys) => (data) => {
29
23
  return { scalars, body };
30
24
  };
31
25
  const postsSplit = (data) => {
32
- const { type, visibility, creatorId, data: postBody } = data, rest = __rest(data, ["type", "visibility", "creatorId", "data"]);
26
+ const { type, visibility, creatorId, lastActivityAt, data: postBody, uri, inReplyToUri, ...rest } = data;
33
27
  const scalars = {};
34
28
  if (type !== undefined)
35
29
  scalars.type = type;
@@ -37,16 +31,34 @@ const postsSplit = (data) => {
37
31
  scalars.visibility = visibility;
38
32
  if (creatorId !== undefined)
39
33
  scalars.creatorId = creatorId;
40
- const body = postBody !== undefined ? Object.assign({}, postBody) : Object.assign({}, rest);
34
+ if (lastActivityAt !== undefined)
35
+ scalars.lastActivityAt = lastActivityAt;
36
+ if (uri !== undefined)
37
+ scalars.uri = uri;
38
+ if (inReplyToUri !== undefined)
39
+ scalars.inReplyToUri = inReplyToUri;
40
+ const body = postBody !== undefined ? { ...postBody } : { ...rest };
41
41
  if (postBody === undefined) {
42
42
  delete body.type;
43
43
  delete body.visibility;
44
44
  delete body.creatorId;
45
+ delete body.lastActivityAt;
46
+ delete body.uri;
47
+ delete body.inReplyToUri;
45
48
  }
46
49
  return { scalars, body };
47
50
  };
51
+ const ACTOR_SCALAR_KEYS = [
52
+ 'uri',
53
+ 'inboxUrl',
54
+ 'sharedInboxUrl',
55
+ 'publicKeyPem',
56
+ 'privateKeyPem',
57
+ 'keyId',
58
+ 'fetchedAt',
59
+ ];
48
60
  const profilesSplit = (data) => {
49
- const { handle, type, activityPub } = data, rest = __rest(data, ["handle", "type", "activityPub"]);
61
+ const { handle, type, activityPub, ...rest } = data;
50
62
  const scalars = {};
51
63
  if (handle !== undefined)
52
64
  scalars.handle = handle;
@@ -57,11 +69,18 @@ const profilesSplit = (data) => {
57
69
  if (domain !== undefined)
58
70
  scalars.activityPubDomain = domain;
59
71
  }
60
- return { scalars, body: Object.assign({}, rest) };
72
+ const body = { ...rest };
73
+ for (const key of ACTOR_SCALAR_KEYS) {
74
+ if (key in body) {
75
+ scalars[key] = body[key];
76
+ delete body[key];
77
+ }
78
+ }
79
+ return { scalars, body };
61
80
  };
62
81
  /** App model uses `tag`; Postgres column is `name`. */
63
82
  const hashtagsSplit = (data) => {
64
- const normalized = Object.assign({}, data);
83
+ const normalized = { ...data };
65
84
  if ('tag' in normalized && !('name' in normalized)) {
66
85
  normalized.name = normalized.tag;
67
86
  delete normalized.tag;
@@ -71,25 +90,25 @@ const hashtagsSplit = (data) => {
71
90
  }
72
91
  return withScalars('name')(normalized);
73
92
  };
74
- /** Arango jam events use jamId; Postgres column is post_id. */
93
+ /** Older jam events stored jamId; the column is post_id. */
75
94
  const jamEventsSplit = (data) => {
76
- const { postId, jamId } = data, rest = __rest(data, ["postId", "jamId"]);
95
+ const { postId, jamId, ...rest } = data;
77
96
  const scalars = {};
78
- const resolvedPostId = postId !== null && postId !== void 0 ? postId : jamId;
97
+ const resolvedPostId = postId ?? jamId;
79
98
  if (resolvedPostId !== undefined) {
80
99
  scalars.postId = resolvedPostId;
81
100
  }
82
- return { scalars, body: Object.assign({}, rest) };
101
+ return { scalars, body: { ...rest } };
83
102
  };
84
103
  /** Legacy settings docs use profile id as document id, not profileId. */
85
104
  const profileSettingsSplit = (data) => {
86
- const { profileId, id } = data, rest = __rest(data, ["profileId", "id"]);
105
+ const { profileId, id, ...rest } = data;
87
106
  const scalars = {};
88
- const resolvedProfileId = profileId !== null && profileId !== void 0 ? profileId : id;
107
+ const resolvedProfileId = profileId ?? id;
89
108
  if (resolvedProfileId !== undefined) {
90
109
  scalars.profileId = resolvedProfileId;
91
110
  }
92
- return { scalars, body: Object.assign({}, rest) };
111
+ return { scalars, body: { ...rest } };
93
112
  };
94
113
  export const documentRegistry = {
95
114
  accounts: {
@@ -177,11 +196,6 @@ export const documentRegistry = {
177
196
  table: documents.i18nEntries,
178
197
  splitPatch: withScalars('locale', 'namespace'),
179
198
  },
180
- dataMigrations: {
181
- kind: 'document',
182
- table: documents.dataMigrations,
183
- splitPatch: bodyOnly,
184
- },
185
199
  };
186
200
  export const edgeRegistry = {
187
201
  follows: {
@@ -190,6 +204,12 @@ export const edgeRegistry = {
190
204
  fromCollection: 'profiles',
191
205
  toCollection: 'profiles',
192
206
  },
207
+ blocks: {
208
+ kind: 'edge',
209
+ table: edges.blocks,
210
+ fromCollection: 'profiles',
211
+ toCollection: 'profiles',
212
+ },
193
213
  requestsFollow: {
194
214
  kind: 'edge',
195
215
  table: edges.requestsFollow,
@@ -226,12 +246,6 @@ export const edgeRegistry = {
226
246
  fromCollection: 'profiles',
227
247
  toCollection: 'posts',
228
248
  },
229
- reactions: {
230
- kind: 'edge',
231
- table: edges.reactions,
232
- fromCollection: 'profiles',
233
- toCollection: 'posts',
234
- },
235
249
  replyTo: {
236
250
  kind: 'edge',
237
251
  table: edges.replyTo,
@@ -334,8 +348,14 @@ export const edgeRegistry = {
334
348
  fromCollection: 'profiles',
335
349
  toCollection: 'posts',
336
350
  },
351
+ profileHashtags: {
352
+ kind: 'edge',
353
+ table: edges.profileHashtags,
354
+ fromCollection: 'profiles',
355
+ toCollection: 'hashtags',
356
+ },
337
357
  };
338
- export const getCollectionConfig = (collection) => { var _a; return (_a = documentRegistry[collection]) !== null && _a !== void 0 ? _a : edgeRegistry[collection]; };
358
+ export const getCollectionConfig = (collection) => documentRegistry[collection] ?? edgeRegistry[collection];
339
359
  export const getTableForCollection = (collection) => {
340
360
  const config = getCollectionConfig(collection);
341
361
  if (!config) {
@@ -353,7 +373,6 @@ export const parseDocRef = (ref) => {
353
373
  export const docRef = (collection, id) => `${collection}/${id}`;
354
374
  const rowTimestamps = (row) => modelTimestampsFromRow(row);
355
375
  export const rowToDocument = (collection, row, keepMetadata = false) => {
356
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
357
376
  const config = getCollectionConfig(collection);
358
377
  if (!config) {
359
378
  throw new Error(`Unknown collection: ${collection}`);
@@ -364,7 +383,14 @@ export const rowToDocument = (collection, row, keepMetadata = false) => {
364
383
  const toId = row.toId;
365
384
  // Body fields first; row id / edge refs / timestamps always win so a
366
385
  // stale body.id (from older inserts) cannot shadow the primary key.
367
- const base = Object.assign(Object.assign({}, ((_a = row.body) !== null && _a !== void 0 ? _a : {})), { id: row.id, _from: docRef(config.fromCollection, fromId), _to: docRef(config.toCollection, toId), createdAt: timestamps.createdAt, updatedAt: timestamps.updatedAt });
386
+ const base = {
387
+ ...(row.body ?? {}),
388
+ id: row.id,
389
+ _from: docRef(config.fromCollection, fromId),
390
+ _to: docRef(config.toCollection, toId),
391
+ createdAt: timestamps.createdAt,
392
+ updatedAt: timestamps.updatedAt,
393
+ };
368
394
  return keepMetadata ? base : base;
369
395
  }
370
396
  switch (collection) {
@@ -373,37 +399,88 @@ export const rowToDocument = (collection, row, keepMetadata = false) => {
373
399
  email: row.email,
374
400
  passwordHash: row.passwordHash,
375
401
  emailValidated: row.emailValidated,
376
- guest: (_b = row.guest) !== null && _b !== void 0 ? _b : undefined,
402
+ guest: row.guest ?? undefined,
377
403
  }, timestamps);
378
404
  case 'profiles':
379
- return rowToModel(row.id, Object.assign(Object.assign({ handle: row.handle, type: row.type }, (row.activityPubDomain
380
- ? { activityPub: { domain: row.activityPubDomain } }
381
- : {})), ((_c = row.body) !== null && _c !== void 0 ? _c : {})), timestamps);
382
- case 'posts':
383
405
  return rowToModel(row.id, {
406
+ handle: row.handle,
384
407
  type: row.type,
385
- visibility: row.visibility,
386
- creatorId: row.creatorId,
387
- data: (_d = row.body) !== null && _d !== void 0 ? _d : {},
408
+ ...(row.activityPubDomain
409
+ ? { activityPub: { domain: row.activityPubDomain } }
410
+ : {}),
411
+ ...(row.body ?? {}),
412
+ ...(typeof row.uri === 'string' ? { uri: row.uri } : {}),
413
+ ...(typeof row.inboxUrl === 'string'
414
+ ? { inboxUrl: row.inboxUrl }
415
+ : {}),
416
+ ...(typeof row.sharedInboxUrl === 'string'
417
+ ? { sharedInboxUrl: row.sharedInboxUrl }
418
+ : {}),
419
+ ...(typeof row.publicKeyPem === 'string'
420
+ ? { publicKeyPem: row.publicKeyPem }
421
+ : {}),
422
+ // privateKeyPem stays on the column and is never hydrated here.
423
+ ...(typeof row.keyId === 'string' ? { keyId: row.keyId } : {}),
424
+ ...(typeof row.fetchedAt === 'string'
425
+ ? { fetchedAt: normalizeIsoDatetime(row.fetchedAt) }
426
+ : {}),
388
427
  }, timestamps);
428
+ case 'posts': {
429
+ const lastActivityAt = row.lastActivityAt
430
+ ? normalizeIsoDatetime(row.lastActivityAt)
431
+ : timestamps.createdAt;
432
+ return {
433
+ ...rowToModel(row.id, {
434
+ type: row.type,
435
+ visibility: row.visibility,
436
+ creatorId: row.creatorId,
437
+ ...(typeof row.uri === 'string' ? { uri: row.uri } : {}),
438
+ ...(typeof row.inReplyToUri === 'string'
439
+ ? { inReplyToUri: row.inReplyToUri }
440
+ : {}),
441
+ data: row.body ?? {},
442
+ }, timestamps),
443
+ lastActivityAt,
444
+ };
445
+ }
389
446
  case 'groups':
390
- return rowToModel(row.id, Object.assign({ handle: row.handle }, ((_e = row.body) !== null && _e !== void 0 ? _e : {})), timestamps);
447
+ return rowToModel(row.id, {
448
+ handle: row.handle,
449
+ ...(row.body ?? {}),
450
+ }, timestamps);
391
451
  case 'hashtags':
392
452
  return rowToModel(row.id, { tag: row.name }, timestamps);
393
453
  case 'roles':
394
- return rowToModel(row.id, Object.assign({ key: row.key, isDefault: row.isDefault }, ((_f = row.body) !== null && _f !== void 0 ? _f : {})), timestamps);
454
+ return rowToModel(row.id, {
455
+ key: row.key,
456
+ isDefault: row.isDefault,
457
+ ...(row.body ?? {}),
458
+ }, timestamps);
395
459
  case 'notifications':
396
- return rowToModel(row.id, Object.assign({ profileId: row.profileId }, ((_g = row.body) !== null && _g !== void 0 ? _g : {})), timestamps);
460
+ return rowToModel(row.id, {
461
+ profileId: row.profileId,
462
+ ...(row.body ?? {}),
463
+ }, timestamps);
397
464
  case 'jamEvents':
398
- return rowToModel(row.id, Object.assign({ jamId: row.postId }, ((_h = row.body) !== null && _h !== void 0 ? _h : {})), timestamps);
465
+ return rowToModel(row.id, {
466
+ jamId: row.postId,
467
+ ...(row.body ?? {}),
468
+ }, timestamps);
399
469
  case 'processingStats':
400
- return rowToModel(row.id, Object.assign({ filetype: row.filetype, filesize: row.filesize }, ((_j = row.body) !== null && _j !== void 0 ? _j : {})), timestamps);
470
+ return rowToModel(row.id, {
471
+ filetype: row.filetype,
472
+ filesize: row.filesize,
473
+ ...(row.body ?? {}),
474
+ }, timestamps);
401
475
  case 'profileSettings':
402
- return rowToModel(row.profileId, ((_k = row.body) !== null && _k !== void 0 ? _k : {}), timestamps);
476
+ return rowToModel(row.profileId, (row.body ?? {}), timestamps);
403
477
  case 'inviteLinks':
404
- return rowToModel(row.id, Object.assign({ slug: row.slug }, ((_l = row.body) !== null && _l !== void 0 ? _l : {})), timestamps);
478
+ return rowToModel(row.id, {
479
+ slug: row.slug,
480
+ ...(row.body ?? {}),
481
+ }, timestamps);
405
482
  default:
406
- return rowToModel(row.id, ((_m = row.body) !== null && _m !== void 0 ? _m : {}), timestamps);
483
+ return rowToModel(row.id, (row.body ?? {}), timestamps);
407
484
  }
408
485
  };
409
486
  export const searchViewCollections = {