@openpeepshq/core 0.1.34 → 0.2.0

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 (192) 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 +13 -8
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +1 -2
  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 +116 -135
  14. package/dist/analytics/report.d.ts +2 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +13 -16
  18. package/dist/backups/metadata.js +1 -1
  19. package/dist/config/db.js +2 -4
  20. package/dist/config/defaults/community.js +1 -0
  21. package/dist/config/defaults/core.js +13 -8
  22. package/dist/config/defaults/logs.d.ts +4 -0
  23. package/dist/config/defaults/logs.js +5 -0
  24. package/dist/config/index.d.ts +9 -0
  25. package/dist/config/index.js +9 -11
  26. package/dist/db/explorer/query.js +9 -8
  27. package/dist/db/explorer/sql.js +8 -8
  28. package/dist/db/helpers.js +15 -5
  29. package/dist/db/migration/importCollections.js +15 -18
  30. package/dist/db/migration/shared.js +15 -35
  31. package/dist/db/pg/client.js +4 -7
  32. package/dist/db/pg/filters/index.js +1 -1
  33. package/dist/db/pg/filters/posts.d.ts +2 -0
  34. package/dist/db/pg/filters/posts.js +3 -1
  35. package/dist/db/pg/helpers.js +2 -14
  36. package/dist/db/pg/map/filters.js +8 -8
  37. package/dist/db/pg/map/helpers.js +5 -1
  38. package/dist/db/pg/map/index.js +46 -51
  39. package/dist/db/pg/map/mutations.js +56 -21
  40. package/dist/db/pg/map/registry.js +87 -50
  41. package/dist/db/pg/map/relations.js +67 -63
  42. package/dist/db/pg/map/search.js +15 -37
  43. package/dist/db/pg/mappers.js +13 -7
  44. package/dist/db/pg/migrate.js +2 -3
  45. package/dist/db/pg/queries/activity.js +2 -2
  46. package/dist/db/pg/queries/derived.js +8 -12
  47. package/dist/db/pg/schema/documents.js +119 -18
  48. package/dist/db/pg/schema/edges.js +7 -1
  49. package/dist/db/pg/schema/index.js +5 -1
  50. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  51. package/dist/db/pg/sql/meta/_journal.json +8 -1
  52. package/dist/db/replaceOrigin.js +1 -1
  53. package/dist/email/queueStats.js +8 -11
  54. package/dist/email/render.js +7 -4
  55. package/dist/email/send.js +19 -17
  56. package/dist/email/smtpTest.js +10 -6
  57. package/dist/errors/index.js +1 -1
  58. package/dist/events/once.js +2 -4
  59. package/dist/federation/activities.js +1 -2
  60. package/dist/groups/finders.d.ts +2 -2
  61. package/dist/groups/helpers.d.ts +6 -6
  62. package/dist/groups/helpers.js +1 -2
  63. package/dist/groups/mapping.d.ts +4 -4
  64. package/dist/groups/mutations.js +1 -1
  65. package/dist/hashtags/finders.js +2 -2
  66. package/dist/inviteLinks/mutations.js +2 -3
  67. package/dist/jams/export.js +5 -7
  68. package/dist/jams/finders.js +4 -1
  69. package/dist/jams/health.d.ts +6 -4
  70. package/dist/jams/health.js +15 -11
  71. package/dist/jams/helpers.d.ts +2 -2
  72. package/dist/jams/helpers.js +6 -2
  73. package/dist/jams/index.js +2 -2
  74. package/dist/jams/jobs.js +1 -2
  75. package/dist/jams/livekit.d.ts +2 -2
  76. package/dist/jams/livekit.js +8 -8
  77. package/dist/jams/mapping.d.ts +10 -10
  78. package/dist/jams/mutations.d.ts +2 -2
  79. package/dist/jams/recording.js +1 -1
  80. package/dist/jams/token.js +13 -17
  81. package/dist/jobs/index.js +7 -6
  82. package/dist/jobs/jobDetail.js +5 -6
  83. package/dist/jobs/jobLog.js +2 -3
  84. package/dist/lib/streams.js +4 -39
  85. package/dist/lib/zodDeepPartial.d.ts +1 -1
  86. package/dist/lib/zodDeepPartial.js +1 -1
  87. package/dist/log/index.d.ts +1 -0
  88. package/dist/log/index.js +14 -29
  89. package/dist/log/retention.d.ts +9 -0
  90. package/dist/log/retention.js +83 -0
  91. package/dist/log/retentionJobs.d.ts +17 -0
  92. package/dist/log/retentionJobs.js +50 -0
  93. package/dist/media/index.js +127 -4
  94. package/dist/media/jobs.js +1 -2
  95. package/dist/media/openpeeps/index.js +11 -46
  96. package/dist/media/processing.js +7 -4
  97. package/dist/media/streaming.js +5 -5
  98. package/dist/media/streamingCleanupJobs.js +1 -2
  99. package/dist/media/streamingJobs.js +3 -4
  100. package/dist/media/streamingPrewarm.js +7 -11
  101. package/dist/mediaAttachments/index.js +6 -2
  102. package/dist/mediaAttachments/mapping.d.ts +1 -1
  103. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  104. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  105. package/dist/notifications/defaultNotifications/follow/index.js +14 -17
  106. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  107. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  108. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  109. package/dist/notifications/defaultNotifications/jamModerator/index.js +27 -20
  110. package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
  111. package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
  112. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  113. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  114. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  115. package/dist/notifications/defaultNotifications/newGroupPost/index.js +9 -10
  116. package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
  117. package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
  118. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  119. package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
  120. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
  121. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  122. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  123. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  124. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  125. package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
  126. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
  127. package/dist/notifications/eventIcsAttachment.d.ts +6 -0
  128. package/dist/notifications/eventIcsAttachment.js +32 -0
  129. package/dist/notifications/fcmCredential.js +1 -1
  130. package/dist/notifications/finders.js +1 -1
  131. package/dist/notifications/helpers.d.ts +11 -1
  132. package/dist/notifications/helpers.js +38 -9
  133. package/dist/notifications/jobs.js +16 -7
  134. package/dist/notifications/mutations.js +13 -2
  135. package/dist/notifications/push.js +11 -16
  136. package/dist/performance/index.js +3 -3
  137. package/dist/plugins/helpers.js +3 -6
  138. package/dist/plugins/index.js +2 -3
  139. package/dist/plugins/install.js +31 -17
  140. package/dist/plugins/pluginAuth.js +3 -4
  141. package/dist/plugins/state.js +2 -3
  142. package/dist/posts/activity.d.ts +1 -1
  143. package/dist/posts/activity.js +2 -3
  144. package/dist/posts/contextClosure.js +1 -2
  145. package/dist/posts/conversationQueries.js +2 -4
  146. package/dist/posts/eventAgenda.js +12 -7
  147. package/dist/posts/eventOccurrences.js +2 -2
  148. package/dist/posts/finders.d.ts +46 -6
  149. package/dist/posts/finders.js +21 -9
  150. package/dist/posts/helpers/filters.js +2 -3
  151. package/dist/posts/helpers/index.d.ts +170 -18
  152. package/dist/posts/helpers/index.js +43 -27
  153. package/dist/posts/mapping.d.ts +616 -84
  154. package/dist/posts/mapping.js +60 -18
  155. package/dist/posts/mutations.d.ts +85 -9
  156. package/dist/posts/mutations.js +47 -34
  157. package/dist/posts/pollEnd.js +3 -6
  158. package/dist/posts/rsvpConfirmationEmail.js +18 -8
  159. package/dist/posts/threadPreview.js +1 -1
  160. package/dist/processingStats/queries.js +6 -7
  161. package/dist/profileSettings/cache.js +1 -2
  162. package/dist/profileSettings/mapping.d.ts +1 -0
  163. package/dist/profiles/activitySummary.js +23 -28
  164. package/dist/profiles/cache.js +15 -8
  165. package/dist/profiles/export.js +30 -39
  166. package/dist/profiles/finders.js +7 -5
  167. package/dist/profiles/mapping.d.ts +10 -10
  168. package/dist/profiles/mutations.js +3 -5
  169. package/dist/redis/connection.js +1 -1
  170. package/dist/reports/helpers.js +7 -3
  171. package/dist/reports/mapping.d.ts +1 -1
  172. package/dist/roles/mutations.js +20 -21
  173. package/dist/search/finders.js +15 -3
  174. package/dist/search/helpers.js +1 -1
  175. package/dist/sentry/index.js +9 -11
  176. package/dist/seo/index.d.ts +50 -0
  177. package/dist/seo/index.js +145 -0
  178. package/dist/seo/route.d.ts +18 -0
  179. package/dist/seo/route.js +19 -0
  180. package/dist/server/index.d.ts +1 -0
  181. package/dist/server/index.js +16 -11
  182. package/dist/server/status.js +6 -7
  183. package/dist/session/index.js +2 -2
  184. package/dist/stats/finders.js +13 -4
  185. package/dist/stats/helpers.js +4 -1
  186. package/dist/stats/mapping.d.ts +43 -5
  187. package/dist/stats/mapping.js +9 -2
  188. package/dist/stripe/cache.js +5 -6
  189. package/dist/stripe/connection.js +3 -4
  190. package/dist/stripe/helpers.js +15 -20
  191. package/package.json +5 -6
  192. package/LICENSE +0 -674
