@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,23 +1,19 @@
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
- const buildComputedSelect = (mapData, tableRef) => {
7
- var _a;
8
- return Object.fromEntries(((_a = mapData.computedFields) !== null && _a !== void 0 ? _a : []).map((field) => [
9
- field.alias,
10
- field.expr({
11
- table: tableRef,
12
- collection: mapData.collection,
13
- activityWindow: mapData.activityWindow,
14
- }),
15
- ]));
16
- };
6
+ const buildComputedSelect = (mapData, tableRef) => Object.fromEntries((mapData.computedFields ?? []).map((field) => [
7
+ field.alias,
8
+ field.expr({
9
+ table: tableRef,
10
+ collection: mapData.collection,
11
+ activityWindow: mapData.activityWindow,
12
+ }),
13
+ ]));
17
14
  const mapRowToDoc = (mapData, row) => {
18
- var _a;
19
15
  const doc = rowToDocument(mapData.collection, row);
20
- for (const field of (_a = mapData.computedFields) !== null && _a !== void 0 ? _a : []) {
16
+ for (const field of mapData.computedFields ?? []) {
21
17
  if (field.alias in row) {
22
18
  const value = row[field.alias];
23
19
  doc[field.alias] =
@@ -27,11 +23,11 @@ const mapRowToDoc = (mapData, row) => {
27
23
  return doc;
28
24
  };
29
25
  const vertexCollectionFor = (relation) => {
30
- var _a, _b, _c;
31
26
  const edgeName = typeof relation.edgeCollection === 'string'
32
27
  ? relation.edgeCollection
33
28
  : relation.edgeCollection.name;
34
- return ((_b = (_a = relation.mapping) === null || _a === void 0 ? void 0 : _a.collection) !== null && _b !== void 0 ? _b : (_c = edgeRegistry[edgeName]) === null || _c === void 0 ? void 0 : _c[relation.direction === 'INBOUND' ? 'fromCollection' : 'toCollection']);
29
+ return (relation.mapping?.collection ??
30
+ edgeRegistry[edgeName]?.[relation.direction === 'INBOUND' ? 'fromCollection' : 'toCollection']);
35
31
  };
36
32
  const edgeCollectionName = (edge) => typeof edge === 'string' ? edge : edge.name;
37
33
  const parentEdgeColumn = (relation) => relation.direction === 'INBOUND' ? 'toId' : 'fromId';
@@ -40,7 +36,9 @@ export const fetchRowsByIds = async (db, collection, ids, softDelete) => {
40
36
  if (!ids.length)
41
37
  return [];
42
38
  const table = asTable(getTableForCollection(collection));
43
- const conditions = [inArray(table.id, ids)];
39
+ const conditions = [
40
+ inArray(documentIdColumn(collection, table), ids),
41
+ ];
44
42
  if (softDelete !== false && table.deletedAt) {
45
43
  conditions.push(sql `${table.deletedAt} IS NULL`);
46
44
  }
@@ -61,7 +59,9 @@ export const fetchFilteredRowsByIds = async (db, mapData, ids) => {
61
59
  const tableRef = getTableForCollection(mapData.collection);
62
60
  const table = asTable(tableRef);
63
61
  const { sqlWhere, postFilters } = partitionFilters(mapData.collection, table, mapData.filters, mapData.defaultFilter, mapData.softDelete);
64
- const conditions = [inArray(table.id, ids)];
62
+ const conditions = [
63
+ inArray(documentIdColumn(mapData.collection, table), ids),
64
+ ];
65
65
  if (sqlWhere) {
66
66
  conditions.push(sqlWhere);
67
67
  }
@@ -69,7 +69,7 @@ export const fetchFilteredRowsByIds = async (db, mapData, ids) => {
69
69
  const columns = getTableColumns(tableRef);
70
70
  const computedSelect = buildComputedSelect(mapData, tableRef);
71
71
  let query = db
72
- .select(Object.assign(Object.assign({}, columns), computedSelect))
72
+ .select({ ...columns, ...computedSelect })
73
73
  .from(tableRef)
74
74
  .where(and(...conditions))
75
75
  .$dynamic();
@@ -84,56 +84,65 @@ export const fetchFilteredRowsByIds = async (db, mapData, ids) => {
84
84
  return { docs, postFilters };
85
85
  };
86
86
  const hydrateDocuments = async (db, collection, mapData, rows, postFilters) => {
87
- var _a, _b, _c, _d;
88
87
  let docs = rows;
89
- for (const relation of (_a = mapData.relations) !== null && _a !== void 0 ? _a : []) {
88
+ for (const relation of mapData.relations ?? []) {
90
89
  docs = await attachRelation(db, collection, docs, relation);
91
90
  }
92
- for (const fkr of (_b = mapData.foreignKeyRelations) !== null && _b !== void 0 ? _b : []) {
91
+ for (const fkr of mapData.foreignKeyRelations ?? []) {
93
92
  docs = await attachForeignKeyRelation(db, docs, fkr);
94
93
  }
95
94
  docs = await attachDerivedProperties(db, docs, mapData.derivedProperties);
96
- docs = applyPostFilters(docs, postFilters !== null && postFilters !== void 0 ? postFilters : mapData.filters, postFilters ? undefined : mapData.defaultFilter);
95
+ docs = applyPostFilters(docs, postFilters ?? mapData.filters, postFilters ? undefined : mapData.defaultFilter);
97
96
  docs = applySort(docs, mapData.sort);
98
- for (const relation of (_c = mapData.postFilterRelations) !== null && _c !== void 0 ? _c : []) {
97
+ for (const relation of mapData.postFilterRelations ?? []) {
99
98
  docs = await attachRelation(db, collection, docs, relation);
100
99
  }
101
- for (const fkr of (_d = mapData.postFilterForeignKeyRelations) !== null && _d !== void 0 ? _d : []) {
100
+ for (const fkr of mapData.postFilterForeignKeyRelations ?? []) {
102
101
  docs = await attachForeignKeyRelation(db, docs, fkr);
103
102
  }
104
103
  docs = await attachDerivedProperties(db, docs, mapData.postFilterDerivedProperties);
105
104
  return docs;
106
105
  };
107
106
  const attachDerivedProperties = async (db, docs, derivedProperties) => {
108
- if (!(derivedProperties === null || derivedProperties === void 0 ? void 0 : derivedProperties.length))
107
+ if (!derivedProperties?.length)
109
108
  return docs;
110
109
  let result = docs;
111
110
  for (const dp of derivedProperties) {
112
111
  if (dp.batchResolve) {
113
112
  const values = await dp.batchResolve(db, result);
114
- result = result.map((doc) => (Object.assign(Object.assign({}, doc), { [String(dp.alias)]: values.get(doc.id) })));
113
+ result = result.map((doc) => ({
114
+ ...doc,
115
+ [String(dp.alias)]: values.get(doc.id),
116
+ }));
115
117
  continue;
116
118
  }
117
- result = await Promise.all(result.map(async (doc) => (Object.assign(Object.assign({}, doc), { [String(dp.alias)]: await evaluateDerived(db, doc, dp) }))));
119
+ result = await Promise.all(result.map(async (doc) => ({
120
+ ...doc,
121
+ [String(dp.alias)]: await evaluateDerived(db, doc, dp),
122
+ })));
118
123
  }
119
124
  return result;
120
125
  };
121
126
  export const hydrateMapData = async (db, mapData, rows, postFilters) => hydrateDocuments(db, mapData.collection, mapData, rows, postFilters);
122
127
  const attachForeignKeyRelation = async (db, docs, fkr) => Promise.all(docs.map(async (doc) => {
123
- var _a, _b;
124
128
  const raw = doc[fkr.foreignKeyProperty];
125
129
  const ids = fkr.cardinality === 'many'
126
- ? ((_a = raw) !== null && _a !== void 0 ? _a : [])
130
+ ? (raw ?? [])
127
131
  : raw
128
132
  ? [raw]
129
133
  : [];
130
134
  const loaded = (await Promise.all(ids.map((id) => executeFind(db, fkr.mapping.collection, fkr.mapping, id)))).filter(Boolean);
131
- return Object.assign(Object.assign({}, doc), { [fkr.alias]: fkr.cardinality === 'many' ? loaded : ((_b = loaded[0]) !== null && _b !== void 0 ? _b : undefined) });
135
+ return {
136
+ ...doc,
137
+ [fkr.alias]: fkr.cardinality === 'many' ? loaded : (loaded[0] ?? undefined),
138
+ };
132
139
  }));
133
140
  const attachRelation = async (db, _parentCollection, docs, relation) => {
134
- var _a, _b;
135
141
  if (relation.maxDepth && relation.maxDepth > 1) {
136
- return Promise.all(docs.map(async (doc) => (Object.assign(Object.assign({}, doc), { [relation.alias]: await traverseRelation(db, doc.id, relation) }))));
142
+ return Promise.all(docs.map(async (doc) => ({
143
+ ...doc,
144
+ [relation.alias]: await traverseRelation(db, doc.id, relation),
145
+ })));
137
146
  }
138
147
  const edgeTableRef = getEdgeTable(edgeCollectionName(relation.edgeCollection));
139
148
  const edgeTable = asTable(edgeTableRef);
@@ -156,12 +165,12 @@ const attachRelation = async (db, _parentCollection, docs, relation) => {
156
165
  const grouped = new Map();
157
166
  for (const edge of edgeRows) {
158
167
  const parentId = edge[parentEdgeColumn(relation)];
159
- const list = (_a = grouped.get(parentId)) !== null && _a !== void 0 ? _a : [];
168
+ const list = grouped.get(parentId) ?? [];
160
169
  list.push(edge);
161
170
  grouped.set(parentId, list);
162
171
  }
163
172
  const vertexCol = vertexEdgeColumn(relation);
164
- const edgesFor = (doc) => { var _a; return (_a = grouped.get(doc.id)) !== null && _a !== void 0 ? _a : []; };
173
+ const edgesFor = (doc) => grouped.get(doc.id) ?? [];
165
174
  const edgeVertexIdsFor = (doc) => edgesFor(doc).map((edge) => edge[vertexCol]);
166
175
  // Vertices are fetched and hydrated once for the whole batch. Doing it per
167
176
  // parent row cost a query per row per relation, so one feed page ran
@@ -170,19 +179,28 @@ const attachRelation = async (db, _parentCollection, docs, relation) => {
170
179
  ...new Set(docs.flatMap(idsFor)),
171
180
  ];
172
181
  if (relation.count) {
173
- if (!((_b = relation.mapping) === null || _b === void 0 ? void 0 : _b.collection)) {
174
- return docs.map((doc) => (Object.assign(Object.assign({}, doc), { [relation.alias]: edgesFor(doc).length })));
182
+ if (!relation.mapping?.collection) {
183
+ return docs.map((doc) => ({
184
+ ...doc,
185
+ [relation.alias]: edgesFor(doc).length,
186
+ }));
175
187
  }
176
188
  const rows = await fetchRowsByIds(db, relation.mapping.collection, batchIdsFrom(edgeVertexIdsFor), relation.mapping.softDelete);
177
189
  const counted = new Set(applyPostFilters(rows, relation.mapping.filters, relation.mapping.defaultFilter).map((row) => row.id));
178
- return docs.map((doc) => (Object.assign(Object.assign({}, doc), { [relation.alias]: [...new Set(edgeVertexIdsFor(doc))].filter((id) => counted.has(id)).length })));
190
+ return docs.map((doc) => ({
191
+ ...doc,
192
+ [relation.alias]: [...new Set(edgeVertexIdsFor(doc))].filter((id) => counted.has(id)).length,
193
+ }));
179
194
  }
180
195
  const vertexIdsFor = (doc) => capVertexIds(edgeVertexIdsFor(doc), relation);
181
196
  const vertexCollection = vertexCollectionFor(relation);
182
197
  const lookup = vertexCollection
183
198
  ? await fetchVertexLookup(db, vertexCollection, batchIdsFrom(vertexIdsFor), relation)
184
199
  : emptyVertexLookup;
185
- return docs.map((doc) => (Object.assign(Object.assign({}, doc), { [relation.alias]: relationValueFrom(edgesFor(doc), relation, vertexIdsFor(doc), lookup) })));
200
+ return docs.map((doc) => ({
201
+ ...doc,
202
+ [relation.alias]: relationValueFrom(edgesFor(doc), relation, vertexIdsFor(doc), lookup),
203
+ }));
186
204
  };
187
205
  const nodeCapFromLimit = (limit) => {
188
206
  if (limit == null)
@@ -196,8 +214,7 @@ const nodeCapFromLimit = (limit) => {
196
214
  * row data to sort on.
197
215
  */
198
216
  const capVertexIds = (vertexIds, relation) => {
199
- var _a;
200
- const nodeCap = nodeCapFromLimit((_a = relation.mapping) === null || _a === void 0 ? void 0 : _a.limit);
217
+ const nodeCap = nodeCapFromLimit(relation.mapping?.limit);
201
218
  if (nodeCap === undefined || relation.cardinality !== 'many') {
202
219
  return vertexIds;
203
220
  }
@@ -210,8 +227,7 @@ const emptyVertexLookup = {
210
227
  rank: () => 0,
211
228
  };
212
229
  const fetchVertexLookup = async (db, vertexCollection, vertexIds, relation) => {
213
- var _a;
214
- const rows = await fetchRowsByIds(db, vertexCollection, vertexIds, (_a = relation.mapping) === null || _a === void 0 ? void 0 : _a.softDelete);
230
+ const rows = await fetchRowsByIds(db, vertexCollection, vertexIds, relation.mapping?.softDelete);
215
231
  const vertices = relation.mapping
216
232
  ? await hydrateMapData(db, relation.mapping, rows)
217
233
  : rows;
@@ -219,15 +235,11 @@ const fetchVertexLookup = async (db, vertexCollection, vertexIds, relation) => {
219
235
  const ranks = new Map(vertices.map((vertex, index) => [vertex.id, index]));
220
236
  return {
221
237
  get: (id) => byId.get(id),
222
- rank: (id) => { var _a; return (_a = ranks.get(id)) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER; },
238
+ rank: (id) => ranks.get(id) ?? Number.MAX_SAFE_INTEGER,
223
239
  };
224
240
  };
225
241
  const relationValueFrom = (edgeRows, relation, vertexIds, lookup) => {
226
- var _a, _b;
227
- const toEdgeDoc = (edge) => {
228
- var _a;
229
- return rowToDocument(edgeCollectionName(relation.edgeCollection), edge, (_a = relation.mapping) === null || _a === void 0 ? void 0 : _a.keepMetadata);
230
- };
242
+ const toEdgeDoc = (edge) => rowToDocument(edgeCollectionName(relation.edgeCollection), edge, relation.mapping?.keepMetadata);
231
243
  if (!vertexCollectionFor(relation)) {
232
244
  const items = edgeRows.map(toEdgeDoc);
233
245
  return relation.cardinality === 'one' ? items[0] : items;
@@ -239,7 +251,7 @@ const relationValueFrom = (edgeRows, relation, vertexIds, lookup) => {
239
251
  .filter((vertex) => !!vertex);
240
252
  if (relation.cardinality === 'one')
241
253
  return vertices[0];
242
- return applyLimit(applySort(vertices, (_a = relation.mapping) === null || _a === void 0 ? void 0 : _a.sort), (_b = relation.mapping) === null || _b === void 0 ? void 0 : _b.limit);
254
+ return applyLimit(applySort(vertices, relation.mapping?.sort), relation.mapping?.limit);
243
255
  }
244
256
  const vertexCol = vertexEdgeColumn(relation);
245
257
  const capped = new Set(vertexIds);
@@ -251,9 +263,9 @@ const relationValueFrom = (edgeRows, relation, vertexIds, lookup) => {
251
263
  return undefined;
252
264
  const edgeDoc = toEdgeDoc(edge);
253
265
  if (relation.vertexAlias) {
254
- return Object.assign(Object.assign({}, edgeDoc), { [relation.vertexAlias]: vertex });
266
+ return { ...edgeDoc, [relation.vertexAlias]: vertex };
255
267
  }
256
- return Object.assign(Object.assign({}, edgeDoc), vertex);
268
+ return { ...edgeDoc, ...vertex };
257
269
  })
258
270
  .filter(Boolean);
259
271
  return relation.cardinality === 'one' ? items[0] : items;
@@ -267,9 +279,8 @@ const resolveRelationValue = async (db, edgeRows, relation) => {
267
279
  return relationValueFrom(edgeRows, relation, vertexIds, lookup);
268
280
  };
269
281
  const traverseRelation = async (db, startId, relation) => {
270
- var _a, _b, _c, _d, _e;
271
- const maxDepth = (_a = relation.maxDepth) !== null && _a !== void 0 ? _a : 1;
272
- const nodeCap = nodeCapFromLimit((_b = relation.mapping) === null || _b === void 0 ? void 0 : _b.limit);
282
+ const maxDepth = relation.maxDepth ?? 1;
283
+ const nodeCap = nodeCapFromLimit(relation.mapping?.limit);
273
284
  const edgeTableRef = getEdgeTable(edgeCollectionName(relation.edgeCollection));
274
285
  const edgeTable = asTable(edgeTableRef);
275
286
  const collected = [];
@@ -303,7 +314,7 @@ const traverseRelation = async (db, startId, relation) => {
303
314
  const vertexCollection = vertexCollectionFor(relation);
304
315
  if (!vertexCollection)
305
316
  break;
306
- let vertices = await fetchRowsByIds(db, vertexCollection, vertexIds, (_c = relation.mapping) === null || _c === void 0 ? void 0 : _c.softDelete);
317
+ let vertices = await fetchRowsByIds(db, vertexCollection, vertexIds, relation.mapping?.softDelete);
307
318
  if (relation.mapping) {
308
319
  vertices = await hydrateMapData(db, relation.mapping, vertices);
309
320
  }
@@ -311,7 +322,7 @@ const traverseRelation = async (db, startId, relation) => {
311
322
  frontier = vertexIds;
312
323
  }
313
324
  // BFS is nearest-first; conversation roots need mapping sort (e.g. id ASC).
314
- return applyLimit(applySort(collected, (_d = relation.mapping) === null || _d === void 0 ? void 0 : _d.sort), (_e = relation.mapping) === null || _e === void 0 ? void 0 : _e.limit);
325
+ return applyLimit(applySort(collected, relation.mapping?.sort), relation.mapping?.limit);
315
326
  };
316
327
  export const executeFind = async (db, collection, mapData, id, ignoreSoftDelete = false) => {
317
328
  if (!id)
@@ -320,12 +331,12 @@ export const executeFind = async (db, collection, mapData, id, ignoreSoftDelete
320
331
  const table = asTable(tableRef);
321
332
  const columns = getTableColumns(tableRef);
322
333
  const computedSelect = buildComputedSelect(mapData, tableRef);
323
- const conditions = [eq(table.id, id)];
334
+ const conditions = [eq(documentIdColumn(collection, table), id)];
324
335
  if (!ignoreSoftDelete && mapData.softDelete !== false && table.deletedAt) {
325
336
  conditions.push(sql `${table.deletedAt} IS NULL`);
326
337
  }
327
338
  const rows = await db
328
- .select(Object.assign(Object.assign({}, columns), computedSelect))
339
+ .select({ ...columns, ...computedSelect })
329
340
  .from(tableRef)
330
341
  .where(and(...conditions))
331
342
  .limit(1);
@@ -338,16 +349,15 @@ export const executeFind = async (db, collection, mapData, id, ignoreSoftDelete
338
349
  return hydrated[0];
339
350
  };
340
351
  export const executeAll = async (db, mapData) => {
341
- var _a;
342
352
  const tableRef = getTableForCollection(mapData.collection);
343
353
  const table = asTable(tableRef);
344
354
  const { sqlWhere, postFilters } = partitionFilters(mapData.collection, table, mapData.filters, mapData.defaultFilter, mapData.softDelete);
345
355
  const orderBy = sortToSqlOrderBy(mapData.collection, tableRef, mapData.sort, mapData.activityWindow);
346
- const canSqlPaginate = postFilters.length === 0 && (!((_a = mapData.sort) === null || _a === void 0 ? void 0 : _a.length) || !!orderBy);
356
+ const canSqlPaginate = postFilters.length === 0 && (!mapData.sort?.length || !!orderBy);
347
357
  const columns = getTableColumns(tableRef);
348
358
  const computedSelect = buildComputedSelect(mapData, tableRef);
349
359
  let query = db
350
- .select(Object.assign(Object.assign({}, columns), computedSelect))
360
+ .select({ ...columns, ...computedSelect })
351
361
  .from(tableRef)
352
362
  .$dynamic();
353
363
  if (sqlWhere)
@@ -369,7 +379,6 @@ export const executeAll = async (db, mapData) => {
369
379
  return docs;
370
380
  };
371
381
  export const executeCount = async (db, mapData) => {
372
- var _a, _b;
373
382
  const table = getTableForCollection(mapData.collection);
374
383
  const { sqlWhere, postFilters } = partitionFilters(mapData.collection, table, mapData.filters, mapData.defaultFilter, mapData.softDelete);
375
384
  if (!postFilters.length) {
@@ -377,9 +386,9 @@ export const executeCount = async (db, mapData) => {
377
386
  .select({ value: sql `count(*)::int` })
378
387
  .from(table)
379
388
  .where(sqlWhere));
380
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0);
389
+ return Number(rows[0]?.value ?? 0);
381
390
  }
382
- const docs = await executeAll(db, Object.assign(Object.assign({}, mapData), { limit: undefined }));
391
+ const docs = await executeAll(db, { ...mapData, limit: undefined });
383
392
  return docs.length;
384
393
  };
385
394
  export const executeFirst = async (db, mapData) => {
@@ -387,7 +396,6 @@ export const executeFirst = async (db, mapData) => {
387
396
  return limited[0];
388
397
  };
389
398
  export const relationsFrom = async (db, start, _parentCollection, relation) => {
390
- var _a;
391
399
  // Match attachRelation: honor maxDepth via BFS traversal. Without this,
392
400
  // callers like getConversationByStart only see direct (depth-1) replies.
393
401
  if (relation.maxDepth && relation.maxDepth > 1) {
@@ -419,7 +427,7 @@ export const relationsFrom = async (db, start, _parentCollection, relation) => {
419
427
  if (relation.cardinality === 'one') {
420
428
  return value ? [value] : [];
421
429
  }
422
- return (_a = value) !== null && _a !== void 0 ? _a : [];
430
+ return value ?? [];
423
431
  };
424
432
  export const evaluateDerived = async (db, doc, derived) => derived.resolve(db, doc);
425
433
  export const deleteRelationsFor = async (db, startId, relation) => {
@@ -438,7 +446,7 @@ export const deleteRelationsFor = async (db, startId, relation) => {
438
446
  const vertexTable = asTable(vertexTableRef);
439
447
  await db
440
448
  .delete(vertexTableRef)
441
- .where(eq(vertexTable.id, vertexId));
449
+ .where(eq(documentIdColumn(relation.mapping.collection, vertexTable), vertexId));
442
450
  }
443
451
  await db
444
452
  .delete(edgeTableRef)
@@ -1,16 +1,3 @@
1
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
2
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
3
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
5
- return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
6
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
7
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
8
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
9
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
10
- function fulfill(value) { resume("next", value); }
11
- function reject(value) { resume("throw", value); }
12
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
13
- };
14
1
  import { and, sql } from 'drizzle-orm';
15
2
  import { applyLimit, applyPostFilters, applySort, applySqlLimit, partitionFilters, } from './filters.js';
16
3
  import { hydrateMapData } from './relations.js';
@@ -44,13 +31,12 @@ const fieldToSql = (collection, field) => {
44
31
  const scalars = scalarFields[collection];
45
32
  const path = normalizeSearchPath(collection, field);
46
33
  const top = path.split('.')[0];
47
- if (scalars === null || scalars === void 0 ? void 0 : scalars[top]) {
34
+ if (scalars?.[top]) {
48
35
  return sql.raw(`"${scalars[top]}"`);
49
36
  }
50
37
  return jsonBodyTextExpr(path);
51
38
  };
52
39
  const fieldMatchesQuery = (collection, field, query, mode = 'substring') => {
53
- var _a;
54
40
  const like = mode === 'prefix' ? `${query}%` : `%${query}%`;
55
41
  const scalarFields = {
56
42
  profiles: { handle: 'handle' },
@@ -59,7 +45,7 @@ const fieldMatchesQuery = (collection, field, query, mode = 'substring') => {
59
45
  };
60
46
  const path = normalizeSearchPath(collection, field);
61
47
  const top = path.split('.')[0];
62
- if ((_a = scalarFields[collection]) === null || _a === void 0 ? void 0 : _a[top]) {
48
+ if (scalarFields[collection]?.[top]) {
63
49
  return sql `${fieldToSql(collection, field)} ILIKE ${like}`;
64
50
  }
65
51
  const parts = path.split('.');
@@ -102,10 +88,8 @@ const buildSearchWhere = (collection, fields, query, table) => {
102
88
  return sql `(${tsvectorExpr} @@ ${tsQuery} OR ${sql.join(ilikeParts, sql ` OR `)})`;
103
89
  };
104
90
  export const buildSearchResult = (mapData, searchDefinition) => {
105
- var _a;
106
- const collection = (_a = searchViewCollections[searchDefinition.view]) !== null && _a !== void 0 ? _a : mapData.collection;
91
+ const collection = searchViewCollections[searchDefinition.view] ?? mapData.collection;
107
92
  const runSearch = async (db) => {
108
- var _a;
109
93
  const tableRef = getTableForCollection(collection);
110
94
  const table = asTable(tableRef);
111
95
  const { sqlWhere, postFilters } = collection === mapData.collection
@@ -117,7 +101,7 @@ export const buildSearchResult = (mapData, searchDefinition) => {
117
101
  const rank = searchableCollections.has(collection)
118
102
  ? sql `ts_rank(${searchVectorExpr(table)}, ${tsQuery})`
119
103
  : sql `ts_rank(to_tsvector('english', coalesce(${table.body}::text, '')), ${tsQuery})`;
120
- const pageLimit = (_a = searchDefinition.limit) !== null && _a !== void 0 ? _a : mapData.limit;
104
+ const pageLimit = searchDefinition.limit ?? mapData.limit;
121
105
  // When post-filters must run in JS, fetch the full match set; otherwise
122
106
  // page in SQL so we only hydrate the requested window.
123
107
  let selectQuery = db
@@ -135,17 +119,14 @@ export const buildSearchResult = (mapData, searchDefinition) => {
135
119
  const rows = await selectQuery;
136
120
  let docs = rows.map(({ row, score }) => ({
137
121
  data: rowToDocument(collection, row),
138
- score: score !== null && score !== void 0 ? score : 0,
122
+ score: score ?? 0,
139
123
  }));
140
124
  if (collection === mapData.collection && docs.length) {
141
125
  const hydrated = await hydrateMapData(db, mapData, docs.map((d) => d.data), postFilters);
142
- docs = hydrated.map((data, i) => {
143
- var _a, _b;
144
- return ({
145
- data: data,
146
- score: (_b = (_a = docs[i]) === null || _a === void 0 ? void 0 : _a.score) !== null && _b !== void 0 ? _b : 0,
147
- });
148
- });
126
+ docs = hydrated.map((data, i) => ({
127
+ data: data,
128
+ score: docs[i]?.score ?? 0,
129
+ }));
149
130
  if (postFilters.length) {
150
131
  const kept = new Set(applyPostFilters(docs.map((d) => d.data), postFilters));
151
132
  docs = docs.filter((d) => kept.has(d.data));
@@ -155,7 +136,6 @@ export const buildSearchResult = (mapData, searchDefinition) => {
155
136
  return applyLimit(docs, pageLimit);
156
137
  };
157
138
  const runCount = async (db) => {
158
- var _a, _b;
159
139
  const tableRef = getTableForCollection(collection);
160
140
  const { sqlWhere, postFilters } = collection === mapData.collection
161
141
  ? partitionFilters(mapData.collection, tableRef, mapData.filters, mapData.defaultFilter, mapData.softDelete)
@@ -167,7 +147,7 @@ export const buildSearchResult = (mapData, searchDefinition) => {
167
147
  .select({ value: sql `count(*)::int` })
168
148
  .from(tableRef)
169
149
  .where(where));
170
- return Number((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0);
150
+ return Number(rows[0]?.value ?? 0);
171
151
  }
172
152
  return runSearch(db).then((rows) => rows.length);
173
153
  };
@@ -175,16 +155,14 @@ export const buildSearchResult = (mapData, searchDefinition) => {
175
155
  all: (db) => runSearch(db),
176
156
  count: (db) => runCount(db),
177
157
  first: (db) => runSearch(db).then((rows) => rows[0]),
178
- limit: (limit) => buildSearchResult(Object.assign(Object.assign({}, mapData), { limit: limit }), searchDefinition),
158
+ limit: (limit) => buildSearchResult({ ...mapData, limit: limit }, searchDefinition),
179
159
  query: () => {
180
160
  throw new Error('query() is not supported for Postgres fulltextSearch');
181
161
  },
182
- cursor: function (db) {
183
- return __asyncGenerator(this, arguments, function* () {
184
- for (const row of yield __await(runSearch(db))) {
185
- yield yield __await(row);
186
- }
187
- });
162
+ cursor: async function* (db) {
163
+ for (const row of await runSearch(db)) {
164
+ yield row;
165
+ }
188
166
  },
189
167
  };
190
168
  };
@@ -13,9 +13,15 @@ export const normalizeComputedDatetime = (value) => {
13
13
  return normalizeIsoDatetime(value);
14
14
  return null;
15
15
  };
16
- export const rowToModel = (id, data, timestamps) => (Object.assign(Object.assign(Object.assign({ id }, data), { createdAt: normalizeIsoDatetime(timestamps.createdAt), updatedAt: normalizeIsoDatetime(timestamps.updatedAt) }), (timestamps.deletedAt
17
- ? { deletedAt: normalizeIsoDatetime(timestamps.deletedAt) }
18
- : {})));
16
+ export const rowToModel = (id, data, timestamps) => ({
17
+ id,
18
+ ...data,
19
+ createdAt: normalizeIsoDatetime(timestamps.createdAt),
20
+ updatedAt: normalizeIsoDatetime(timestamps.updatedAt),
21
+ ...(timestamps.deletedAt
22
+ ? { deletedAt: normalizeIsoDatetime(timestamps.deletedAt) }
23
+ : {}),
24
+ });
19
25
  export const modelTimestampsFromRow = (row) => ({
20
26
  createdAt: normalizeIsoDatetime(row.createdAt),
21
27
  updatedAt: normalizeIsoDatetime(row.updatedAt),
@@ -23,7 +29,7 @@ export const modelTimestampsFromRow = (row) => ({
23
29
  });
24
30
  export const notDeleted = (row) => !row.deletedAt;
25
31
  export const nowIso = () => new Date().toISOString();
26
- export const mergeDocumentBody = (row, scalars = {}) => {
27
- var _a;
28
- return (Object.assign(Object.assign({}, ((_a = row.body) !== null && _a !== void 0 ? _a : {})), scalars));
29
- };
32
+ export const mergeDocumentBody = (row, scalars = {}) => ({
33
+ ...(row.body ?? {}),
34
+ ...scalars,
35
+ });
@@ -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: (databaseType: "arango" | "postgres", schemaVersion?: string) => string;
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
  /**
@@ -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 = (databaseType, schemaVersion) => {
62
- if (databaseType === 'arango') {
63
- return getFirstSchemaVersion();
64
- }
60
+ export const resolveRestoreSchemaVersion = (schemaVersion) => {
65
61
  if (schemaVersion) {
66
62
  return assertKnownSchemaVersion(schemaVersion);
67
63
  }
@@ -76,7 +72,7 @@ const buildMigrationsFolderUpTo = async (tag) => {
76
72
  const entries = journal.entries.slice(0, endIdx + 1);
77
73
  const folder = await mkdtemp(join(tmpdir(), 'op-migrate-'));
78
74
  await mkdir(join(folder, 'meta'), { recursive: true });
79
- await writeFile(join(folder, 'meta', '_journal.json'), `${JSON.stringify(Object.assign(Object.assign({}, journal), { entries }), null, 2)}\n`);
75
+ await writeFile(join(folder, 'meta', '_journal.json'), `${JSON.stringify({ ...journal, entries }, null, 2)}\n`);
80
76
  for (const entry of entries) {
81
77
  copyFileSync(join(migrationsFolder, `${entry.tag}.sql`), join(folder, `${entry.tag}.sql`));
82
78
  }
@@ -108,10 +104,9 @@ const APP_TABLE_NAMES = [
108
104
  ...EDGE_IMPORT_ORDER.map((collection) => getTableName(getTableForCollection(collection))),
109
105
  ];
110
106
  const tableExists = async (tableName) => {
111
- var _a;
112
107
  const db = pgDb();
113
108
  const result = await db.execute(sql.raw(`SELECT to_regclass('public.${tableName}')::text AS regclass`));
114
- return ((_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.regclass) != null;
109
+ return result.rows[0]?.regclass != null;
115
110
  };
116
111
  const missingAppTables = async () => {
117
112
  const missing = [];
@@ -144,8 +139,12 @@ const isSchemaConflictError = (err) => {
144
139
  const code = candidate.code;
145
140
  // 23505 unique_violation (e.g. orphan composite type in pg_type)
146
141
  // 42P07 duplicate_table
142
+ // 42701 duplicate_column (partial migrate left a column, journal did not)
147
143
  // 3F000 invalid_schema_name (stale search_path after DROP public)
148
- return code === '23505' || code === '42P07' || code === '3F000';
144
+ return (code === '23505' ||
145
+ code === '42P07' ||
146
+ code === '42701' ||
147
+ code === '3F000');
149
148
  });
150
149
  };
151
150
  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, reactions, repost, replyTo, } from '../schema/edges.js';
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`;
@@ -9,18 +9,18 @@ const edgeOutboundCount = (edgeTable, outerTable, window) => {
9
9
  const conditions = [
10
10
  sql `${edgeTable.fromId} = ${outerIdText(outerTable)}`,
11
11
  ];
12
- if (window === null || window === void 0 ? void 0 : window.start) {
12
+ if (window?.start) {
13
13
  conditions.push(gte(edgeTable.createdAt, window.start.toISOString()));
14
14
  }
15
- if (window === null || window === void 0 ? void 0 : window.end) {
15
+ if (window?.end) {
16
16
  conditions.push(lt(edgeTable.createdAt, window.end.toISOString()));
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(reactions, outerTable, window)}, 0) + COALESCE(${edgeOutboundCount(follows, outerTable, window)}, 0)`;
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 ${reactions} WHERE ${reactions.toId} = ${postId}) + (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})`;
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');