@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,232 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { access } from 'node:fs/promises';
13
- import { constants } from 'node:fs';
14
- import { join } from 'node:path';
15
- import { groupCapabilityTemplates } from '@openpeepshq/common/lib';
16
- import { defaultGroupAdminCapabilityAdds } from '@openpeepshq/common/types';
17
- import { documentRegistry, edgeRegistry, parseDocRef, } from '../pg/map/registry.js';
18
- import { nowIso } from '../pg/mappers.js';
19
- import { uuidv7 } from 'uuidv7';
20
- import { readJsonl } from './shared.js';
21
- const ARANGO_META = ['_id', '_key', '_rev', '_from', '_to'];
22
- const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
23
- /** Postgres uuid compares case-insensitively; normalize so dedupe matches. */
24
- export const normalizeImportId = (value) => {
25
- if (typeof value !== 'string') {
26
- return undefined;
27
- }
28
- const trimmed = value.trim();
29
- if (!trimmed) {
30
- return undefined;
31
- }
32
- return UUID_REGEX.test(trimmed) ? trimmed.toLowerCase() : trimmed;
33
- };
34
- export const arangoDocToModel = (doc) => {
35
- var _a;
36
- const id = ((_a = doc._key) !== null && _a !== void 0 ? _a : doc.id);
37
- const model = Object.assign(Object.assign({}, doc), { id });
38
- for (const key of ARANGO_META) {
39
- delete model[key];
40
- }
41
- return model;
42
- };
43
- const isNonEmptyTimestamp = (value) => typeof value === 'string' && value.trim() !== '';
44
- const resolveDocumentId = (doc) => {
45
- const candidates = [doc.id, doc._key]
46
- .map((value) => normalizeImportId(value))
47
- .filter((value) => Boolean(value));
48
- const uuid = candidates.find((value) => UUID_REGEX.test(value));
49
- return uuid !== null && uuid !== void 0 ? uuid : uuidv7();
50
- };
51
- const timestampsFromModel = (model) => {
52
- const ts = nowIso();
53
- return {
54
- createdAt: isNonEmptyTimestamp(model.createdAt) ? model.createdAt : ts,
55
- updatedAt: isNonEmptyTimestamp(model.updatedAt) ? model.updatedAt : ts,
56
- deletedAt: isNonEmptyTimestamp(model.deletedAt) ? model.deletedAt : null,
57
- };
58
- };
59
- const entryTypeFromDoc = (doc) => {
60
- if (typeof doc.type === 'string') {
61
- return doc.type;
62
- }
63
- const body = doc.body;
64
- if (body && typeof body === 'object' && 'type' in body) {
65
- return body.type;
66
- }
67
- return undefined;
68
- };
69
- /** Pre-scan entries edges so legacy posts without creatorId can be imported. */
70
- export const buildPostCreatorIdByPostId = async (collectionsDir) => {
71
- var _a, _b;
72
- const map = new Map();
73
- const filePath = join(collectionsDir, 'entries.jsonl');
74
- try {
75
- await access(filePath, constants.F_OK);
76
- }
77
- catch (_e) {
78
- return map;
79
- }
80
- const docs = await readJsonl(filePath);
81
- for (const doc of docs) {
82
- const fromRef = parseDocRef(doc._from);
83
- const toRef = parseDocRef(doc._to);
84
- if (!fromRef || !toRef || toRef.collection !== 'posts') {
85
- continue;
86
- }
87
- const entryType = entryTypeFromDoc(doc);
88
- const postId = (_a = normalizeImportId(toRef.id)) !== null && _a !== void 0 ? _a : toRef.id;
89
- const creatorId = (_b = normalizeImportId(fromRef.id)) !== null && _b !== void 0 ? _b : fromRef.id;
90
- if (entryType === 'create' || !map.has(postId)) {
91
- map.set(postId, creatorId);
92
- }
93
- }
94
- return map;
95
- };
96
- /**
97
- * Legacy Arango groups used discoverable/locked flags; capabilities were added
98
- * later via an Arango-only data migration that never runs on Postgres restores.
99
- */
100
- export const capabilitiesFromLegacyGroupFlags = (data) => {
101
- if (data.capabilities && typeof data.capabilities === 'object') {
102
- return undefined;
103
- }
104
- const discoverable = Boolean(data.discoverable);
105
- const locked = Boolean(data.locked);
106
- const { publicGroup, privateGroup, lockedGroup } = groupCapabilityTemplates;
107
- const template = discoverable
108
- ? locked
109
- ? lockedGroup
110
- : publicGroup
111
- : privateGroup;
112
- return template.capabilities;
113
- };
114
- export const normalizeGroupMembershipRoles = (roles) => {
115
- if (!Array.isArray(roles))
116
- return roles;
117
- return [...new Set(roles.map((role) => (role === 'admin' ? 'owner' : role)))];
118
- };
119
- export const normalizeGroupCapabilityMap = (capabilities) => {
120
- const next = Object.assign({}, capabilities);
121
- if (next.admin && !next.owner) {
122
- next.owner = next.admin;
123
- delete next.admin;
124
- }
125
- if (!next.admin) {
126
- next.admin = { add: [...defaultGroupAdminCapabilityAdds] };
127
- }
128
- return next;
129
- };
130
- export const arangoDocToDocumentRow = (collection, doc, context) => {
131
- var _a, _b, _e, _f, _g, _h, _j, _k, _m, _o, _p, _q, _r, _s;
132
- const model = arangoDocToModel(doc);
133
- const { createdAt, updatedAt, deletedAt } = timestampsFromModel(model);
134
- if (collection === 'configs') {
135
- const { createdAt: _c, updatedAt: _u, deletedAt: _d, id: _id } = model, body = __rest(model, ["createdAt", "updatedAt", "deletedAt", "id"]);
136
- const rawKey = String((_b = (_a = doc._key) !== null && _a !== void 0 ? _a : doc.id) !== null && _b !== void 0 ? _b : '');
137
- // Legacy Arango backups used allpeep-* keys; runtime loaders use openpeeps-*.
138
- const key = rawKey.startsWith('allpeep-')
139
- ? `openpeeps-${rawKey.slice('allpeep-'.length)}`
140
- : rawKey;
141
- return { key, body, createdAt, updatedAt, deletedAt };
142
- }
143
- if (collection === 'dataMigrations') {
144
- const appliedAtRaw = (_e = doc.appliedAt) !== null && _e !== void 0 ? _e : model.createdAt;
145
- return {
146
- id: (_f = doc._key) !== null && _f !== void 0 ? _f : doc.id,
147
- appliedAt: isNonEmptyTimestamp(appliedAtRaw) ? appliedAtRaw : nowIso(),
148
- };
149
- }
150
- if (collection === 'i18n') {
151
- const id = resolveDocumentId(doc);
152
- const locale = ((_h = (_g = doc.locale) !== null && _g !== void 0 ? _g : doc._key) !== null && _h !== void 0 ? _h : id);
153
- const namespace = ((_j = doc.namespace) !== null && _j !== void 0 ? _j : 'translation');
154
- const body = (_m = (_k = doc.body) !== null && _k !== void 0 ? _k : doc.translations) !== null && _m !== void 0 ? _m : (() => {
155
- const { createdAt: _c, updatedAt: _u, deletedAt: _d, id: _id, locale: _l, namespace: _n, translations: _t } = model, rest = __rest(model, ["createdAt", "updatedAt", "deletedAt", "id", "locale", "namespace", "translations"]);
156
- return rest;
157
- })();
158
- return {
159
- id,
160
- locale,
161
- namespace,
162
- body,
163
- createdAt,
164
- updatedAt,
165
- deletedAt,
166
- };
167
- }
168
- const config = documentRegistry[collection];
169
- if (!config) {
170
- throw new Error(`Unknown document collection: ${collection}`);
171
- }
172
- const id = (_p = normalizeImportId((_o = doc._key) !== null && _o !== void 0 ? _o : doc.id)) !== null && _p !== void 0 ? _p : String((_r = (_q = doc._key) !== null && _q !== void 0 ? _q : doc.id) !== null && _r !== void 0 ? _r : '');
173
- const { createdAt: _c, updatedAt: _u, deletedAt: _d, id: _id } = model, data = __rest(model, ["createdAt", "updatedAt", "deletedAt", "id"]);
174
- const { scalars, body } = config.splitPatch(data);
175
- if (collection === 'posts' &&
176
- scalars.creatorId === undefined &&
177
- (context === null || context === void 0 ? void 0 : context.postCreatorIdByPostId)) {
178
- const creatorId = context.postCreatorIdByPostId.get(id);
179
- if (creatorId) {
180
- scalars.creatorId = creatorId;
181
- }
182
- }
183
- if (collection === 'profileSettings' && scalars.profileId === undefined) {
184
- scalars.profileId = id;
185
- }
186
- if (collection === 'notifications' && scalars.profileId === undefined) {
187
- const actorId = (_s = model.actorId) !== null && _s !== void 0 ? _s : model.profileId;
188
- if (typeof actorId === 'string') {
189
- scalars.profileId = actorId;
190
- }
191
- }
192
- if (collection === 'groups') {
193
- const capabilities = capabilitiesFromLegacyGroupFlags(data);
194
- if (capabilities) {
195
- body.capabilities = capabilities;
196
- }
197
- else if (body.capabilities && typeof body.capabilities === 'object') {
198
- body.capabilities = normalizeGroupCapabilityMap(body.capabilities);
199
- }
200
- }
201
- return Object.assign(Object.assign({ id }, scalars), { body,
202
- createdAt,
203
- updatedAt,
204
- deletedAt });
205
- };
206
- export const arangoDocToEdgeRow = (collection, doc) => {
207
- var _a, _b, _e, _f, _g;
208
- const config = edgeRegistry[collection];
209
- if (!config) {
210
- throw new Error(`Unknown edge collection: ${collection}`);
211
- }
212
- const fromRef = parseDocRef(doc._from);
213
- const toRef = parseDocRef(doc._to);
214
- if (!fromRef || !toRef) {
215
- throw new Error(`Invalid edge refs in ${collection}/${String(doc._key)}: ${String(doc._from)} -> ${String(doc._to)}`);
216
- }
217
- const model = arangoDocToModel(doc);
218
- const { createdAt, updatedAt } = timestampsFromModel(model);
219
- const { createdAt: _c, updatedAt: _u, id: _id } = model, body = __rest(model, ["createdAt", "updatedAt", "id"]);
220
- if (collection === 'userGroups' && 'roles' in body) {
221
- body.roles = normalizeGroupMembershipRoles(body.roles);
222
- }
223
- return {
224
- id: (_b = normalizeImportId((_a = doc._key) !== null && _a !== void 0 ? _a : doc.id)) !== null && _b !== void 0 ? _b : String((_e = doc._key) !== null && _e !== void 0 ? _e : doc.id),
225
- fromId: (_f = normalizeImportId(fromRef.id)) !== null && _f !== void 0 ? _f : fromRef.id,
226
- toId: (_g = normalizeImportId(toRef.id)) !== null && _g !== void 0 ? _g : toRef.id,
227
- body,
228
- createdAt,
229
- updatedAt,
230
- };
231
- };
232
- export const isEdgeCollection = (collection) => collection in edgeRegistry;
@@ -1,18 +0,0 @@
1
- import { type CollectionCounts } from './shared';
2
- type ValidationIssue = {
3
- collection: string;
4
- kind: 'count' | 'checksum';
5
- expected: string | number;
6
- actual: string | number;
7
- };
8
- export declare const validateMigration: (exportDir?: string, options?: {
9
- closeConnection?: boolean;
10
- importedCounts?: CollectionCounts;
11
- }) => Promise<{
12
- ok: true;
13
- issues: ValidationIssue[];
14
- } | {
15
- ok: false;
16
- issues: ValidationIssue[];
17
- }>;
18
- export {};
@@ -1,69 +0,0 @@
1
- import { sql } from 'drizzle-orm';
2
- import { logger } from '../../log/index.js';
3
- import { closePostgres, pgDb } from '../pg/client.js';
4
- import { documentRegistry, edgeRegistry } from '../pg/map/registry.js';
5
- import { tableCount } from './detect.js';
6
- import { assertExportDir, expectedCollectionCount, exportDirFromEnv, readImportStats, readManifest, sortedChecksum, } from './shared.js';
7
- const log = logger('core:migration:validate');
8
- const accountEmailChecksum = async () => {
9
- const db = pgDb();
10
- const rows = await db.execute(sql `SELECT email FROM accounts ORDER BY email`);
11
- return sortedChecksum(rows.rows.map((row) => row.email));
12
- };
13
- const postIdChecksum = async () => {
14
- const db = pgDb();
15
- const rows = await db.execute(sql `SELECT id FROM posts ORDER BY id`);
16
- return sortedChecksum(rows.rows.map((row) => row.id));
17
- };
18
- export const validateMigration = async (exportDir = exportDirFromEnv(), options = {}) => {
19
- var _a, _b, _c;
20
- const closeConnection = (_a = options.closeConnection) !== null && _a !== void 0 ? _a : true;
21
- await assertExportDir(exportDir);
22
- const manifest = await readManifest(exportDir);
23
- const importStats = await readImportStats(exportDir);
24
- const importedCounts = (_c = (_b = options.importedCounts) !== null && _b !== void 0 ? _b : importStats === null || importStats === void 0 ? void 0 : importStats.collections) !== null && _c !== void 0 ? _c : null;
25
- if (importedCounts) {
26
- log.info('Validating Postgres counts against import stats (intentional Arango skips/remaps allowed)');
27
- }
28
- const issues = [];
29
- const collections = [
30
- ...Object.keys(documentRegistry),
31
- ...Object.keys(edgeRegistry),
32
- ];
33
- for (const collection of collections) {
34
- const expected = expectedCollectionCount(collection, manifest.collections, importedCounts);
35
- const actual = await tableCount(collection);
36
- if (expected !== actual) {
37
- issues.push({ collection, kind: 'count', expected, actual });
38
- }
39
- }
40
- const emailChecksum = await accountEmailChecksum();
41
- if (emailChecksum !== manifest.checksums.accountEmails) {
42
- issues.push({
43
- collection: 'accounts',
44
- kind: 'checksum',
45
- expected: manifest.checksums.accountEmails,
46
- actual: emailChecksum,
47
- });
48
- }
49
- const postsChecksum = await postIdChecksum();
50
- if (postsChecksum !== manifest.checksums.postIds) {
51
- issues.push({
52
- collection: 'posts',
53
- kind: 'checksum',
54
- expected: manifest.checksums.postIds,
55
- actual: postsChecksum,
56
- });
57
- }
58
- if (closeConnection) {
59
- await closePostgres();
60
- }
61
- if (issues.length === 0) {
62
- log.info('Validation passed for export %s', exportDir);
63
- return { ok: true, issues };
64
- }
65
- for (const issue of issues) {
66
- log.error('Validation failed for %s (%s): expected %s, got %s', issue.collection, issue.kind, issue.expected, issue.actual);
67
- }
68
- return { ok: false, issues };
69
- };