@@ -3,21 +3,17 @@ import { applyDateRangeToEdgeSql, applyLimit, applyPostFilters, applySqlLimit, a
3
3
  import { isSqlFilter } from '../filters/index.js';
4
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';
@@ -73,7 +69,7 @@ export const fetchFilteredRowsByIds = async (db, mapData, ids) => {
73
69
  const columns = getTableColumns(tableRef);
74
70
  const computedSelect = buildComputedSelect(mapData, tableRef);
75
71
  let query = db
76
- .select(Object.assign(Object.assign({}, columns), computedSelect))
72
+ .select({ ...columns, ...computedSelect })
77
73
  .from(tableRef)
78
74
  .where(and(...conditions))
79
75
  .$dynamic();
@@ -88,56 +84,65 @@ export const fetchFilteredRowsByIds = async (db, mapData, ids) => {
88
84
  return { docs, postFilters };
89
85
  };
90
86
  const hydrateDocuments = async (db, collection, mapData, rows, postFilters) => {
91
- var _a, _b, _c, _d;
92
87
  let docs = rows;
93
- for (const relation of (_a = mapData.relations) !== null && _a !== void 0 ? _a : []) {
88
+ for (const relation of mapData.relations ?? []) {
94
89
  docs = await attachRelation(db, collection, docs, relation);
95
90
  }
96
- for (const fkr of (_b = mapData.foreignKeyRelations) !== null && _b !== void 0 ? _b : []) {
91
+ for (const fkr of mapData.foreignKeyRelations ?? []) {
97
92
  docs = await attachForeignKeyRelation(db, docs, fkr);
98
93
  }
99
94
  docs = await attachDerivedProperties(db, docs, mapData.derivedProperties);
100
- 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);
101
96
  docs = applySort(docs, mapData.sort);
102
- for (const relation of (_c = mapData.postFilterRelations) !== null && _c !== void 0 ? _c : []) {
97
+ for (const relation of mapData.postFilterRelations ?? []) {
103
98
  docs = await attachRelation(db, collection, docs, relation);
104
99
  }
105
- for (const fkr of (_d = mapData.postFilterForeignKeyRelations) !== null && _d !== void 0 ? _d : []) {
100
+ for (const fkr of mapData.postFilterForeignKeyRelations ?? []) {
106
101
  docs = await attachForeignKeyRelation(db, docs, fkr);
107
102
  }
108
103
  docs = await attachDerivedProperties(db, docs, mapData.postFilterDerivedProperties);
109
104
  return docs;
110
105
  };
111
106
  const attachDerivedProperties = async (db, docs, derivedProperties) => {
112
- if (!(derivedProperties === null || derivedProperties === void 0 ? void 0 : derivedProperties.length))
107
+ if (!derivedProperties?.length)
113
108
  return docs;
114
109
  let result = docs;
115
110
  for (const dp of derivedProperties) {
116
111
  if (dp.batchResolve) {
117
112
  const values = await dp.batchResolve(db, result);
118
- 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
+ }));
119
117
  continue;
120
118
  }
121
- 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
+ })));
122
123
  }
