@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
@@ -6,17 +6,16 @@ const DEFAULT_SETTINGS = {
6
6
  recipients: [],
7
7
  };
8
8
  export const getAnalyticsReportSettings = async () => {
9
- var _a, _b, _c, _d;
10
9
  const db = await database();
11
10
  const rows = await db
12
11
  .select()
13
12
  .from(analyticsSettings)
14
13
  .where(eq(analyticsSettings.id, 'default'))
15
14
  .limit(1);
16
- const body = ((_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {});
15
+ const body = (rows[0]?.body ?? {});
17
16
  return {
18
- enabled: (_c = body.enabled) !== null && _c !== void 0 ? _c : DEFAULT_SETTINGS.enabled,
19
- recipients: (_d = body.recipients) !== null && _d !== void 0 ? _d : DEFAULT_SETTINGS.recipients,
17
+ enabled: body.enabled ?? DEFAULT_SETTINGS.enabled,
18
+ recipients: body.recipients ?? DEFAULT_SETTINGS.recipients,
20
19
  };
21
20
  };
22
21
  export const setAnalyticsReportSettings = async (settings) => {
@@ -1,4 +1,4 @@
1
- import { access, cp, mkdir, mkdtemp, readdir, rm, writeFile, readFile, } from 'node:fs/promises';
1
+ import { access, cp, mkdir, mkdtemp, readdir, rm, writeFile, readFile, stat, } from 'node:fs/promises';
2
2
  import { constants, createWriteStream } from 'node:fs';
3
3
  import { spawn } from 'node:child_process';
4
4
  import { emptyDir } from 'fs-extra';
@@ -7,26 +7,30 @@ import { tmpdir } from 'node:os';
7
7
  import archiver from 'archiver';
8
8
  import extract from 'extract-zip';
9
9
  import { collectionInfos } from '../db/index.js';
10
- import { communityConfig, config } from '../config/index.js';
11
- import { exportAllPostgresCollections, importAllArangoCollections, importAllPostgresCollections, } from '../db/migration/importCollections.js';
10
+ import { communityConfig, config, defaultConfig } from '../config/index.js';
11
+ import { exportAllPostgresCollections, importAllPostgresCollections, } from '../db/migration/importCollections.js';
12
12
  import { getLatestSchemaVersion } from '../db/pg/migrate.js';
13
13
  import { replaceOrigin } from '../db/replaceOrigin.js';
14
14
  import { logger } from '../log/index.js';
15
15
  import { setDefaultRoles } from '../roles/index.js';
16
+ import { backfillMissingEventOccurrences } from '../posts/eventOccurrences.js';
16
17
  import { serverRootUrl } from '../server/index.js';
17
- import { resolveBackupDatabaseType, } from './metadata.js';
18
+ import { linkHostPeerDependencies } from '../plugins/index.js';
19
+ import { resolveBackupDatabaseType } from './metadata.js';
18
20
  export { resolveBackupDatabaseType } from './metadata.js';
19
21
  const log = logger('core:backups');
22
+ const pathExists = (p) => access(p)
23
+ .then(() => true)
24
+ .catch(() => false);
20
25
  /** Safety net if extraction stalls (normal 1 GiB restore finishes in a few minutes). */
21
26
  const EXTRACT_TIMEOUT_MS = 30 * 60 * 1000;
22
27
  const extractWithUnzipCli = (zipPath, tempDir) => {
23
- var _a, _b;
24
28
  const proc = spawn('unzip', ['-qq', '-o', zipPath, '-d', tempDir], {
25
29
  stdio: ['ignore', 'ignore', 'pipe'],
26
30
  });
27
31
  let stderrTail = '';
28
- (_a = proc.stderr) === null || _a === void 0 ? void 0 : _a.setEncoding('utf8');
29
- (_b = proc.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (chunk) => {
32
+ proc.stderr?.setEncoding('utf8');
33
+ proc.stderr?.on('data', (chunk) => {
30
34
  stderrTail = (stderrTail + chunk).slice(-4096);
31
35
  });
32
36
  const promise = new Promise((resolve, reject) => {
@@ -41,7 +45,7 @@ const extractWithUnzipCli = (zipPath, tempDir) => {
41
45
  return;
42
46
  }
43
47
  const detail = stderrTail.trim();
44
- reject(new Error(`unzip exited with code ${code !== null && code !== void 0 ? code : 'null'}${detail ? `: ${detail}` : ''}`));
48
+ reject(new Error(`unzip exited with code ${code ?? 'null'}${detail ? `: ${detail}` : ''}`));
45
49
  });
46
50
  });
47
51
  return {
@@ -79,7 +83,7 @@ const extractZipArchive = (zipPath, tempDir) => {
79
83
  promise,
80
84
  kill: () => {
81
85
  cli.kill();
82
- fallbackKill === null || fallbackKill === void 0 ? void 0 : fallbackKill();
86
+ fallbackKill?.();
83
87
  },
84
88
  };
85
89
  };
@@ -104,13 +108,47 @@ const zipDirectory = (sourceDir, zipPath) => new Promise((resolve, reject) => {
104
108
  archive.directory(sourceDir, false);
105
109
  void archive.finalize();
106
110
  });
111
+ /**
112
+ * Peer-dependency symlinks in a restored plugin were created against the host
113
+ * packages of the image the backup came from. Re-anchor them to the current
114
+ * host tree so restored plugins resolve even after an image update.
115
+ */
116
+ const relinkRestoredPlugins = async (pluginsPath) => {
117
+ const namespaces = await readdir(pluginsPath).catch(() => []);
118
+ for (const namespace of namespaces) {
119
+ const namespaceDir = join(pluginsPath, namespace);
120
+ if (!(await stat(namespaceDir)
121
+ .then((s) => s.isDirectory())
122
+ .catch(() => false))) {
123
+ continue;
124
+ }
125
+ const names = await readdir(namespaceDir).catch(() => []);
126
+ for (const name of names) {
127
+ const pluginDir = join(namespaceDir, name);
128
+ let pkg;
129
+ try {
130
+ pkg = JSON.parse(await readFile(join(pluginDir, 'package.json'), 'utf8'));
131
+ }
132
+ catch {
133
+ continue;
134
+ }
135
+ const peers = Object.keys(pkg.peerDependencies ?? {});
136
+ if (peers.length === 0)
137
+ continue;
138
+ const linked = await linkHostPeerDependencies(pluginDir, peers);
139
+ if (!linked.success) {
140
+ log.warn(`Restored plugin ${pkg.name ?? pluginDir} peer re-link failed: ${linked.error}`);
141
+ }
142
+ }
143
+ }
144
+ };
107
145
  const withTimeout = (promise, ms, message, onTimeout) => {
108
146
  let timeoutId;
109
147
  return Promise.race([
110
148
  promise,
111
149
  new Promise((_, reject) => {
112
150
  timeoutId = setTimeout(() => {
113
- onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout();
151
+ onTimeout?.();
114
152
  reject(new Error(message));
115
153
  }, ms);
116
154
  }),
@@ -137,14 +175,13 @@ const assertBackupExtracted = async (tempDir) => {
137
175
  try {
138
176
  await access(metadataPath, constants.F_OK);
139
177
  }
140
- catch (_a) {
141
- // Legacy Arango JSONL templates (e.g. test-backup.zip) omit metadata.json.
142
- log.warn(`Backup has no metadata.json under ${tempDir}; treating as legacy Arango JSONL`);
178
+ catch {
179
+ throw new Error('Backup invalid: missing metadata.json (Postgres JSONL archives only)');
143
180
  }
144
181
  try {
145
182
  await access(collectionsPath, constants.F_OK);
146
183
  }
147
- catch (_b) {
184
+ catch {
148
185
  throw new Error('Backup invalid: missing collections/ directory after extract');
149
186
  }
150
187
  const files = await readdir(collectionsPath);
@@ -154,15 +191,14 @@ const assertBackupExtracted = async (tempDir) => {
154
191
  }
155
192
  log.info(`Found ${jsonlFiles.length} collection backup files in archive`);
156
193
  };
157
- const restoreDatabaseFromBackup = async (collectionsDir, databaseType, schemaVersion) => {
158
- log.info('Restoring %s database from JSONL collections', databaseType);
159
- const { total } = databaseType === 'postgres'
160
- ? await importAllPostgresCollections(collectionsDir, schemaVersion)
161
- : await importAllArangoCollections(collectionsDir);
194
+ const restoreDatabaseFromBackup = async (collectionsDir, schemaVersion) => {
195
+ log.info('Restoring postgres database from JSONL collections');
196
+ const { total } = await importAllPostgresCollections(collectionsDir, schemaVersion);
162
197
  if (total === 0) {
163
198
  throw new Error('Backup restore completed with zero rows; archive may be empty or corrupt');
164
199
  }
165
- log.info('Restored %d database rows from backup', total);
200
+ const backfilled = await backfillMissingEventOccurrences();
201
+ log.info('Restored %d database rows from backup; indexed %d events', total, backfilled);
166
202
  };
167
203
  export const createBackup = async () => {
168
204
  try {
@@ -187,6 +223,14 @@ export const createBackup = async () => {
187
223
  await cp(coreConfig.logs.local.path, logsDir, {
188
224
  recursive: true,
189
225
  });
226
+ // Admin-installed plugins, so restores and moves carry them with the
227
+ // instance. Missing (e.g. fresh installs) is not an error.
228
+ const pluginsPath = defaultConfig.plugins.path;
229
+ if (await pathExists(pluginsPath)) {
230
+ const backupPluginsDir = join(backupDir, 'plugins');
231
+ await mkdir(backupPluginsDir);
232
+ await cp(pluginsPath, backupPluginsDir, { recursive: true });
233
+ }
190
234
  await writeFile(join(metaDir, 'collectionInfos.json'), JSON.stringify(collectionInfos, null, 2));
191
235
  await writeFile(join(backupDir, 'metadata.json'), JSON.stringify({
192
236
  databaseType: 'postgres',
@@ -219,7 +263,6 @@ export const listAllBackups = async () => {
219
263
  .map((filename) => filename.replace('.zip', ''));
220
264
  };
221
265
  export const restoreBackups = async (zipFilePath) => {
222
- var _a, _b, _c;
223
266
  console.log('Restoring backup', zipFilePath);
224
267
  log.info(`Restoring backup ${zipFilePath}`);
225
268
  const coreConfig = await config();
@@ -244,7 +287,7 @@ export const restoreBackups = async (zipFilePath) => {
244
287
  const backupMetadata = await readFile(join(tempDir, 'metadata.json'), 'utf-8')
245
288
  .then(JSON.parse)
246
289
  .catch(() => undefined);
247
- const databaseType = resolveBackupDatabaseType(backupMetadata);
290
+ resolveBackupDatabaseType(backupMetadata);
248
291
  log.info(`Emptying media directory ${coreConfig.media.storage.params.path}`);
249
292
  await emptyDir(coreConfig.media.storage.params.path);
250
293
  log.info(`Copying media from backup to ${coreConfig.media.storage.params.path}`);
@@ -257,12 +300,26 @@ export const restoreBackups = async (zipFilePath) => {
257
300
  await cp(join(tempDir, 'logs'), coreConfig.logs.local.path, {
258
301
  recursive: true,
259
302
  });
260
- await restoreDatabaseFromBackup(collectionsDir, databaseType, backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.schemaVersion);
303
+ // Older images never archived plugins; never wipe a live plugins tree for
304
+ // such a backup.
305
+ const pluginsPath = defaultConfig.plugins.path;
306
+ const backupPluginsDir = join(tempDir, 'plugins');
307
+ if (await pathExists(backupPluginsDir)) {
308
+ log.info(`Emptying plugins directory ${pluginsPath}`);
309
+ await emptyDir(pluginsPath);
310
+ log.info(`Copying plugins from backup to ${pluginsPath}`);
311
+ await cp(backupPluginsDir, pluginsPath, { recursive: true });
312
+ await relinkRestoredPlugins(pluginsPath);
313
+ }
314
+ else {
315
+ log.info('Backup contains no plugins; leaving existing plugins in place.');
316
+ }
317
+ await restoreDatabaseFromBackup(collectionsDir, backupMetadata?.schemaVersion);
261
318
  // Repoint the backup's absolute URLs at this server's full origin (scheme +
262
319
  // host + port). Matching by the backup hostname means a prod backup on
263
320
  // `https://host` restores cleanly onto `http://localhost:5174` without
264
321
  // stranding the old scheme/port.
265
- await replaceOrigin((_a = backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.config) === null || _a === void 0 ? void 0 : _a.hostname, await serverRootUrl());
266
- log.info(`Restored ${databaseType} backup (hostname was ${(_c = (_b = backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.config) === null || _b === void 0 ? void 0 : _b.hostname) !== null && _c !== void 0 ? _c : 'unknown'})`);
322
+ await replaceOrigin(backupMetadata?.config?.hostname, await serverRootUrl());
323
+ log.info(`Restored postgres backup (hostname was ${backupMetadata?.config?.hostname ?? 'unknown'})`);
267
324
  await setDefaultRoles();
268
325
  };
@@ -1,16 +1,15 @@
1
- export type BackupDatabaseType = 'arango' | 'postgres';
1
+ export type BackupDatabaseType = 'postgres';
2
2
  export type BackupMetadata = {
3
3
  databaseType?: BackupDatabaseType;
4
4
  /** When this backup archive was created (ISO-8601). */
5
5
  createdAt?: string;
6
6
  /**
7
7
  * Drizzle journal tag the database was on when the backup was created
8
- * (e.g. `0007_shallow_oracle`). Omitted on legacy Arango archives.
8
+ * (e.g. `0007_shallow_oracle`).
9
9
  */
10
10
  schemaVersion?: string;
11
11
  config?: {
12
12
  hostname?: string;
13
13
  };
14
14
  };
15
- /** Legacy Arango backups omit databaseType; treat them as Arango JSONL. */
16
15
  export declare const resolveBackupDatabaseType: (metadata?: BackupMetadata) => BackupDatabaseType;
@@ -1,2 +1,6 @@
1
- /** Legacy Arango backups omit databaseType; treat them as Arango JSONL. */
2
- export const resolveBackupDatabaseType = (metadata) => (metadata === null || metadata === void 0 ? void 0 : metadata.databaseType) === 'postgres' ? 'postgres' : 'arango';
1
+ export const resolveBackupDatabaseType = (metadata) => {
2
+ if (metadata?.databaseType === 'postgres') {
3
+ return 'postgres';
4
+ }
5
+ throw new Error('Backup is not a Postgres JSONL archive (missing metadata.json databaseType: "postgres")');
6
+ };
package/dist/config/db.js CHANGED
@@ -3,7 +3,6 @@ import { allpeepDb } from '../db/index.js';
3
3
  import { configs } from '../db/pg/schema/documents.js';
4
4
  import { nowIso } from '../db/pg/mappers.js';
5
5
  export const storeConfig = (key, config) => allpeepDb().then(async ({ db }) => {
6
- var _a;
7
6
  const ts = nowIso();
8
7
  const rows = await db
9
8
  .insert(configs)
@@ -13,14 +12,13 @@ export const storeConfig = (key, config) => allpeepDb().then(async ({ db }) => {
13
12
  set: { body: config, updatedAt: ts },
14
13
  })
15
14
  .returning();
16
- return (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.body;
15
+ return rows[0]?.body;
17
16
  });
18
17
  export const loadConfig = (key) => allpeepDb().then(async ({ db }) => {
19
- var _a;
20
18
  const rows = await db
21
19
  .select()
22
20
  .from(configs)
23
21
  .where(eq(configs.key, key))
24
22
  .limit(1);
25
- return (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.body;
23
+ return rows[0]?.body;
26
24
  });
@@ -35,8 +35,19 @@ export const defaultCapabilitiesConfig = {
35
35
  ],
36
36
  },
37
37
  self: { add: ['core-profiles-update', ...postCapabilities] },
38
- blocked: { remove: ['*'] },
39
- blockedBy: { remove: ['*'] },
38
+ blocked: {
39
+ remove: [
40
+ 'core-posts-*',
41
+ 'core-profiles-read',
42
+ 'core-profiles-follow',
43
+ 'core-profiles-unfollow',
44
+ 'core-profiles-requestFollow',
45
+ 'core-profiles-block',
46
+ 'core-profiles-mute',
47
+ 'core-profiles-unmute',
48
+ ],
49
+ },
50
+ 'blocked-by': { remove: ['*'] },
40
51
  },
41
52
  report: {
42
53
  reporter: { add: ['core-reports-read'] },
@@ -7,14 +7,18 @@ export const defaultCommunityConfig = {
7
7
  light: {
8
8
  primaryHex: '#15678a',
9
9
  logoSmall: '/img/logo-small.png',
10
- defaultProfileAvatar: '/img/default-avatar.png',
10
+ // No defaultProfileAvatar — profiles without a custom avatar fall back
11
+ // to letter initials in the Avatar component.
11
12
  defaultGroupAvatar: '/img/default-group-avatar.svg',
12
13
  backgroundAuth: '/img/background-auth.png',
13
14
  },
14
15
  dark: {
15
- primaryHex: '#15678a',
16
+ // Lighter than the light-mode primary so it stays readable on the
17
+ // near-black dark background.
18
+ primaryHex: '#38aee1',
16
19
  logoSmall: '/img/logo-small-white.png',
17
- defaultProfileAvatar: '/img/default-avatar.png',
20
+ // No defaultProfileAvatar — profiles without a custom avatar fall back
21
+ // to letter initials in the Avatar component.
18
22
  defaultGroupAvatar: '/img/default-group-avatar.svg',
19
23
  backgroundAuth: '/img/background-auth.png',
20
24
  },
@@ -26,6 +30,7 @@ export const defaultCommunityConfig = {
26
30
  },
27
31
  settings: {
28
32
  openRegistrations: process.env.COMMUNITY_SETTINGS_OPEN_REGISTRATIONS !== 'false',
33
+ indexProfiles: process.env.COMMUNITY_SETTINGS_INDEX_PROFILES === 'true',
29
34
  },
30
35
  content: {},
31
36
  roles: {
@@ -1,2 +1,2 @@
1
- import type { CoreConfig } from '@openpeepshq/common/types';
1
+ import { type CoreConfig } from '@openpeepshq/common/types';
2
2
  export declare const defaultConfig: CoreConfig;
@@ -1,3 +1,4 @@
1
+ import { DEFAULT_MAX_MEDIA_UPLOAD_MB, } from '@openpeepshq/common/types';
1
2
  import db from './db.js';
2
3
  import redis from './redis.js';
3
4
  import { readEnvInteger, resolveJwtSecret } from '../helpers.js';
@@ -20,17 +21,23 @@ export const defaultConfig = {
20
21
  service: 'smtp',
21
22
  defaultTemplatePath: 'assets/email/templates',
22
23
  defaultFrom: process.env.EMAIL_DEFAULT_FROM,
23
- transportConfig: Object.assign({ host: process.env.EMAIL_CONFIG_HOST || 'localhost', port: readEnvInteger('EMAIL_CONFIG_PORT', 465), secure: process.env.EMAIL_CONFIG_SECURE !== 'false' }, (process.env.EMAIL_CONFIG_AUTH_USER
24
- ? {
25
- auth: {
26
- user: process.env.EMAIL_CONFIG_AUTH_USER,
27
- pass: process.env.EMAIL_CONFIG_AUTH_PASS,
28
- },
29
- }
30
- : {})),
24
+ transportConfig: {
25
+ host: process.env.EMAIL_CONFIG_HOST || 'localhost',
26
+ port: readEnvInteger('EMAIL_CONFIG_PORT', 465),
27
+ secure: process.env.EMAIL_CONFIG_SECURE !== 'false',
28
+ ...(process.env.EMAIL_CONFIG_AUTH_USER
29
+ ? {
30
+ auth: {
31
+ user: process.env.EMAIL_CONFIG_AUTH_USER,
32
+ pass: process.env.EMAIL_CONFIG_AUTH_PASS,
33
+ },
34
+ }
35
+ : {}),
36
+ },
31
37
  },
32
38
  logs,
33
39
  media: {
40
+ maxUploadMb: DEFAULT_MAX_MEDIA_UPLOAD_MB,
34
41
  storage: {
35
42
  driver: 'openpeeps',
36
43
  params: {
@@ -65,6 +72,7 @@ export const defaultConfig = {
65
72
  },
66
73
  federation: {
67
74
  active: false,
75
+ allowedHosts: [],
68
76
  },
69
77
  activityPub: {
70
78
  defaultDomain: process.env.ACTIVITY_PUB_DEFAULT_DOMAIN || 'localhost',
@@ -51,6 +51,7 @@ export declare const config: <T = {
51
51
  };
52
52
  };
53
53
  media: {
54
+ maxUploadMb: number;
54
55
  storage: {
55
56
  driver: "openpeeps";
56
57
  params: {
@@ -84,6 +85,7 @@ export declare const config: <T = {
84
85
  };
85
86
  federation: {
86
87
  active: boolean;
88
+ allowedHosts: string[];
87
89
  };
88
90
  activityPub: {
89
91
  defaultDomain: string;
@@ -118,6 +120,10 @@ export declare const config: <T = {
118
120
  tokenUrl: string;
119
121
  userinfoUrl: string;
120
122
  clientId: string;
123
+ kind?: "oidc" | "github" | "gitlab" | "gitlab-selfhosted" | "google" | "entra" | "auth0" | "keycloak" | "authentik" | "okta" | "discord" | "pocketid" | undefined;
124
+ instanceUrl?: string | undefined;
125
+ tenant?: string | undefined;
126
+ emailsUrl?: string | undefined;
121
127
  jwksUri?: string | undefined;
122
128
  clientSecret?: string | undefined;
123
129
  scope?: string | undefined;
@@ -201,6 +207,13 @@ export declare const communityConfig: () => Promise<{
201
207
  };
202
208
  icon?: string | undefined;
203
209
  mobileIcon?: string | undefined;
210
+ primaryHex?: string | undefined;
211
+ logoFull?: string | undefined;
212
+ logoSmall?: string | undefined;
213
+ defaultProfileAvatar?: string | undefined;
214
+ defaultGroupAvatar?: string | undefined;
215
+ backgroundAuth?: string | undefined;
216
+ background?: string | undefined;
204
217
  };
205
218
  info: {
206
219
  name: string;
@@ -219,6 +232,9 @@ export declare const communityConfig: () => Promise<{
219
232
  settings: {
220
233
  openRegistrations: boolean;
221
234
  defaultLanguage?: string | undefined;
235
+ defaultTimeZone?: string | undefined;
236
+ defaultFeedFormat?: "threaded" | "linear" | undefined;
237
+ indexProfiles?: boolean | undefined;
222
238
  };
223
239
  roles: {
224
240
  onRegistration: {
@@ -277,6 +293,7 @@ export declare const sanitizedConfigWithDefaults: <T = {
277
293
  };
278
294
  };
279
295
  media: {
296
+ maxUploadMb: number;
280
297
  storage: {
281
298
  driver: "openpeeps";
282
299
  params: {
@@ -310,6 +327,7 @@ export declare const sanitizedConfigWithDefaults: <T = {
310
327
  };
311
328
  federation: {
312
329
  active: boolean;
330
+ allowedHosts: string[];
313
331
  };
314
332
  activityPub: {
315
333
  defaultDomain: string;
@@ -344,6 +362,10 @@ export declare const sanitizedConfigWithDefaults: <T = {
344
362
  tokenUrl: string;
345
363
  userinfoUrl: string;
346
364
  clientId: string;
365
+ kind?: "oidc" | "github" | "gitlab" | "gitlab-selfhosted" | "google" | "entra" | "auth0" | "keycloak" | "authentik" | "okta" | "discord" | "pocketid" | undefined;
366
+ instanceUrl?: string | undefined;
367
+ tenant?: string | undefined;
368
+ emailsUrl?: string | undefined;
347
369
  jwksUri?: string | undefined;
348
370
  clientSecret?: string | undefined;
349
371
  scope?: string | undefined;
@@ -1,11 +1,13 @@
1
1
  import { deepmergeCustom } from 'deepmerge-ts';
2
2
  import { coreConfigSchemaFactory, communityConfigSchemaFactory, capabilitiesConfigSchemaFactory, } from '@openpeepshq/common/types';
3
+ import { restorePasswordPlaceholders } from '@openpeepshq/common/lib';
3
4
  import { zodDeepPartialSchema } from '../lib/zodDeepPartial.js';
4
5
  import { defaultConfig } from './defaults/core.js';
5
6
  import { defaultCommunityConfig } from './defaults/community.js';
6
7
  import { default as logsConfig } from './defaults/logs.js';
7
8
  import { default as dbConfig } from './defaults/db.js';
8
9
  import { hub } from '../events/index.js';
10
+ import { stablePublicServerInfo } from '../server/stablePublicServerInfo.js';
9
11
  import { loadConfig, storeConfig } from './db.js';
10
12
  import { defaultCapabilitiesConfig } from './defaults/capabilities.js';
11
13
  import { pruneEmptyConfigStrings } from './pruneEmptyConfigStrings.js';
@@ -32,12 +34,15 @@ const initConfig = async (namespace, name) => {
32
34
  if (!factory) {
33
35
  throw new Error(`No config registered for ${key}`);
34
36
  }
35
- const customConfig = (customConfigDocument === null || customConfigDocument === void 0 ? void 0 : customConfigDocument.config) &&
37
+ const customConfig = customConfigDocument?.config &&
36
38
  zodDeepPartialSchema(factory()).parse(pruneEmptyConfigStrings(customConfigDocument.config));
37
39
  return (customConfig ? deepmerge(defaults, customConfig) : defaults);
38
40
  };
39
41
  export const refreshConfig = (namespace = 'openpeeps', name = 'core') => {
40
42
  configPromises.set(configKey(namespace, name), initConfig(namespace, name));
43
+ // /server/info is bucket-cached so RN clients do not remount. Drop that
44
+ // snapshot when config changes or SSO/theme patches stay invisible.
45
+ stablePublicServerInfo.reset();
41
46
  };
42
47
  /** Full-document write. Prefer `updateConfigValues` for patches. */
43
48
  const replaceStoredConfig = (config, namespace = 'openpeeps', name = 'core') => storeConfig(configKey(namespace, name), {
@@ -51,8 +56,8 @@ const replaceStoredConfig = (config, namespace = 'openpeeps', name = 'core') =>
51
56
  * admin UI forms and pin/unpin all send partial trees.
52
57
  */
53
58
  export const updateConfigValues = (configValues, namespace = 'openpeeps', name = 'core') => loadConfig(configKey(namespace, name)).then((configDocument) => {
54
- var _a;
55
- return replaceStoredConfig(deepmerge((_a = configDocument === null || configDocument === void 0 ? void 0 : configDocument.config) !== null && _a !== void 0 ? _a : {}, configValues), namespace, name);
59
+ const stored = configDocument?.config ?? {};
60
+ return replaceStoredConfig(deepmerge(stored, restorePasswordPlaceholders(configValues, stored)), namespace, name);
56
61
  });
57
62
  export const config = (namespace = 'openpeeps', name = 'core') => {
58
63
  const key = configKey(namespace, name);
@@ -67,17 +72,16 @@ export const config = (namespace = 'openpeeps', name = 'core') => {
67
72
  return configPromises.get(key);
68
73
  };
69
74
  export const communityConfig = () => config('openpeeps', 'community');
70
- export const capabilitiesConfig = () => config('openpeeps', 'capabilities').then((loaded) => {
71
- var _a, _b;
72
- return (Object.assign(Object.assign({}, loaded), { accessToken: deepmerge((_a = defaultCapabilitiesConfig.accessToken) !== null && _a !== void 0 ? _a : {}, (_b = loaded.accessToken) !== null && _b !== void 0 ? _b : {}) }));
73
- });
75
+ export const capabilitiesConfig = () => config('openpeeps', 'capabilities').then((loaded) => ({
76
+ ...loaded,
77
+ accessToken: deepmerge(defaultCapabilitiesConfig.accessToken ?? {}, loaded.accessToken ?? {}),
78
+ }));
74
79
  export const sanitizedConfigWithDefaults = async (namespace = 'openpeeps', name = 'core') => {
75
- var _a;
76
80
  const key = configKey(namespace, name);
77
- const { defaults, factory } = (_a = configSchemaRegistry.get(key)) !== null && _a !== void 0 ? _a : {};
81
+ const { defaults, factory } = configSchemaRegistry.get(key) ?? {};
78
82
  const sanitizedSchema = factory && factory(true);
79
83
  return {
80
- config: sanitizedSchema === null || sanitizedSchema === void 0 ? void 0 : sanitizedSchema.parse(await config(namespace, name)),
81
- defaults: sanitizedSchema === null || sanitizedSchema === void 0 ? void 0 : sanitizedSchema.parse(defaults),
84
+ config: sanitizedSchema?.parse(await config(namespace, name)),
85
+ defaults: sanitizedSchema?.parse(defaults),
82
86
  };
83
87
  };
@@ -2,10 +2,10 @@ import { pgPool } from '../pg/client.js';
2
2
  import { assertKnownColumns, describeExplorerTable, getExplorerTable, primaryKeyColumns, quoteIdent, } from './tables.js';
3
3
  export const DEFAULT_ROW_LIMIT = 100;
4
4
  /** Hard cap for browse page sizes (50 / 200 / 1000 / All). */
5
- export const MAX_ROW_LIMIT = 10000;
6
- export const MAX_EXPORT_LIMIT = 10000;
5
+ export const MAX_ROW_LIMIT = 10_000;
6
+ export const MAX_EXPORT_LIMIT = 10_000;
7
7
  export const clampLimit = (limit, max) => {
8
- const n = limit !== null && limit !== void 0 ? limit : DEFAULT_ROW_LIMIT;
8
+ const n = limit ?? DEFAULT_ROW_LIMIT;
9
9
  if (!Number.isFinite(n) || n < 1)
10
10
  return DEFAULT_ROW_LIMIT;
11
11
  return Math.min(Math.floor(n), max);
@@ -21,13 +21,14 @@ export const buildFilterClause = (tableName, filters, params) => {
21
21
  return ` WHERE ${parts.join(' AND ')}`;
22
22
  };
23
23
  export const listExplorerRows = async (input, options) => {
24
- var _a, _b, _c, _d, _e, _f, _g, _h;
25
24
  const tableName = input.table;
26
25
  const meta = describeExplorerTable(getExplorerTable(tableName));
27
- const maxLimit = (_a = options === null || options === void 0 ? void 0 : options.maxLimit) !== null && _a !== void 0 ? _a : MAX_ROW_LIMIT;
26
+ const maxLimit = options?.maxLimit ?? MAX_ROW_LIMIT;
28
27
  const limit = clampLimit(input.limit, maxLimit);
29
- const offset = Math.max(0, Math.floor((_b = input.offset) !== null && _b !== void 0 ? _b : 0));
30
- const orderCol = (_e = (_c = input.orderBy) !== null && _c !== void 0 ? _c : (_d = primaryKeyColumns(tableName)[0]) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : (_f = meta.columns[0]) === null || _f === void 0 ? void 0 : _f.name;
28
+ const offset = Math.max(0, Math.floor(input.offset ?? 0));
29
+ const orderCol = input.orderBy ??
30
+ primaryKeyColumns(tableName)[0]?.name ??
31
+ meta.columns[0]?.name;
31
32
  if (!orderCol) {
32
33
  throw new Error(`Table ${tableName} has no columns`);
33
34
  }
@@ -36,7 +37,7 @@ export const listExplorerRows = async (input, options) => {
36
37
  const where = buildFilterClause(tableName, input.filters, filterParams);
37
38
  const tableSql = quoteIdent(tableName);
38
39
  const countResult = await pgPool().query(`SELECT count(*)::text AS count FROM ${tableSql}${where}`, filterParams);
39
- const total = Number((_h = (_g = countResult.rows[0]) === null || _g === void 0 ? void 0 : _g.count) !== null && _h !== void 0 ? _h : 0);
40
+ const total = Number(countResult.rows[0]?.count ?? 0);
40
41
  const result = await pgPool().query(`SELECT * FROM ${tableSql}${where} ORDER BY ${quoteIdent(orderCol)} LIMIT $${filterParams.length + 1} OFFSET $${filterParams.length + 2}`, [...filterParams, limit, offset]);
41
42
  return {
42
43
  columns: meta.columns.map((c) => c.name),
@@ -1,18 +1,17 @@
1
1
  import { pgPool } from '../pg/client.js';
2
- export const SQL_STATEMENT_TIMEOUT_MS = 15000;
2
+ export const SQL_STATEMENT_TIMEOUT_MS = 15_000;
3
3
  /** Absolute cap for returned SQL rows (All). */
4
- export const SQL_HARD_MAX_ROWS = 100000;
4
+ export const SQL_HARD_MAX_ROWS = 100_000;
5
5
  /** Default cap when the client does not request a limit. */
6
- export const SQL_DEFAULT_MAX_ROWS = 1000;
6
+ export const SQL_DEFAULT_MAX_ROWS = 1_000;
7
7
  /** @deprecated Use SQL_HARD_MAX_ROWS */
8
8
  export const SQL_MAX_ROWS = SQL_HARD_MAX_ROWS;
9
9
  export const runExplorerSql = async (statement, options) => {
10
- var _a, _b, _c;
11
10
  const trimmed = statement.trim();
12
11
  if (!trimmed) {
13
12
  throw new Error('SQL statement is empty');
14
13
  }
15
- const requested = options === null || options === void 0 ? void 0 : options.limit;
14
+ const requested = options?.limit;
16
15
  const maxRows = requested != null && Number.isFinite(requested) && requested > 0
17
16
  ? Math.min(Math.floor(requested), SQL_HARD_MAX_ROWS)
18
17
  : SQL_DEFAULT_MAX_ROWS;
@@ -22,11 +21,12 @@ export const runExplorerSql = async (statement, options) => {
22
21
  const result = await client.query(trimmed);
23
22
  const allRows = result.rows;
24
23
  const rows = allRows.slice(0, maxRows);
25
- const columns = (_b = (_a = result.fields) === null || _a === void 0 ? void 0 : _a.map((f) => f.name)) !== null && _b !== void 0 ? _b : (rows[0] ? Object.keys(rows[0]) : []);
24
+ const columns = result.fields?.map((f) => f.name) ??
25
+ (rows[0] ? Object.keys(rows[0]) : []);
26
26
  return {
27
27
  columns,
28
28
  rows,
29
- rowCount: (_c = result.rowCount) !== null && _c !== void 0 ? _c : allRows.length,
29
+ rowCount: result.rowCount ?? allRows.length,
30
30
  command: result.command,
31
31
  };
32
32
  }
@@ -34,7 +34,7 @@ export const runExplorerSql = async (statement, options) => {
34
34
  try {
35
35
  await client.query('SET statement_timeout = 0');
36
36
  }
37
- catch (_d) {
37
+ catch {
38
38
  // ignore reset failures on a broken connection
39
39
  }
40
40
  client.release();
@@ -35,6 +35,7 @@ export declare const sortNewestFirst: <T extends object>(mapping: Mapping<T>) =>
35
35
  export declare const sortOldestFirst: <T extends object>(mapping: Mapping<T>) => Mapping<T, WithId<T>, WithId<T>>;
36
36
  export declare const addStartLimit: <T extends object>(mapping: Mapping<T>, start?: string, limit?: number) => Mapping<T>;
37
37
  export declare const addStart: <T extends object>(mapping: Mapping<T>, start?: string) => Mapping<T>;
38
+ export declare const addActivityStart: <T extends object>(mapping: Mapping<T>, start?: string) => Mapping<T>;
38
39
  export declare const filterAndTransform: <I extends object, O extends object = I>(queryResult: PgQueryResult<I>, db: PgDb, options: FilterAndTransformOptions<I, O>) => Promise<O[]>;
39
40
  export declare const composeFilters: <O extends object>(...filters: ObjectFilter<O>[]) => ObjectFilter<O>;
40
41
  export declare const retrievePaged: <T extends object>(queryResult: PgQueryResult<T>, db: PgDb, options?: {