@openpeepshq/core 0.1.32 → 0.1.34

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 (261) hide show
  1. package/dist/accessTokens/helpers.d.ts +2 -2
  2. package/dist/accessTokens/tokens.js +14 -7
  3. package/dist/accounts/mutations.d.ts +2 -2
  4. package/dist/accounts/mutations.js +33 -35
  5. package/dist/analytics/cache.js +12 -7
  6. package/dist/analytics/compile.js +16 -10
  7. package/dist/analytics/pdfReport.d.ts +1 -0
  8. package/dist/analytics/pdfReport.js +5 -4
  9. package/dist/analytics/privacy.d.ts +18 -0
  10. package/dist/analytics/privacy.js +10 -0
  11. package/dist/analytics/read.js +75 -19
  12. package/dist/analytics/report.d.ts +21 -1
  13. package/dist/analytics/report.js +9 -2
  14. package/dist/backups/index.js +78 -15
  15. package/dist/backups/metadata.d.ts +8 -2
  16. package/dist/backups/metadata.js +6 -2
  17. package/dist/config/defaults/capabilities.js +13 -2
  18. package/dist/config/defaults/community.js +7 -9
  19. package/dist/config/defaults/core.d.ts +1 -1
  20. package/dist/config/defaults/core.js +3 -0
  21. package/dist/config/defaults/db.d.ts +0 -2
  22. package/dist/config/defaults/db.js +0 -2
  23. package/dist/config/index.d.ts +25 -3
  24. package/dist/config/index.js +7 -1
  25. package/dist/db/helpers.d.ts +7 -28
  26. package/dist/db/helpers.js +30 -152
  27. package/dist/db/index.d.ts +3 -1
  28. package/dist/db/index.js +5 -0
  29. package/dist/db/init.js +2 -2
  30. package/dist/db/migration/importCollections.d.ts +15 -10
  31. package/dist/db/migration/importCollections.js +121 -155
  32. package/dist/db/migration/shared.d.ts +2 -37
  33. package/dist/db/migration/shared.js +2 -59
  34. package/dist/db/pg/client.js +4 -0
  35. package/dist/db/pg/collections.d.ts +2 -2
  36. package/dist/db/pg/collections.js +2 -2
  37. package/dist/db/pg/filters/edges.d.ts +1 -1
  38. package/dist/db/pg/filters/edges.js +1 -1
  39. package/dist/db/pg/filters/posts.d.ts +11 -0
  40. package/dist/db/pg/filters/posts.js +37 -3
  41. package/dist/db/pg/filters/profiles.d.ts +1 -0
  42. package/dist/db/pg/filters/profiles.js +2 -1
  43. package/dist/db/pg/map/filters.js +37 -2
  44. package/dist/db/pg/map/mutations.js +13 -8
  45. package/dist/db/pg/map/registry.d.ts +5 -0
  46. package/dist/db/pg/map/registry.js +64 -24
  47. package/dist/db/pg/map/relations.d.ts +1 -1
  48. package/dist/db/pg/map/relations.js +98 -46
  49. package/dist/db/pg/migrate.d.ts +22 -0
  50. package/dist/db/pg/migrate.js +88 -2
  51. package/dist/db/pg/queries/activity.js +3 -3
  52. package/dist/db/pg/queries/sorts.d.ts +1 -0
  53. package/dist/db/pg/queries/sorts.js +4 -0
  54. package/dist/db/pg/schema/documents.d.ts +422 -41
  55. package/dist/db/pg/schema/documents.js +43 -9
  56. package/dist/db/pg/schema/edges.d.ts +117 -7
  57. package/dist/db/pg/schema/edges.js +4 -2
  58. package/dist/db/pg/schema/index.d.ts +505 -15
  59. package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
  60. package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
  61. package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
  62. package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
  63. package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
  64. package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
  65. package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
  66. package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
  67. package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
  68. package/dist/db/pg/sql/meta/{0006_snapshot.json → 0015_snapshot.json} +393 -39
  69. package/dist/db/pg/sql/meta/_journal.json +64 -1
  70. package/dist/db/replaceOrigin.js +6 -0
  71. package/dist/db/types.d.ts +0 -4
  72. package/dist/email/render.js +11 -3
  73. package/dist/events/index.d.ts +6 -1
  74. package/dist/events/index.js +55 -33
  75. package/dist/federation/activities.d.ts +17 -0
  76. package/dist/federation/activities.js +26 -0
  77. package/dist/federation/identity.d.ts +16 -0
  78. package/dist/federation/identity.js +52 -0
  79. package/dist/federation/index.d.ts +4 -0
  80. package/dist/federation/index.js +3 -0
  81. package/dist/federation/profiles.d.ts +3 -0
  82. package/dist/federation/profiles.js +14 -0
  83. package/dist/groups/finders.d.ts +3 -2
  84. package/dist/groups/helpers.d.ts +24 -6
  85. package/dist/groups/mapping.d.ts +6 -4
  86. package/dist/groups/mapping.js +2 -2
  87. package/dist/groups/mutations.js +1 -1
  88. package/dist/hashtags/finders.d.ts +6 -3
  89. package/dist/hashtags/finders.js +2 -0
  90. package/dist/hashtags/helpers.d.ts +8 -0
  91. package/dist/hashtags/helpers.js +4 -0
  92. package/dist/hashtags/index.d.ts +2 -0
  93. package/dist/hashtags/index.js +2 -0
  94. package/dist/hashtags/mutations.d.ts +3 -0
  95. package/dist/hashtags/mutations.js +13 -1
  96. package/dist/i18n/index.d.ts +1 -1
  97. package/dist/i18n/index.js +3 -1
  98. package/dist/i18n/pluginLocales.d.ts +6 -0
  99. package/dist/i18n/pluginLocales.js +15 -0
  100. package/dist/inviteLinks/helpers.d.ts +4 -4
  101. package/dist/jams/cache.d.ts +1 -1
  102. package/dist/jams/cache.js +2 -1
  103. package/dist/jams/export.d.ts +19 -0
  104. package/dist/jams/export.js +60 -0
  105. package/dist/jams/finders.d.ts +2 -1
  106. package/dist/jams/finders.js +18 -7
  107. package/dist/jams/health.d.ts +8 -0
  108. package/dist/jams/health.js +46 -0
  109. package/dist/jams/helpers.d.ts +6 -2
  110. package/dist/jams/index.d.ts +6 -3
  111. package/dist/jams/index.js +41 -27
  112. package/dist/jams/jobs.js +1 -1
  113. package/dist/jams/livekit.d.ts +93 -10
  114. package/dist/jams/livekit.js +151 -52
  115. package/dist/jams/mapping.d.ts +17 -7
  116. package/dist/jams/mutations.d.ts +3 -1
  117. package/dist/jams/recording.d.ts +10 -0
  118. package/dist/jams/recording.js +32 -0
  119. package/dist/jams/rtmp.d.ts +5 -0
  120. package/dist/jams/rtmp.js +8 -0
  121. package/dist/jams/token.d.ts +15 -3
  122. package/dist/jams/token.js +30 -16
  123. package/dist/jams/waitingRoom.d.ts +6 -6
  124. package/dist/jams/waitingRoom.js +24 -23
  125. package/dist/jobs/index.d.ts +1 -0
  126. package/dist/jobs/index.js +6 -1
  127. package/dist/jobs/jobDetail.js +1 -6
  128. package/dist/media/index.d.ts +1 -1
  129. package/dist/media/index.js +23 -8
  130. package/dist/media/processing.js +18 -7
  131. package/dist/notifications/defaultNotifications/follow/index.js +2 -2
  132. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
  133. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
  134. package/dist/notifications/defaultNotifications/index.js +4 -0
  135. package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
  136. package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
  137. package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
  138. package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
  139. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +18 -0
  140. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
  141. package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
  142. package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
  143. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
  144. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
  145. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
  146. package/dist/notifications/helpers.js +6 -2
  147. package/dist/notifications/jobs.js +3 -1
  148. package/dist/notifications/mutations.js +4 -0
  149. package/dist/notifications/push.js +11 -4
  150. package/dist/plugins/helpers.d.ts +1 -0
  151. package/dist/plugins/helpers.js +1 -8
  152. package/dist/plugins/index.d.ts +5 -0
  153. package/dist/plugins/index.js +78 -5
  154. package/dist/plugins/install.d.ts +39 -0
  155. package/dist/plugins/install.js +455 -0
  156. package/dist/plugins/pluginAuth.d.ts +1 -1
  157. package/dist/plugins/pluginAuth.js +10 -6
  158. package/dist/plugins/state.d.ts +4 -0
  159. package/dist/plugins/state.js +29 -0
  160. package/dist/posts/activity.d.ts +9 -0
  161. package/dist/posts/activity.js +35 -0
  162. package/dist/posts/contextClosure.d.ts +1 -9
  163. package/dist/posts/contextClosure.js +15 -44
  164. package/dist/posts/conversationQueries.d.ts +7 -0
  165. package/dist/posts/conversationQueries.js +76 -2
  166. package/dist/posts/eventAgenda.d.ts +166 -0
  167. package/dist/posts/eventAgenda.js +126 -0
  168. package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
  169. package/dist/posts/eventOccurrenceJobs.js +28 -0
  170. package/dist/posts/eventOccurrences.d.ts +10 -0
  171. package/dist/posts/eventOccurrences.js +61 -0
  172. package/dist/posts/finders.d.ts +47 -16
  173. package/dist/posts/finders.js +93 -62
  174. package/dist/posts/helpers/filters.js +14 -9
  175. package/dist/posts/helpers/index.d.ts +129 -30
  176. package/dist/posts/helpers/index.js +66 -33
  177. package/dist/posts/index.d.ts +7 -1
  178. package/dist/posts/index.js +7 -1
  179. package/dist/posts/mapping.d.ts +491 -13
  180. package/dist/posts/mapping.js +45 -10
  181. package/dist/posts/mutations.d.ts +441 -4
  182. package/dist/posts/mutations.js +177 -43
  183. package/dist/posts/pollEnd.d.ts +3 -0
  184. package/dist/posts/pollEnd.js +7 -0
  185. package/dist/posts/pollEndJobs.d.ts +8 -0
  186. package/dist/posts/pollEndJobs.js +49 -0
  187. package/dist/posts/replyClosure.d.ts +10 -0
  188. package/dist/posts/replyClosure.js +43 -0
  189. package/dist/posts/rsvpConfirmationEmail.js +14 -15
  190. package/dist/posts/threadPreview.d.ts +8 -0
  191. package/dist/posts/threadPreview.js +44 -0
  192. package/dist/posts/unseenCounts.d.ts +2 -0
  193. package/dist/posts/unseenCounts.js +28 -8
  194. package/dist/profileSettings/cache.js +22 -5
  195. package/dist/profileSettings/mapping.d.ts +2 -0
  196. package/dist/profiles/activityQueries.d.ts +5 -0
  197. package/dist/profiles/activityQueries.js +85 -0
  198. package/dist/profiles/activitySummary.d.ts +3 -0
  199. package/dist/profiles/activitySummary.js +87 -0
  200. package/dist/profiles/blocks.d.ts +12 -0
  201. package/dist/profiles/blocks.js +73 -0
  202. package/dist/profiles/cache.d.ts +4 -1
  203. package/dist/profiles/cache.js +28 -7
  204. package/dist/profiles/finders.d.ts +2 -1
  205. package/dist/profiles/finders.js +8 -3
  206. package/dist/profiles/helpers.d.ts +7 -5
  207. package/dist/profiles/index.d.ts +3 -1
  208. package/dist/profiles/index.js +3 -1
  209. package/dist/profiles/mapping.d.ts +10 -5
  210. package/dist/profiles/mapping.js +13 -1
  211. package/dist/profiles/mutations.d.ts +8 -4
  212. package/dist/profiles/mutations.js +42 -15
  213. package/dist/pushSubscriptions/helpers.d.ts +2 -2
  214. package/dist/pushSubscriptions/mutations.js +13 -1
  215. package/dist/redis/connection.d.ts +2 -0
  216. package/dist/redis/connection.js +25 -6
  217. package/dist/reports/helpers.d.ts +6 -6
  218. package/dist/roles/index.d.ts +1 -1
  219. package/dist/roles/index.js +1 -1
  220. package/dist/roles/mapping.d.ts +1 -0
  221. package/dist/roles/mutations.js +86 -3
  222. package/dist/search/mapping.d.ts +1 -1
  223. package/dist/search/mapping.js +6 -2
  224. package/dist/server/index.d.ts +19 -1
  225. package/dist/server/index.js +37 -18
  226. package/dist/server/stablePublicServerInfo.d.ts +17 -0
  227. package/dist/server/stablePublicServerInfo.js +37 -0
  228. package/dist/server/status.d.ts +25 -0
  229. package/dist/server/status.js +98 -0
  230. package/dist/stats/finders.d.ts +1 -16131
  231. package/dist/stats/finders.js +9 -5
  232. package/dist/stats/mapping.d.ts +21 -1
  233. package/dist/stats/mapping.js +0 -3
  234. package/package.json +6 -12
  235. package/dist/db/arango.d.ts +0 -2
  236. package/dist/db/arango.js +0 -110
  237. package/dist/db/migration/autoMigrate.d.ts +0 -2
  238. package/dist/db/migration/autoMigrate.js +0 -111
  239. package/dist/db/migration/cli.d.ts +0 -1
  240. package/dist/db/migration/cli.js +0 -56
  241. package/dist/db/migration/detect.d.ts +0 -6
  242. package/dist/db/migration/detect.js +0 -87
  243. package/dist/db/migration/exportArango.d.ts +0 -4
  244. package/dist/db/migration/exportArango.js +0 -80
  245. package/dist/db/migration/importPostgres.d.ts +0 -3
  246. package/dist/db/migration/importPostgres.js +0 -18
  247. package/dist/db/migration/transform.d.ts +0 -18
  248. package/dist/db/migration/transform.js +0 -209
  249. package/dist/db/migration/validate.d.ts +0 -18
  250. package/dist/db/migration/validate.js +0 -69
  251. package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
  252. package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
  253. package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
  254. package/dist/mastodon/index.d.ts +0 -4
  255. package/dist/mastodon/index.js +0 -51
  256. package/dist/mastodon/types.d.ts +0 -7579
  257. package/dist/mastodon/types.js +0 -523
  258. package/dist/mastodon/typescript.d.ts +0 -1578
  259. package/dist/mastodon/typescript.js +0 -1
  260. package/dist/roles/defaults.d.ts +0 -2
  261. package/dist/roles/defaults.js +0 -94