123
124
  return result;
124
125
  };
125
126
  export const hydrateMapData = async (db, mapData, rows, postFilters) => hydrateDocuments(db, mapData.collection, mapData, rows, postFilters);
126
127
  const attachForeignKeyRelation = async (db, docs, fkr) => Promise.all(docs.map(async (doc) => {
127
- var _a, _b;
128
128
  const raw = doc[fkr.foreignKeyProperty];
129
129
  const ids = fkr.cardinality === 'many'
130
- ? ((_a = raw) !== null && _a !== void 0 ? _a : [])
130
+ ? (raw ?? [])
131
131
  : raw
132
132
  ? [raw]
133
133
  : [];
134
134
  const loaded = (await Promise.all(ids.map((id) => executeFind(db, fkr.mapping.collection, fkr.mapping, id)))).filter(Boolean);
135
- 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
+ };
136
139
  }));
137
140
  const attachRelation = async (db, _parentCollection, docs, relation) => {
138
- var _a, _b;
139
141
  if (relation.maxDepth && relation.maxDepth > 1) {
140
- 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
+ })));
141
146
  }
142
147
  const edgeTableRef = getEdgeTable(edgeCollectionName(relation.edgeCollection));
143
148
  const edgeTable = asTable(edgeTableRef);
@@ -160,12 +165,12 @@ const attachRelation = async (db, _parentCollection, docs, relation) => {
160
165
  const grouped = new Map();
161
166
  for (const edge of edgeRows) {
162
167
  const parentId = edge[parentEdgeColumn(relation)];
163
- const list = (_a = grouped.get(parentId)) !== null && _a !== void 0 ? _a : [];
168
+ const list = grouped.get(parentId) ?? [];
164
169
  list.push(edge);
165
170
  grouped.set(parentId, list);
166
171
  }
167
172
  const vertexCol = vertexEdgeColumn(relation);
168
- const edgesFor = (doc) => { var _a; return (_a = grouped.get(doc.id)) !== null && _a !== void 0 ? _a : []; };
173
+ const edgesFor = (doc) => grouped.get(doc.id) ?? [];
169
174
  const edgeVertexIdsFor = (doc) => edgesFor(doc).map((edge) => edge[vertexCol]);
170
175
  // Vertices are fetched and hydrated once for the whole batch. Doing it per
171
176
  // parent row cost a query per row per relation, so one feed page ran
@@ -174,19 +179,28 @@ const attachRelation = async (db, _parentCollection, docs, relation) => {
174
179
  ...new Set(docs.flatMap(idsFor)),
175
180
  ];
176
181
  if (relation.count) {
177
- if (!((_b = relation.mapping) === null || _b === void 0 ? void 0 : _b.collection)) {
178
- 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
+ }));
179
187
  }
