@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,29 +1,8 @@
1
- var __asyncValues = (this && this.__asyncValues) || function (o) {
2
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
3
- var m = o[Symbol.asyncIterator], i;
4
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
5
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
6
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
7
- };
8
- import { createHash } from 'node:crypto';
9
1
  import { createReadStream } from 'node:fs';
10
- import { access, readFile, writeFile } from 'node:fs/promises';
11
- import { constants } from 'node:fs';
12
2
  import { createInterface } from 'node:readline';
13
- import { join } from 'node:path';
14
- import dotenv from 'dotenv';
15
- dotenv.config();
16
- export const DEFAULT_EXPORT_DIR = './arango-export';
17
- export const exportDirFromEnv = () => { var _a; return (_a = process.env.MIGRATION_EXPORT_DIR) !== null && _a !== void 0 ? _a : DEFAULT_EXPORT_DIR; };
18
- export const collectionsDir = (exportDir) => join(exportDir, 'collections');
19
- export const manifestPath = (exportDir) => join(exportDir, 'manifest.json');
20
- /** Counts actually inserted into Postgres (after skips / remaps / dedupe). */
21
- export const importStatsPath = (exportDir) => join(exportDir, 'import-stats.json');
22
- export const collectionFilePath = (exportDir, collection) => join(collectionsDir(exportDir), `${collection}.jsonl`);
23
3
  export const DOCUMENT_IMPORT_ORDER = [
24
4
  'configs',
25
5
  'i18n',
26
- 'dataMigrations',
27
6
  'accounts',
28
7
  'roles',
29
8
  'profiles',
@@ -43,12 +22,12 @@ export const DOCUMENT_IMPORT_ORDER = [
43
22
  export const EDGE_IMPORT_ORDER = [
44
23
  'controls',
45
24
  'follows',
25
+ 'blocks',
46
26
  'requestsFollow',
47
27
  'mentions',
48
28
  'audience',
49
29
  'postHashtags',
50
30
  'entries',
51
- 'reactions',
52
31
  'replyTo',
53
32
  'repost',
54
33
  'bookmarks',
@@ -66,86 +45,37 @@ export const EDGE_IMPORT_ORDER = [
66
45
  'inviteLinkCreators',
67
46
  'inviteLinkRedeemers',
68
47
  'jamRecordings',
48
+ 'profileHashtags',
69
49
  ];
70
- export const sha256 = (value) => createHash('sha256').update(value).digest('hex');
71
- export const sortedChecksum = (values) => sha256(values.filter(Boolean).sort().join('\n'));
72
50
  export const readJsonl = async (filePath) => {
73
- var _a, e_1, _b, _c;
74
51
  const docs = [];
75
52
  let buffer = '';
76
53
  const lineReader = createInterface({
77
54
  input: createReadStream(filePath),
78
55
  crlfDelay: Infinity,
79
56
  });
80
- try {
81
- for (var _d = true, lineReader_1 = __asyncValues(lineReader), lineReader_1_1; lineReader_1_1 = await lineReader_1.next(), _a = lineReader_1_1.done, !_a; _d = true) {
82
- _c = lineReader_1_1.value;
83
- _d = false;
84
- const line = _c;
85
- if (!line.trim()) {
86
- continue;
87
- }
88
- buffer += line;
89
- try {
90
- docs.push(JSON.parse(buffer));
91
- buffer = '';
92
- }
93
- catch (err) {
94
- const message = err instanceof Error ? err.message : String(err);
95
- const partialJson = message.includes('Unexpected end of JSON input') ||
96
- message.includes('Unterminated string') ||
97
- message.includes('Unexpected token');
98
- if (!partialJson) {
99
- throw err;
100
- }
101
- }
57
+ for await (const line of lineReader) {
58
+ if (!line.trim()) {
59
+ continue;
102
60
  }
103
- }
104
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
105
- finally {
61
+ buffer += line;
106
62
  try {
107
- if (!_d && !_a && (_b = lineReader_1.return)) await _b.call(lineReader_1);
63
+ docs.push(JSON.parse(buffer));
64
+ buffer = '';
65
+ }
66
+ catch (err) {
67
+ const message = err instanceof Error ? err.message : String(err);
68
+ const partialJson = message.includes('Unexpected end of JSON input') ||
69
+ message.includes('Unterminated string') ||
70
+ message.includes('Unexpected token');
71
+ if (!partialJson) {
72
+ throw err;
73
+ }
108
74
  }
109
- finally { if (e_1) throw e_1.error; }
110
75
  }
111
76
  if (buffer.trim().length > 0) {
112
77
  throw new Error(`Unparsed JSON remaining in ${filePath}`);
113
78
  }
114
79
  return docs;
115
80
  };
116
- export const readManifest = async (exportDir) => {
117
- const raw = await readFile(manifestPath(exportDir), 'utf-8');
118
- return JSON.parse(raw);
119
- };
120
- export const writeManifest = async (exportDir, manifest) => {
121
- await writeFile(manifestPath(exportDir), JSON.stringify(manifest, null, 2));
122
- };
123
- export const writeImportStats = async (exportDir, collections) => {
124
- const stats = {
125
- importedAt: new Date().toISOString(),
126
- collections,
127
- };
128
- await writeFile(importStatsPath(exportDir), JSON.stringify(stats, null, 2));
129
- };
130
- export const readImportStats = async (exportDir) => {
131
- try {
132
- await access(importStatsPath(exportDir), constants.F_OK);
133
- }
134
- catch (_a) {
135
- return null;
136
- }
137
- const raw = await readFile(importStatsPath(exportDir), 'utf-8');
138
- return JSON.parse(raw);
139
- };
140
- /** Prefer post-import counts when present (skips / remaps / dedupe). */
141
- export const expectedCollectionCount = (collection, manifestCounts, importedCounts) => {
142
- var _a, _b;
143
- return importedCounts
144
- ? ((_a = importedCounts[collection]) !== null && _a !== void 0 ? _a : 0)
145
- : ((_b = manifestCounts[collection]) !== null && _b !== void 0 ? _b : 0);
146
- };
147
- export const assertExportDir = async (exportDir) => {
148
- await access(manifestPath(exportDir), constants.F_OK);
149
- await access(collectionsDir(exportDir), constants.F_OK);
150
- };
151
81
  export const BATCH_SIZE = 500;
@@ -10,10 +10,8 @@ const log = logger('openpeeps:pg');
10
10
  export const SCHEMA_MIGRATE_LOCK = { key1: 8742301, key2: 1 };
11
11
  let pool;
12
12
  let dbInstance;
13
- export const pgConnectionString = () => {
14
- var _a;
15
- return (_a = process.env.DATABASE_URL) !== null && _a !== void 0 ? _a : 'postgresql://openpeeps:openpeeps@localhost:5432/openpeeps';
16
- };
13
+ export const pgConnectionString = () => process.env.DATABASE_URL ??
14
+ 'postgresql://openpeeps:openpeeps@localhost:5432/openpeeps';
17
15
  const instrumentPoolQuery = (target) => {
18
16
  if (!dbTimingEnabled())
19
17
  return;
@@ -92,7 +90,7 @@ export const initPostgres = async () => {
92
90
  return pgDb();
93
91
  };
94
92
  export const closePostgres = async () => {
95
- await (pool === null || pool === void 0 ? void 0 : pool.end());
93
+ await pool?.end();
96
94
  pool = undefined;
97
95
  dbInstance = undefined;
98
96
  // DROP SCHEMA / pool.end leaves allpeepDb() holding a dead Pool; next caller
@@ -111,8 +109,7 @@ export const closePostgres = async () => {
111
109
  * advisory lock).
112
110
  */
113
111
  export const resetPostgresSchemas = async (options = {}) => {
114
- var _a;
115
- const closePool = (_a = options.closePool) !== null && _a !== void 0 ? _a : true;
112
+ const closePool = options.closePool ?? true;
116
113
  const db = pgDb();
117
114
  await db.execute(sql.raw('DROP SCHEMA IF EXISTS public CASCADE'));
118
115
  await db.execute(sql.raw('DROP SCHEMA IF EXISTS drizzle CASCADE'));
@@ -1,12 +1,12 @@
1
1
  import type { CollectionInfo } from './map/queryTypes';
2
2
  /** Named collection/edge refs aligned with `documentRegistry` and `edgeRegistry`. */
3
3
  export declare const collectionInfos: {
4
- readonly dataMigrationsCollection: CollectionInfo;
5
4
  readonly i18nCollection: CollectionInfo;
6
5
  readonly configCollection: CollectionInfo;
7
6
  readonly accountsCollection: CollectionInfo;
8
7
  readonly profilesCollection: CollectionInfo;
9
8
  readonly followsCollection: CollectionInfo;
9
+ readonly blocksCollection: CollectionInfo;
10
10
  readonly requestsFollowCollection: CollectionInfo;
11
11
  readonly controlsCollection: CollectionInfo;
12
12
  readonly postsCollection: CollectionInfo;
@@ -19,7 +19,6 @@ export declare const collectionInfos: {
19
19
  readonly isReportedProfileCollection: CollectionInfo;
20
20
  readonly isReportedObjectCollection: CollectionInfo;
21
21
  readonly entriesCollection: CollectionInfo;
22
- readonly reactionsCollection: CollectionInfo;
23
22
  readonly repliesCollection: CollectionInfo;
24
23
  readonly repostCollection: CollectionInfo;
25
24
  readonly mediaAttachmentsCollection: CollectionInfo;
@@ -44,5 +43,6 @@ export declare const collectionInfos: {
44
43
  readonly postSeenCollection: CollectionInfo;
45
44
  readonly profileSettingsCollection: CollectionInfo;
46
45
  readonly jamRecordingsCollection: CollectionInfo;
46
+ readonly profileHashtagsCollection: CollectionInfo;
47
47
  };
48
48
  export type CollectionInfoKey = keyof typeof collectionInfos;
@@ -7,12 +7,12 @@ const edge = (name) => ({
7
7
  });
8
8
  /** Named collection/edge refs aligned with `documentRegistry` and `edgeRegistry`. */
9
9
  export const collectionInfos = {
10
- dataMigrationsCollection: document('dataMigrations'),
11
10
  i18nCollection: document('i18n'),
12
11
  configCollection: document('configs'),
13
12
  accountsCollection: document('accounts'),
14
13
  profilesCollection: document('profiles'),
15
14
  followsCollection: edge('follows'),
15
+ blocksCollection: edge('blocks'),
16
16
  requestsFollowCollection: edge('requestsFollow'),
17
17
  controlsCollection: edge('controls'),
18
18
  postsCollection: document('posts'),
@@ -25,7 +25,6 @@ export const collectionInfos = {
25
25
  isReportedProfileCollection: edge('isReportedProfile'),
26
26
  isReportedObjectCollection: edge('isReportedObject'),
27
27
  entriesCollection: edge('entries'),
28
- reactionsCollection: edge('reactions'),
29
28
  repliesCollection: edge('replyTo'),
30
29
  repostCollection: edge('repost'),
31
30
  mediaAttachmentsCollection: document('mediaAttachments'),
@@ -50,4 +49,5 @@ export const collectionInfos = {
50
49
  postSeenCollection: edge('postSeen'),
51
50
  profileSettingsCollection: document('profileSettings'),
52
51
  jamRecordingsCollection: edge('jamRecordings'),
52
+ profileHashtagsCollection: edge('profileHashtags'),
53
53
  };
@@ -24,7 +24,7 @@ export const sqlConditions = (...filters) => {
24
24
  export const partitionPgFilters = (filters) => {
25
25
  const sqlFilters = [];
26
26
  const omFilters = [];
27
- for (const filter of filters !== null && filters !== void 0 ? filters : []) {
27
+ for (const filter of filters ?? []) {
28
28
  if (isSqlFilter(filter))
29
29
  sqlFilters.push(filter);
30
30
  else
@@ -1,16 +1,28 @@
1
+ import type { FeedCursor } from '@openpeepshq/common';
1
2
  import { type SqlFilter } from './types';
2
3
  export declare const postFilters: {
3
4
  notDirect: () => SqlFilter;
4
5
  isDirect: () => SqlFilter;
6
+ /** Original posts only — replies belong in the parent thread, not the feed. */
7
+ notReply: () => SqlFilter;
8
+ /**
9
+ * Keyset for `ORDER BY last_activity_at DESC, id DESC`. A uuid-only cursor
10
+ * looks up the referenced row so older clients keep paginating.
11
+ */
12
+ afterActivity: (cursor: FeedCursor) => SqlFilter;
5
13
  hasJam: () => SqlFilter;
6
14
  creatorId: (id: string) => SqlFilter;
15
+ notCreatorIn: (ids: string[]) => SqlFilter | undefined;
7
16
  myFeed: (profileId: string, followedProfileIds: string[], groupIds: string[]) => SqlFilter;
8
17
  type: (type: string) => SqlFilter;
18
+ inGroup: (groupId: string) => SqlFilter;
19
+ notInAnyGroup: () => SqlFilter;
9
20
  replyCount: (op: "==" | "!=" | ">" | ">=" | "<" | "<=", count: number) => SqlFilter;
10
21
  replyCountZero: () => SqlFilter;
11
22
  replyCountPositive: () => SqlFilter;
12
23
  isJamModerator: (profileId: string) => SqlFilter;
13
24
  hasYesOrMaybeRsvp: (profileId: string) => SqlFilter;
25
+ hasAnyHashtag: (hashtagIds: string[]) => SqlFilter | undefined;
14
26
  };
15
27
  export declare const eventTimeFilters: {
16
28
  upcoming: (now?: string) => SqlFilter;
@@ -1,17 +1,38 @@
1
- import { and, eq, inArray, isNotNull, ne, or, sql } from 'drizzle-orm';
1
+ import { and, eq, inArray, isNotNull, ne, notInArray, or, sql, } from 'drizzle-orm';
2
2
  import { posts } from '../schema/documents.js';
3
- import { postGroups } from '../schema/edges.js';
3
+ import { postGroups, postHashtags, replyTo } from '../schema/edges.js';
4
4
  import { postHasYesOrMaybeRsvpExpr, postReplyCountExpr, } from '../queries/activity.js';
5
5
  import { compareCount } from './common.js';
6
6
  import { pgSql } from './types.js';
7
7
  const eventStart = sql `${posts.body}->>'start'`;
8
8
  const eventEnd = sql `${posts.body}->>'end'`;
9
+ // Open-ended events count as one hour long when they are current or past.
10
+ const eventEffectiveEnd = sql `COALESCE(NULLIF(${eventEnd}, '')::timestamptz, ${eventStart}::timestamptz + interval '1 hour')`;
9
11
  const postsReplyCountExpr = postReplyCountExpr(posts);
10
12
  export const postFilters = {
11
13
  notDirect: () => pgSql(ne(posts.visibility, 'direct')),
12
14
  isDirect: () => pgSql(eq(posts.visibility, 'direct')),
15
+ /** Original posts only — replies belong in the parent thread, not the feed. */
16
+ notReply: () => pgSql(sql `NOT EXISTS (SELECT 1 FROM ${replyTo} WHERE ${replyTo.fromId} = ${posts.id}::text)`),
17
+ /**
18
+ * Keyset for `ORDER BY last_activity_at DESC, id DESC`. A uuid-only cursor
19
+ * looks up the referenced row so older clients keep paginating.
20
+ */
21
+ afterActivity: (cursor) => {
22
+ const activity = cursor.lastActivityAt
23
+ ? sql `${cursor.lastActivityAt}::timestamptz`
24
+ : sql `(SELECT p2.last_activity_at FROM posts p2 WHERE p2.id = ${cursor.id}::uuid)`;
25
+ return pgSql(sql `(
26
+ ${posts.lastActivityAt} < ${activity}
27
+ OR (
28
+ ${posts.lastActivityAt} = ${activity}
29
+ AND ${posts.id} < ${cursor.id}::uuid
30
+ )
31
+ )`);
32
+ },
13
33
  hasJam: () => pgSql(isNotNull(sql `${posts.body}->'jam'`)),
14
34
  creatorId: (id) => pgSql(eq(posts.creatorId, id)),
35
+ notCreatorIn: (ids) => ids.length ? pgSql(notInArray(posts.creatorId, ids)) : undefined,
15
36
  myFeed: (profileId, followedProfileIds, groupIds) => {
16
37
  const followed = followedProfileIds.length
17
38
  ? inArray(posts.creatorId, followedProfileIds)
@@ -22,14 +43,19 @@ export const postFilters = {
22
43
  return pgSql(or(eq(posts.creatorId, profileId), followed, groupMemberPost));
23
44
  },
24
45
  type: (type) => pgSql(eq(posts.type, type)),
46
+ inGroup: (groupId) => pgSql(sql `EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text AND ${postGroups.toId} = ${groupId})`),
47
+ notInAnyGroup: () => pgSql(sql `NOT EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text)`),
25
48
  replyCount: (op, count) => pgSql(compareCount(postsReplyCountExpr, op, count)),
26
49
  replyCountZero: () => postFilters.replyCount('==', 0),
27
50
  replyCountPositive: () => postFilters.replyCount('>', 0),
28
51
  isJamModerator: (profileId) => pgSql(sql `${posts.body}->'jam'->'moderators' ? ${profileId}`),
29
52
  hasYesOrMaybeRsvp: (profileId) => pgSql(postHasYesOrMaybeRsvpExpr(posts, profileId)),
53
+ hasAnyHashtag: (hashtagIds) => hashtagIds.length
54
+ ? pgSql(sql `EXISTS (SELECT 1 FROM ${postHashtags} WHERE ${postHashtags.fromId} = ${posts.id}::text AND ${inArray(postHashtags.toId, hashtagIds)})`)
55
+ : undefined,
30
56
  };
31
57
  export const eventTimeFilters = {
32
58
  upcoming: (now = new Date().toISOString()) => pgSql(or(sql `${eventStart} > ${now}`, and(sql `${posts.body}->'end' IS NOT NULL`, sql `${eventEnd} > ${now}`))),
33
- current: (now = new Date().toISOString()) => pgSql(and(sql `${eventStart} <= ${now}`, or(sql `${posts.body}->'end' IS NULL`, sql `${eventEnd} >= ${now}`))),
34
- past: (now = new Date().toISOString()) => pgSql(sql `COALESCE(${eventEnd}, ${eventStart}) < ${now}`),
59
+ current: (now = new Date().toISOString()) => pgSql(and(sql `${eventStart}::timestamptz <= ${now}::timestamptz`, sql `${eventEffectiveEnd} >= ${now}::timestamptz`)),
60
+ past: (now = new Date().toISOString()) => pgSql(sql `${eventEffectiveEnd} < ${now}::timestamptz`),
35
61
  };
@@ -2,5 +2,6 @@ import { type SqlFilter } from './types';
2
2
  export declare const profileFilters: {
3
3
  notGuest: () => SqlFilter;
4
4
  type: (type: string) => SqlFilter;
5
+ notIdIn: (ids: string[]) => SqlFilter | undefined;
5
6
  activityScorePositive: (start?: Date, end?: Date) => SqlFilter;
6
7
  };
@@ -1,9 +1,10 @@
1
- import { eq, gt, ne } from 'drizzle-orm';
1
+ import { eq, gt, ne, notInArray } from 'drizzle-orm';
2
2
  import { profiles } from '../schema/documents.js';
3
3
  import { profileActivityScoreExpr } from '../queries/activity.js';
4
4
  import { pgSql } from './types.js';
5
5
  export const profileFilters = {
6
6
  notGuest: () => pgSql(ne(profiles.type, 'guest')),
7
7
  type: (type) => pgSql(eq(profiles.type, type)),
8
+ notIdIn: (ids) => ids.length ? pgSql(notInArray(profiles.id, ids)) : undefined,
8
9
  activityScorePositive: (start, end) => pgSql(gt(profileActivityScoreExpr(profiles, { start, end }), 0)),
9
10
  };
@@ -1,14 +1,3 @@
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
1
  import { and, eq, isNull, sql } from 'drizzle-orm';
13
2
  import { nowIso } from './mappers.js';
14
3
  import { uuidv7 } from 'uuidv7';
@@ -37,7 +26,7 @@ export const softDeleteById = async (db, table, id) => {
37
26
  export const insertEdge = async (db, table, fromId, toId, body = {}) => {
38
27
  // Callers (e.g. jam recordings) pass a pre-generated id on the body; use it
39
28
  // as the row primary key and keep it out of jsonb so finds/updates match.
40
- const { id: providedId } = body, edgeBody = __rest(body, ["id"]);
29
+ const { id: providedId, ...edgeBody } = body;
41
30
  const id = typeof providedId === 'string' && providedId.length > 0
42
31
  ? providedId
43
32
  : uuidv7();
@@ -58,10 +47,9 @@ export const deleteEdge = async (db, table, fromId, toId) => {
58
47
  .where(and(eq(table.fromId, fromId), eq(table.toId, toId)));
59
48
  };
60
49
  export const countRows = async (db, table, where) => {
61
- var _a, _b;
62
50
  const query = db
63
51
  .select({ count: sql `count(*)::int` })
64
52
  .from(table);
65
53
  const result = (where ? await query.where(where) : await query);
66
- return (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0;
54
+ return result[0]?.count ?? 0;
67
55
  };
@@ -5,8 +5,24 @@ import { groupLastPostAtExpr, postActivityScoreExpr, postReplyCountExpr, postRep
5
5
  import { asTable, edgeRegistry, getCollectionConfig, parseDocRef, } from './registry.js';
6
6
  const SCALAR_COLUMNS = {
7
7
  accounts: ['email', 'passwordHash', 'emailValidated', 'guest'],
8
- profiles: ['handle', 'type', 'activityPubDomain'],
9
- posts: ['type', 'visibility', 'creatorId'],
8
+ profiles: [
9
+ 'handle',
10
+ 'type',
11
+ 'activityPubDomain',
12
+ 'uri',
13
+ 'inboxUrl',
14
+ 'sharedInboxUrl',
15
+ 'keyId',
16
+ 'fetchedAt',
17
+ ],
18
+ posts: [
19
+ 'type',
20
+ 'visibility',
21
+ 'creatorId',
22
+ 'lastActivityAt',
23
+ 'uri',
24
+ 'inReplyToUri',
25
+ ],
10
26
  groups: ['handle'],
11
27
  hashtags: ['name'],
12
28
  roles: ['key', 'isDefault'],
@@ -41,7 +57,7 @@ export const evaluateStringFilter = (doc, expression) => {
41
57
  const fn = new Function('doc', 'CHECK_CAPABILITIES', 'MERGE_CAPABILITIES', `return ${normalizeAqlExpression(expression)};`);
42
58
  return Boolean(fn(doc, checkCapabilities, mergeCapabilities));
43
59
  }
44
- catch (_a) {
60
+ catch {
45
61
  return false;
46
62
  }
47
63
  };
@@ -74,7 +90,7 @@ export const evaluateFilter = (doc, filter) => {
74
90
  if (parsed) {
75
91
  const docRef = getPath(doc, field);
76
92
  const docParsed = docRef ? parseDocRef(docRef) : undefined;
77
- return (docParsed === null || docParsed === void 0 ? void 0 : docParsed.id) === parsed.id;
93
+ return docParsed?.id === parsed.id;
78
94
  }
79
95
  }
80
96
  return getPath(doc, field) === value;
@@ -92,12 +108,15 @@ const docFieldSql = (collection, table, fieldPath) => {
92
108
  return sql `${t.createdAt}`;
93
109
  if (fieldPath === 'updatedAt' && t.updatedAt)
94
110
  return sql `${t.updatedAt}`;
111
+ if (fieldPath === 'lastActivityAt' && t.lastActivityAt) {
112
+ return sql `${t.lastActivityAt}`;
113
+ }
95
114
  if (fieldPath === '_from' && t.fromId)
96
115
  return sql `${t.fromId}`;
97
116
  if (fieldPath === '_to' && t.toId)
98
117
  return sql `${t.toId}`;
99
118
  const scalars = SCALAR_COLUMNS[collection];
100
- if (scalars === null || scalars === void 0 ? void 0 : scalars.includes(fieldPath))
119
+ if (scalars?.includes(fieldPath))
101
120
  return sql `${t[fieldPath]}`;
102
121
  let jsonPath = fieldPath;
103
122
  if (collection === 'posts' && jsonPath.startsWith('data.')) {
@@ -399,9 +418,20 @@ const matchToSql = (collection, table, match) => {
399
418
  const config = getCollectionConfig(collection);
400
419
  if (!config)
401
420
  continue;
421
+ if (collection === 'profiles' &&
422
+ key === 'activityPub' &&
423
+ value &&
424
+ typeof value === 'object' &&
425
+ !Array.isArray(value)) {
426
+ const domain = value.domain;
427
+ if (typeof domain === 'string') {
428
+ conditions.push(eq(t.activityPubDomain, domain));
429
+ }
430
+ continue;
431
+ }
402
432
  if (config.kind === 'document') {
403
433
  const scalars = SCALAR_COLUMNS[collection];
404
- if (scalars === null || scalars === void 0 ? void 0 : scalars.includes(key)) {
434
+ if (scalars?.includes(key)) {
405
435
  conditions.push(eq(t[key], value));
406
436
  }
407
437
  else if (t.body) {
@@ -461,7 +491,7 @@ export const partitionFilters = (collection, table, filters, defaultFilter, soft
461
491
  }
462
492
  for (const filter of [
463
493
  ...(defaultFilter ? [defaultFilter] : []),
464
- ...(filters !== null && filters !== void 0 ? filters : []),
494
+ ...(filters ?? []),
465
495
  ]) {
466
496
  if (isSqlFilter(filter)) {
467
497
  sqlConditions.push(filter.where);
@@ -489,7 +519,7 @@ export const applyDateRangeToEdgeSql = (table, filter) => {
489
519
  return createdAtRangeSql(table, filter);
490
520
  };
491
521
  export const sortToSqlOrderBy = (collection, table, sort, activityWindow) => {
492
- if (!(sort === null || sort === void 0 ? void 0 : sort.length))
522
+ if (!sort?.length)
493
523
  return undefined;
494
524
  const orderBy = [];
495
525
  for (const [expr, direction] of sort) {
@@ -523,7 +553,7 @@ export const sortToSqlOrderBy = (collection, table, sort, activityWindow) => {
523
553
  export const applyPostFilters = (docs, filters, defaultFilter) => {
524
554
  const allFilters = [
525
555
  ...(defaultFilter ? [defaultFilter] : []),
526
- ...(filters !== null && filters !== void 0 ? filters : []),
556
+ ...(filters ?? []),
527
557
  ];
528
558
  return docs.filter((doc) => allFilters.every((f) => {
529
559
  if (isSqlFilter(f))
@@ -532,7 +562,7 @@ export const applyPostFilters = (docs, filters, defaultFilter) => {
532
562
  }));
533
563
  };
534
564
  export const applySort = (docs, sort) => {
535
- if (!(sort === null || sort === void 0 ? void 0 : sort.length))
565
+ if (!sort?.length)
536
566
  return docs;
537
567
  return [...docs].sort((a, b) => {
538
568
  for (const [expr, direction] of sort) {
@@ -1,2 +1,6 @@
1
1
  export const addFilter = (mapData, filter) => filter
2
- ? Object.assign(Object.assign({}, mapData), { filters: [...(mapData.filters || []), filter] }) : mapData;
2
+ ? {
3
+ ...mapData,
4
+ filters: [...(mapData.filters || []), filter],
5
+ }
6
+ : mapData;
@@ -1,16 +1,3 @@
1
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
2
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
3
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
5
- return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
6
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
7
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
8
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
9
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
10
- function fulfill(value) { resume("next", value); }
11
- function reject(value) { resume("throw", value); }
12
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
13
- };
14
1
  import { addFilter } from './helpers.js';
15
2
  import { createDocument, deleteDocument, updateDocument } from './mutations.js';
16
3
  import { deleteRelationsFor, executeAll, executeCount, executeFind, executeFirst, relationsFrom, } from './relations.js';
@@ -22,43 +9,50 @@ const throwIfUndefined = (message) => (value) => {
22
9
  return value;
23
10
  };
24
11
  export const map = (mapData) => ({
25
- addRelation: (relation) => {
26
- var _a;
27
- return map(Object.assign(Object.assign({}, mapData), { relations: [...((_a = mapData.relations) !== null && _a !== void 0 ? _a : []), relation] }));
28
- },
29
- addRelations: (relations) => {
30
- var _a;
31
- return map(Object.assign(Object.assign({}, mapData), { relations: [...((_a = mapData.relations) !== null && _a !== void 0 ? _a : []), ...relations] }));
32
- },
33
- removeRelation: (predicate) => {
34
- var _a;
35
- return map(Object.assign(Object.assign({}, mapData), { relations: (_a = mapData.relations) === null || _a === void 0 ? void 0 : _a.filter(predicate) }));
36
- },
37
- addDerivedProperty: (derivedProperty) => {
38
- var _a;
39
- return map(Object.assign(Object.assign({}, mapData), { derivedProperties: [
40
- ...((_a = mapData.derivedProperties) !== null && _a !== void 0 ? _a : []),
41
- derivedProperty,
42
- ] }));
43
- },
44
- removeDefaultFilter: () => map(Object.assign(Object.assign({}, mapData), { defaultFilter: undefined })),
12
+ addRelation: (relation) => map({
13
+ ...mapData,
14
+ relations: [...(mapData.relations ?? []), relation],
15
+ }),
16
+ addRelations: (relations) => map({
17
+ ...mapData,
18
+ relations: [...(mapData.relations ?? []), ...relations],
19
+ }),
20
+ removeRelation: (predicate) => map({
21
+ ...mapData,
22
+ relations: mapData.relations?.filter(predicate),
23
+ }),
24
+ addDerivedProperty: (derivedProperty) => map({
25
+ ...mapData,
26
+ derivedProperties: [
27
+ ...(mapData.derivedProperties ?? []),
28
+ derivedProperty,
29
+ ],
30
+ }),
31
+ removeDefaultFilter: () => map({
32
+ ...mapData,
33
+ defaultFilter: undefined,
34
+ }),
45
35
  filter: (filter) => map(addFilter(mapData, filter)),
46
- clearFilters: () => map(Object.assign(Object.assign({}, mapData), { filters: [] })),
47
- sort: (sort) => sort ? map(Object.assign(Object.assign({}, mapData), { sort })) : map(mapData),
48
- limit: (limit) => (limit ? map(Object.assign(Object.assign({}, mapData), { limit })) : map(mapData)),
49
- ignoreSoftDelete: () => map(Object.assign(Object.assign({}, mapData), { softDelete: false })),
50
- find: (db, id, options) => executeFind(db, mapData.collection, mapData, id, options === null || options === void 0 ? void 0 : options.ignoreSoftDelete),
36
+ clearFilters: () => map({
37
+ ...mapData,
38
+ filters: [],
39
+ }),
40
+ sort: (sort) => sort ? map({ ...mapData, sort }) : map(mapData),
41
+ limit: (limit) => (limit ? map({ ...mapData, limit }) : map(mapData)),
42
+ ignoreSoftDelete: () => map({
43
+ ...mapData,
44
+ softDelete: false,
45
+ }),
46
+ find: (db, id, options) => executeFind(db, mapData.collection, mapData, id, options?.ignoreSoftDelete),
51
47
  findOneBy: (db, filter) => map(addFilter(mapData, filter)).first(db),
52
48
  all: (db) => executeAll(db, mapData),
53
49
  fulltextSearch: (searchDefinition) => buildSearchResult(mapData, searchDefinition),
54
50
  count: (db) => executeCount(db, mapData),
55
51
  first: (db) => executeFirst(db, mapData),
56
- cursor: function (db) {
57
- return __asyncGenerator(this, arguments, function* () {
58
- for (const row of yield __await(executeAll(db, mapData))) {
59
- yield yield __await(row);
60
- }
61
- });
52
+ cursor: async function* (db) {
53
+ for (const row of await executeAll(db, mapData)) {
54
+ yield row;
55
+ }
62
56
  },
63
57
  queryBuilder: () => {
64
58
  throw new Error('queryBuilder() is not supported for Postgres map()');
@@ -72,16 +66,17 @@ export const map = (mapData) => ({
72
66
  all: (db) => relationsFrom(db, start, mapData.collection, relation),
73
67
  count: (db) => relationsFrom(db, start, mapData.collection, relation).then((rows) => rows.length),
74
68
  first: (db) => relationsFrom(db, start, mapData.collection, relation).then((rows) => rows[0]),
75
- limit: (limit) => map(mapData).relationsFrom(start, Object.assign(Object.assign({}, relation), { mapping: Object.assign(Object.assign({}, relation.mapping), { limit }) })),
69
+ limit: (limit) => map(mapData).relationsFrom(start, {
70
+ ...relation,
71
+ mapping: { ...relation.mapping, limit },
72
+ }),
76
73
  query: () => {
77
74
  throw new Error('query() is not supported for Postgres relationsFrom');
78
75
  },
79
- cursor: function (db) {
80
- return __asyncGenerator(this, arguments, function* () {
81
- for (const row of yield __await(relationsFrom(db, start, mapData.collection, relation))) {
82
- yield yield __await(row);
83
- }
84
- });
76
+ cursor: async function* (db) {
77
+ for (const row of await relationsFrom(db, start, mapData.collection, relation)) {
78
+ yield row;
79
+ }
85
80
  },
86
81
  };
87
82
  return result;