@@ -1,209 +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 { documentRegistry, edgeRegistry, parseDocRef, } from '../pg/map/registry.js';
17
- import { nowIso } from '../pg/mappers.js';
18
- import { uuidv7 } from 'uuidv7';
19
- import { readJsonl } from './shared.js';
20
- const ARANGO_META = ['_id', '_key', '_rev', '_from', '_to'];
21
- const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
22
- /** Postgres uuid compares case-insensitively; normalize so dedupe matches. */
23
- export const normalizeImportId = (value) => {
24
- if (typeof value !== 'string') {
25
- return undefined;
26
- }
27
- const trimmed = value.trim();
28
- if (!trimmed) {
29
- return undefined;
30
- }
31
- return UUID_REGEX.test(trimmed) ? trimmed.toLowerCase() : trimmed;
32
- };
33
- export const arangoDocToModel = (doc) => {
34
- var _a;
35
- const id = ((_a = doc._key) !== null && _a !== void 0 ? _a : doc.id);
36
- const model = Object.assign(Object.assign({}, doc), { id });
37
- for (const key of ARANGO_META) {
38
- delete model[key];
39
- }
40
- return model;
41
- };
42
- const isNonEmptyTimestamp = (value) => typeof value === 'string' && value.trim() !== '';
43
- const resolveDocumentId = (doc) => {
44
- const candidates = [doc.id, doc._key]
45
- .map((value) => normalizeImportId(value))
46
- .filter((value) => Boolean(value));
47
- const uuid = candidates.find((value) => UUID_REGEX.test(value));
48
- return uuid !== null && uuid !== void 0 ? uuid : uuidv7();
49
- };
50
- const timestampsFromModel = (model) => {
51
- const ts = nowIso();
52
- return {
53
- createdAt: isNonEmptyTimestamp(model.createdAt) ? model.createdAt : ts,
54
- updatedAt: isNonEmptyTimestamp(model.updatedAt) ? model.updatedAt : ts,
55
- deletedAt: isNonEmptyTimestamp(model.deletedAt) ? model.deletedAt : null,
56
- };
57
- };
58
- const entryTypeFromDoc = (doc) => {
59
- if (typeof doc.type === 'string') {
60
- return doc.type;
61
- }
62
- const body = doc.body;
63
- if (body && typeof body === 'object' && 'type' in body) {
64
- return body.type;
65
- }
66
- return undefined;
67
- };
68
- /** Pre-scan entries edges so legacy posts without creatorId can be imported. */
69
- export const buildPostCreatorIdByPostId = async (collectionsDir) => {
70
- var _a, _b;
71
- const map = new Map();
72
- const filePath = join(collectionsDir, 'entries.jsonl');
73
- try {
74
- await access(filePath, constants.F_OK);
75
- }
76
- catch (_e) {
77
- return map;
78
- }
79
- const docs = await readJsonl(filePath);
80
- for (const doc of docs) {
81
- const fromRef = parseDocRef(doc._from);
82
- const toRef = parseDocRef(doc._to);
83
- if (!fromRef || !toRef || toRef.collection !== 'posts') {
84
- continue;
85
- }
86
- const entryType = entryTypeFromDoc(doc);
87
- const postId = (_a = normalizeImportId(toRef.id)) !== null && _a !== void 0 ? _a : toRef.id;
88
- const creatorId = (_b = normalizeImportId(fromRef.id)) !== null && _b !== void 0 ? _b : fromRef.id;
89
- if (entryType === 'create' || !map.has(postId)) {
90
- map.set(postId, creatorId);
91
- }
92
- }
93
- return map;
94
- };
95
- /**
96
- * Legacy Arango groups used discoverable/locked flags; capabilities were added
97
- * later via an Arango-only data migration that never runs on Postgres restores.
98
- */
99
- export const capabilitiesFromLegacyGroupFlags = (data) => {
100
- if (data.capabilities && typeof data.capabilities === 'object') {
101
- return undefined;
102
- }
103
- const discoverable = Boolean(data.discoverable);
104
- const locked = Boolean(data.locked);
105
- const { publicGroup, privateGroup, lockedGroup } = groupCapabilityTemplates;
106
- const template = discoverable
107
- ? locked
108
- ? lockedGroup
109
- : publicGroup
110
- : privateGroup;
111
- return template.capabilities;
112
- };
113
- export const arangoDocToDocumentRow = (collection, doc, context) => {
114
- var _a, _b, _e, _f, _g, _h, _j, _k, _m, _o, _p, _q, _r, _s;
115
- const model = arangoDocToModel(doc);
116
- const { createdAt, updatedAt, deletedAt } = timestampsFromModel(model);
117
- if (collection === 'configs') {
118
- const { createdAt: _c, updatedAt: _u, deletedAt: _d, id: _id } = model, body = __rest(model, ["createdAt", "updatedAt", "deletedAt", "id"]);
119
- const rawKey = String((_b = (_a = doc._key) !== null && _a !== void 0 ? _a : doc.id) !== null && _b !== void 0 ? _b : '');
120
- // Legacy Arango backups used allpeep-* keys; runtime loaders use openpeeps-*.
121
- const key = rawKey.startsWith('allpeep-')
122
- ? `openpeeps-${rawKey.slice('allpeep-'.length)}`
123
- : rawKey;
124
- return { key, body, createdAt, updatedAt, deletedAt };
125
- }
126
- if (collection === 'dataMigrations') {
127
- const appliedAtRaw = (_e = doc.appliedAt) !== null && _e !== void 0 ? _e : model.createdAt;
128
- return {
129
- id: (_f = doc._key) !== null && _f !== void 0 ? _f : doc.id,
130
- appliedAt: isNonEmptyTimestamp(appliedAtRaw) ? appliedAtRaw : nowIso(),
131
- };
132
- }
133
- if (collection === 'i18n') {
134
- const id = resolveDocumentId(doc);
135
- const locale = ((_h = (_g = doc.locale) !== null && _g !== void 0 ? _g : doc._key) !== null && _h !== void 0 ? _h : id);
136
- const namespace = ((_j = doc.namespace) !== null && _j !== void 0 ? _j : 'translation');
137
- const body = (_m = (_k = doc.body) !== null && _k !== void 0 ? _k : doc.translations) !== null && _m !== void 0 ? _m : (() => {
138
- 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"]);
139
- return rest;
140
- })();
141
- return {
142
- id,
143
- locale,
144
- namespace,
145
- body,
146
- createdAt,
147
- updatedAt,
148
- deletedAt,
149
- };
150
- }
151
- const config = documentRegistry[collection];
152
- if (!config) {
153
- throw new Error(`Unknown document collection: ${collection}`);
154
- }
155
- 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 : '');
156
- const { createdAt: _c, updatedAt: _u, deletedAt: _d, id: _id } = model, data = __rest(model, ["createdAt", "updatedAt", "deletedAt", "id"]);
157
- const { scalars, body } = config.splitPatch(data);
158
- if (collection === 'posts' &&
159
- scalars.creatorId === undefined &&
160
- (context === null || context === void 0 ? void 0 : context.postCreatorIdByPostId)) {
161
- const creatorId = context.postCreatorIdByPostId.get(id);
162
- if (creatorId) {
163
- scalars.creatorId = creatorId;
164
- }
165
- }
166
- if (collection === 'profileSettings' && scalars.profileId === undefined) {
167
- scalars.profileId = id;
168
- }
169
- if (collection === 'notifications' && scalars.profileId === undefined) {
170
- const actorId = (_s = model.actorId) !== null && _s !== void 0 ? _s : model.profileId;
171
- if (typeof actorId === 'string') {
172
- scalars.profileId = actorId;
173
- }
174
- }
175
- if (collection === 'groups') {
176
- const capabilities = capabilitiesFromLegacyGroupFlags(data);
177
- if (capabilities) {
178
- body.capabilities = capabilities;
179
- }
180
- }
181
- return Object.assign(Object.assign({ id }, scalars), { body,
182
- createdAt,
183
- updatedAt,
184
- deletedAt });
185
- };
186
- export const arangoDocToEdgeRow = (collection, doc) => {
187
- var _a, _b, _e, _f, _g;
188
- const config = edgeRegistry[collection];
189
- if (!config) {
190
- throw new Error(`Unknown edge collection: ${collection}`);
191
- }
192
- const fromRef = parseDocRef(doc._from);
193
- const toRef = parseDocRef(doc._to);
194
- if (!fromRef || !toRef) {
195
- throw new Error(`Invalid edge refs in ${collection}/${String(doc._key)}: ${String(doc._from)} -> ${String(doc._to)}`);
196
- }
197
- const model = arangoDocToModel(doc);
198
- const { createdAt, updatedAt } = timestampsFromModel(model);
199
- const { createdAt: _c, updatedAt: _u, id: _id } = model, body = __rest(model, ["createdAt", "updatedAt", "id"]);
200
- return {
201
- 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),
202
- fromId: (_f = normalizeImportId(fromRef.id)) !== null && _f !== void 0 ? _f : fromRef.id,
203
- toId: (_g = normalizeImportId(toRef.id)) !== null && _g !== void 0 ? _g : toRef.id,
204
- body,
205
- createdAt,
206
- updatedAt,
207
- };
208
- };
209
- 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
- };