180
188
  const rows = await fetchRowsByIds(db, relation.mapping.collection, batchIdsFrom(edgeVertexIdsFor), relation.mapping.softDelete);
181
189
  const counted = new Set(applyPostFilters(rows, relation.mapping.filters, relation.mapping.defaultFilter).map((row) => row.id));
182
- 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
+ }));
183
194
  }
184
195
  const vertexIdsFor = (doc) => capVertexIds(edgeVertexIdsFor(doc), relation);
185
196
  const vertexCollection = vertexCollectionFor(relation);
186
197
  const lookup = vertexCollection
187
198
  ? await fetchVertexLookup(db, vertexCollection, batchIdsFrom(vertexIdsFor), relation)
188
199
  : emptyVertexLookup;
189
- 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
+ }));
190
204
  };
191
205
  const nodeCapFromLimit = (limit) => {
192
206
  if (limit == null)
@@ -200,8 +214,7 @@ const nodeCapFromLimit = (limit) => {
200
214
  * row data to sort on.
201
215
  */
202
216
  const capVertexIds = (vertexIds, relation) => {
203
- var _a;
204
- const nodeCap = nodeCapFromLimit((_a = relation.mapping) === null || _a === void 0 ? void 0 : _a.limit);
217
+ const nodeCap = nodeCapFromLimit(relation.mapping?.limit);
205
218
  if (nodeCap === undefined || relation.cardinality !== 'many') {
206
219
  return vertexIds;
207
220
  }
@@ -214,8 +227,7 @@ const emptyVertexLookup = {
214
227
  rank: () => 0,
215
228
  };
216
229
  const fetchVertexLookup = async (db, vertexCollection, vertexIds, relation) => {
217
- var _a;
218
- 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);
219
231
  const vertices = relation.mapping
220
232
  ? await hydrateMapData(db, relation.mapping, rows)
221
233
  : rows;
@@ -223,15 +235,11 @@ const fetchVertexLookup = async (db, vertexCollection, vertexIds, relation) => {
223
235
  const ranks = new Map(vertices.map((vertex, index) => [vertex.id, index]));
224
236
  return {
225
237
  get: (id) => byId.get(id),
226
- 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,
227
239
  };
228
240
  };
229
241
  const relationValueFrom = (edgeRows, relation, vertexIds, lookup) => {
230
- var _a, _b;
231
- const toEdgeDoc = (edge) => {
232
- var _a;
233
- return rowToDocument(edgeCollectionName(relation.edgeCollection), edge, (_a = relation.mapping) === null || _a === void 0 ? void 0 : _a.keepMetadata);
234
- };
242
+ const toEdgeDoc = (edge) => rowToDocument(edgeCollectionName(relation.edgeCollection), edge, relation.mapping?.keepMetadata);
235
243
  if (!vertexCollectionFor(relation)) {
236
244
  const items = edgeRows.map(toEdgeDoc);
237
245
  return relation.cardinality === 'one' ? items[0] : items;
@@ -243,7 +251,7 @@ const relationValueFrom = (edgeRows, relation, vertexIds, lookup) => {
243
251
  .filter((vertex) => !!vertex);
244
252
  if (relation.cardinality === 'one')
245
253
  return vertices[0];
246
- 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);
247
255
  }
248
256
  const vertexCol = vertexEdgeColumn(relation);
249
257
  const capped = new Set(vertexIds);
@@ -255,9 +263,9 @@ const relationValueFrom = (edgeRows, relation, vertexIds, lookup) => {
255
263
  return undefined;
256
264
  const edgeDoc = toEdgeDoc(edge);
257
265
  if (relation.vertexAlias) {
258
- return Object.assign(Object.assign({}, edgeDoc), { [relation.vertexAlias]: vertex });
266
+ return { ...edgeDoc, [relation.vertexAlias]: vertex };
259
267
  }
260
- return Object.assign(Object.assign({}, edgeDoc), vertex);
268
+ return { ...edgeDoc, ...vertex };
261
269
  })
262
270
  .filter(Boolean);
263
271
  return relation.cardinality === 'one' ? items[0] : items;
@@ -271,9 +279,8 @@ const resolveRelationValue = async (db, edgeRows, relation) => {
271
279
  return relationValueFrom(edgeRows, relation, vertexIds, lookup);
272
280
  };
273
281
  const traverseRelation = async (db, startId, relation) => {
274
- var _a, _b, _c, _d, _e;
275
- const maxDepth = (_a = relation.maxDepth) !== null && _a !== void 0 ? _a : 1;
276
- 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);
277
284
  const edgeTableRef = getEdgeTable(edgeCollectionName(relation.edgeCollection));
278
285
  const edgeTable = asTable(edgeTableRef);
279
286
  const collected = [];
@@ -307,7 +314,7 @@ const traverseRelation = async (db, startId, relation) => {
307
314
  const vertexCollection = vertexCollectionFor(relation);
308
315
  if (!vertexCollection)
309
316
  break;
310
- 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);
311
318
  if (relation.mapping) {
312
319
  vertices = await hydrateMapData(db, relation.mapping, vertices);
313
320
  }
@@ -315,7 +322,7 @@ const traverseRelation = async (db, startId, relation) => {
315
322
  frontier = vertexIds;
316
323
  }
317
324
  // BFS is nearest-first; conversation roots need mapping sort (e.g. id ASC).
318
- 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);
319
326
  };
320
327
  export const executeFind = async (db, collection, mapData, id, ignoreSoftDelete = false) => {
321
328
  if (!id)
@@ -329,7 +336,7 @@ export const executeFind = async (db, collection, mapData, id, ignoreSoftDelete
329
336
  conditions.push(sql `${table.deletedAt} IS NULL`);
330
337
  }
331
338
  const rows = await db
332
- .select(Object.assign(Object.assign({}, columns), computedSelect))
339
+ .select({ ...columns, ...computedSelect })
333
340
  .from(tableRef)
334
341
  .where(and(...conditions))
335
342
  .limit(1);
@@ -342,16 +349,15 @@ export const executeFind = async (db, collection, mapData, id, ignoreSoftDelete
342
349
  return hydrated[0];
343
350
  };
344
351
  export const executeAll = async (db, mapData) => {
345
- var _a;
346
352
  const tableRef = getTableForCollection(mapData.collection);
347
353
  const table = asTable(tableRef);
348
354
  const { sqlWhere, postFilters } = partitionFilters(mapData.collection, table, mapData.filters, mapData.defaultFilter, mapData.softDelete);
349
355
  const orderBy = sortToSqlOrderBy(mapData.collection, tableRef, mapData.sort, mapData.activityWindow);
350
- 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);
351
357
  const columns = getTableColumns(tableRef);
352
358
  const computedSelect = buildComputedSelect(mapData, tableRef);
353
359
  let query = db
354
- .select(Object.assign(Object.assign({}, columns), computedSelect))
360
+ .select({ ...columns, ...computedSelect })
355
361
  .from(tableRef)
356
362
  .$dynamic();
357
363
  if (sqlWhere)
@@ -373,7 +379,6 @@ export const executeAll = async (db, mapData) => {
373
379
  return docs;
374
380
  };
375
381
  export const executeCount = async (db, mapData) => {
376
- var _a, _b;
377
382
  const table = getTableForCollection(mapData.collection);
378
383
  const { sqlWhere, postFilters } = partitionFilters(mapData.collection, table, mapData.filters, mapData.defaultFilter, mapData.softDelete);
379
384
  if (!postFilters.length) {
@@ -381,9 +386,9 @@ export const executeCount = async (db, mapData) => {
381
386
  .select({ value: sql `count(*)::int` })
382
387
  .from(table)
383
388
  .where(sqlWhere));
384
- 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);
385
390
  }
386
- const docs = await executeAll(db, Object.assign(Object.assign({}, mapData), { limit: undefined }));
391
+ const docs = await executeAll(db, { ...mapData, limit: undefined });
387
392
  return docs.length;
388
393
  };
389
394
  export const executeFirst = async (db, mapData) => {
@@ -391,7 +396,6 @@ export const executeFirst = async (db, mapData) => {
391
396
  return limited[0];
392
397
  };
393
398
  export const relationsFrom = async (db, start, _parentCollection, relation) => {
394
- var _a;
395
399
  // Match attachRelation: honor maxDepth via BFS traversal. Without this,
396
400
  // callers like getConversationByStart only see direct (depth-1) replies.
397
401
  if (relation.maxDepth && relation.maxDepth > 1) {
@@ -423,7 +427,7 @@ export const relationsFrom = async (db, start, _parentCollection, relation) => {
423
427
  if (relation.cardinality === 'one') {
424
428
  return value ? [value] : [];
425
429
  }
426
- return (_a = value) !== null && _a !== void 0 ? _a : [];
430
+ return value ?? [];
427
431
  };
428
432
  export const evaluateDerived = async (db, doc, derived) => derived.resolve(db, doc);
429
433
  export const deleteRelationsFor = async (db, startId, relation) => {
@@ -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
+ });
@@ -72,7 +72,7 @@ const buildMigrationsFolderUpTo = async (tag) => {
72
72
  const entries = journal.entries.slice(0, endIdx + 1);
73
73
  const folder = await mkdtemp(join(tmpdir(), 'op-migrate-'));
74
74
  await mkdir(join(folder, 'meta'), { recursive: true });
75
- 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`);
76
76
  for (const entry of entries) {
77
77
  copyFileSync(join(migrationsFolder, `${entry.tag}.sql`), join(folder, `${entry.tag}.sql`));
78
78
  }
@@ -104,10 +104,9 @@ const APP_TABLE_NAMES = [
104
104
  ...EDGE_IMPORT_ORDER.map((collection) => getTableName(getTableForCollection(collection))),
105
105
  ];
106
106
  const tableExists = async (tableName) => {
107
- var _a;
108
107
  const db = pgDb();
109
108
  const result = await db.execute(sql.raw(`SELECT to_regclass('public.${tableName}')::text AS regclass`));
110
- return ((_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.regclass) != null;
109
+ return result.rows[0]?.regclass != null;
111
110
  };
112
111
  const missingAppTables = async () => {
113
112
  const missing = [];
@@ -9,10 +9,10 @@ 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)})`;
@@ -12,16 +12,14 @@ const maxIso = (values) => {
12
12
  };
13
13
  export const profileDerived = {
14
14
  postsCount: async (db, doc) => {
15
- var _a, _b;
16
15
  const postsTable = asTable(posts);
17
16
  const rows = await db
18
17
  .select({ count: sql `count(*)::int` })
19
18
  .from(posts)
20
19
  .where(and(eq(postsTable.creatorId, doc.id), sql `${postsTable.deletedAt} IS NULL`));
21
- return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0;
20
+ return rows[0]?.count ?? 0;
22
21
  },
23
22
  lastSeen: async (db, doc) => {
24
- var _a, _b;
25
23
  const profileId = doc.id;
26
24
  const entriesTable = asTable(entries);
27
25
  const postSeenTable = asTable(postSeen);
@@ -36,8 +34,8 @@ export const profileDerived = {
36
34
  .where(eq(postSeenTable.fromId, profileId)),
37
35
  ]);
38
36
  return maxIso([
39
- (_a = entryRows[0]) === null || _a === void 0 ? void 0 : _a.max,
40
- (_b = seenRows[0]) === null || _b === void 0 ? void 0 : _b.max,
37
+ entryRows[0]?.max,
38
+ seenRows[0]?.max,
41
39
  ]);
42
40
  },
43
41
  profileStats: (_db, doc) => ({
@@ -46,7 +44,6 @@ export const profileDerived = {
46
44
  }),
47
45
  /** Counts without loading follower/following trees. */
48
46
  profileStatsCounts: async (db, doc) => {
49
- var _a, _b, _c, _d;
50
47
  const edgeTableRef = getEdgeTable('follows');
51
48
  const edgeTable = asTable(edgeTableRef);
52
49
  const profileId = doc.id;
@@ -61,8 +58,8 @@ export const profileDerived = {
61
58
  .where(eq(edgeTable.fromId, profileId)),
62
59
  ]);
63
60
  return {
64
- followersCount: (_b = (_a = followersRows[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0,
65
- followingCount: (_d = (_c = followingRows[0]) === null || _c === void 0 ? void 0 : _c.count) !== null && _d !== void 0 ? _d : 0,
61
+ followersCount: followersRows[0]?.count ?? 0,
62
+ followingCount: followingRows[0]?.count ?? 0,
66
63
  };
67
64
  },
68
65
  };
@@ -103,19 +100,18 @@ export const postDerived = {
103
100
  return values;
104
101
  },
105
102
  }),
106
- inReplyToId: (_db, doc) => { var _a; return (_a = doc.replyTo) === null || _a === void 0 ? void 0 : _a.id; },
107
- groupId: (_db, doc) => { var _a; return (_a = doc.group) === null || _a === void 0 ? void 0 : _a.id; },
103
+ inReplyToId: (_db, doc) => doc.replyTo?.id,
104
+ groupId: (_db, doc) => doc.group?.id,
108
105
  };
109
106
  export const groupDerived = {
110
107
  lastPostAt: async (db, doc) => {
111
- var _a;
112
108
  const edgeTableRef = getEdgeTable('postGroups');
113
109
  const edgeTable = asTable(edgeTableRef);
114
110
  const rows = await db
115
111
  .select({ max: sql `max(${edgeTable.createdAt})` })
116
112
  .from(edgeTableRef)
117
113
  .where(eq(edgeTable.toId, doc.id));
118
- const value = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.max;
114
+ const value = rows[0]?.max;
119
115
  return value ? normalizeIsoDatetime(value) : null;
120
116
  },
121
117
  };