@openpeepshq/core 0.1.31

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 (500) hide show
  1. package/LICENSE +674 -0
  2. package/dist/accessTokens/finders.d.ts +11 -0
  3. package/dist/accessTokens/finders.js +43 -0
  4. package/dist/accessTokens/helpers.d.ts +13 -0
  5. package/dist/accessTokens/helpers.js +15 -0
  6. package/dist/accessTokens/index.d.ts +4 -0
  7. package/dist/accessTokens/index.js +4 -0
  8. package/dist/accessTokens/mapping.d.ts +10 -0
  9. package/dist/accessTokens/mapping.js +25 -0
  10. package/dist/accessTokens/mutations.d.ts +4 -0
  11. package/dist/accessTokens/mutations.js +24 -0
  12. package/dist/accessTokens/revokations.d.ts +2 -0
  13. package/dist/accessTokens/revokations.js +18 -0
  14. package/dist/accessTokens/tokens.d.ts +31 -0
  15. package/dist/accessTokens/tokens.js +174 -0
  16. package/dist/accounts/cache.d.ts +3 -0
  17. package/dist/accounts/cache.js +13 -0
  18. package/dist/accounts/finders.d.ts +6 -0
  19. package/dist/accounts/finders.js +17 -0
  20. package/dist/accounts/helpers.d.ts +7 -0
  21. package/dist/accounts/helpers.js +36 -0
  22. package/dist/accounts/index.d.ts +6 -0
  23. package/dist/accounts/index.js +6 -0
  24. package/dist/accounts/mapping.d.ts +10 -0
  25. package/dist/accounts/mapping.js +28 -0
  26. package/dist/accounts/mutations.d.ts +21 -0
  27. package/dist/accounts/mutations.js +204 -0
  28. package/dist/analytics/cache.d.ts +6 -0
  29. package/dist/analytics/cache.js +29 -0
  30. package/dist/analytics/compile.d.ts +4 -0
  31. package/dist/analytics/compile.js +296 -0
  32. package/dist/analytics/dateRange.d.ts +39 -0
  33. package/dist/analytics/dateRange.js +181 -0
  34. package/dist/analytics/index.d.ts +8 -0
  35. package/dist/analytics/index.js +8 -0
  36. package/dist/analytics/jobs.d.ts +20 -0
  37. package/dist/analytics/jobs.js +84 -0
  38. package/dist/analytics/metrics.d.ts +4 -0
  39. package/dist/analytics/metrics.js +13 -0
  40. package/dist/analytics/pdfReport.d.ts +8 -0
  41. package/dist/analytics/pdfReport.js +821 -0
  42. package/dist/analytics/read.d.ts +6 -0
  43. package/dist/analytics/read.js +696 -0
  44. package/dist/analytics/report.d.ts +293 -0
  45. package/dist/analytics/report.js +153 -0
  46. package/dist/analytics/settings.d.ts +3 -0
  47. package/dist/analytics/settings.js +37 -0
  48. package/dist/backups/index.d.ts +5 -0
  49. package/dist/backups/index.js +260 -0
  50. package/dist/backups/metadata.d.ts +9 -0
  51. package/dist/backups/metadata.js +2 -0
  52. package/dist/config/db.d.ts +7 -0
  53. package/dist/config/db.js +26 -0
  54. package/dist/config/defaults/capabilities.d.ts +2 -0
  55. package/dist/config/defaults/capabilities.js +47 -0
  56. package/dist/config/defaults/community.d.ts +2 -0
  57. package/dist/config/defaults/community.js +41 -0
  58. package/dist/config/defaults/core.d.ts +2 -0
  59. package/dist/config/defaults/core.js +113 -0
  60. package/dist/config/defaults/db.d.ts +6 -0
  61. package/dist/config/defaults/db.js +8 -0
  62. package/dist/config/defaults/logs.d.ts +6 -0
  63. package/dist/config/defaults/logs.js +7 -0
  64. package/dist/config/defaults/redis.d.ts +4 -0
  65. package/dist/config/defaults/redis.js +5 -0
  66. package/dist/config/helpers.d.ts +11 -0
  67. package/dist/config/helpers.js +31 -0
  68. package/dist/config/index.d.ts +392 -0
  69. package/dist/config/index.js +83 -0
  70. package/dist/config/pruneEmptyConfigStrings.d.ts +7 -0
  71. package/dist/config/pruneEmptyConfigStrings.js +29 -0
  72. package/dist/db/aql.d.ts +0 -0
  73. package/dist/db/aql.js +1 -0
  74. package/dist/db/arango.d.ts +2 -0
  75. package/dist/db/arango.js +110 -0
  76. package/dist/db/bootMigrate.d.ts +1 -0
  77. package/dist/db/bootMigrate.js +15 -0
  78. package/dist/db/examples.d.ts +1 -0
  79. package/dist/db/examples.js +13 -0
  80. package/dist/db/explorer/csv.d.ts +1 -0
  81. package/dist/db/explorer/csv.js +18 -0
  82. package/dist/db/explorer/index.d.ts +6 -0
  83. package/dist/db/explorer/index.js +5 -0
  84. package/dist/db/explorer/mutate.d.ts +6 -0
  85. package/dist/db/explorer/mutate.js +66 -0
  86. package/dist/db/explorer/query.d.ts +17 -0
  87. package/dist/db/explorer/query.js +48 -0
  88. package/dist/db/explorer/sql.d.ts +11 -0
  89. package/dist/db/explorer/sql.js +42 -0
  90. package/dist/db/explorer/tables.d.ts +9 -0
  91. package/dist/db/explorer/tables.js +65 -0
  92. package/dist/db/helpers.d.ts +64 -0
  93. package/dist/db/helpers.js +240 -0
  94. package/dist/db/index.d.ts +13 -0
  95. package/dist/db/index.js +15 -0
  96. package/dist/db/init.d.ts +2 -0
  97. package/dist/db/init.js +10 -0
  98. package/dist/db/migration/autoMigrate.d.ts +2 -0
  99. package/dist/db/migration/autoMigrate.js +111 -0
  100. package/dist/db/migration/cli.d.ts +1 -0
  101. package/dist/db/migration/cli.js +56 -0
  102. package/dist/db/migration/detect.d.ts +6 -0
  103. package/dist/db/migration/detect.js +87 -0
  104. package/dist/db/migration/exportArango.d.ts +4 -0
  105. package/dist/db/migration/exportArango.js +80 -0
  106. package/dist/db/migration/importCollections.d.ts +19 -0
  107. package/dist/db/migration/importCollections.js +280 -0
  108. package/dist/db/migration/importPostgres.d.ts +3 -0
  109. package/dist/db/migration/importPostgres.js +18 -0
  110. package/dist/db/migration/shared.d.ts +39 -0
  111. package/dist/db/migration/shared.js +158 -0
  112. package/dist/db/migration/transform.d.ts +18 -0
  113. package/dist/db/migration/transform.js +209 -0
  114. package/dist/db/migration/validate.d.ts +18 -0
  115. package/dist/db/migration/validate.js +69 -0
  116. package/dist/db/pg/client.d.ts +35 -0
  117. package/dist/db/pg/client.js +126 -0
  118. package/dist/db/pg/collections.d.ts +48 -0
  119. package/dist/db/pg/collections.js +53 -0
  120. package/dist/db/pg/filters/common.d.ts +21 -0
  121. package/dist/db/pg/filters/common.js +48 -0
  122. package/dist/db/pg/filters/edges.d.ts +9 -0
  123. package/dist/db/pg/filters/edges.js +10 -0
  124. package/dist/db/pg/filters/groups.d.ts +7 -0
  125. package/dist/db/pg/filters/groups.js +15 -0
  126. package/dist/db/pg/filters/index.d.ts +22 -0
  127. package/dist/db/pg/filters/index.js +35 -0
  128. package/dist/db/pg/filters/notifications.d.ts +6 -0
  129. package/dist/db/pg/filters/notifications.js +10 -0
  130. package/dist/db/pg/filters/posts.d.ts +18 -0
  131. package/dist/db/pg/filters/posts.js +25 -0
  132. package/dist/db/pg/filters/profiles.d.ts +6 -0
  133. package/dist/db/pg/filters/profiles.js +9 -0
  134. package/dist/db/pg/filters/types.d.ts +7 -0
  135. package/dist/db/pg/filters/types.js +5 -0
  136. package/dist/db/pg/helpers.d.ts +19 -0
  137. package/dist/db/pg/helpers.js +67 -0
  138. package/dist/db/pg/map/filters.d.ts +22 -0
  139. package/dist/db/pg/map/filters.js +566 -0
  140. package/dist/db/pg/map/helpers.d.ts +2 -0
  141. package/dist/db/pg/map/helpers.js +2 -0
  142. package/dist/db/pg/map/index.d.ts +46 -0
  143. package/dist/db/pg/map/index.js +93 -0
  144. package/dist/db/pg/map/mutations.d.ts +11 -0
  145. package/dist/db/pg/map/mutations.js +135 -0
  146. package/dist/db/pg/map/queryTypes.d.ts +115 -0
  147. package/dist/db/pg/map/queryTypes.js +1 -0
  148. package/dist/db/pg/map/registry.d.ts +29 -0
  149. package/dist/db/pg/map/registry.js +413 -0
  150. package/dist/db/pg/map/relations.d.ts +28 -0
  151. package/dist/db/pg/map/relations.js +399 -0
  152. package/dist/db/pg/map/search.d.ts +6 -0
  153. package/dist/db/pg/map/search.js +190 -0
  154. package/dist/db/pg/map/types.d.ts +11 -0
  155. package/dist/db/pg/map/types.js +1 -0
  156. package/dist/db/pg/mappers.d.ts +28 -0
  157. package/dist/db/pg/mappers.js +29 -0
  158. package/dist/db/pg/migrate.d.ts +14 -0
  159. package/dist/db/pg/migrate.js +134 -0
  160. package/dist/db/pg/queries/activity.d.ts +10 -0
  161. package/dist/db/pg/queries/activity.js +47 -0
  162. package/dist/db/pg/queries/computed.d.ts +7 -0
  163. package/dist/db/pg/queries/computed.js +19 -0
  164. package/dist/db/pg/queries/derived.d.ts +22 -0
  165. package/dist/db/pg/queries/derived.js +100 -0
  166. package/dist/db/pg/queries/index.d.ts +4 -0
  167. package/dist/db/pg/queries/index.js +4 -0
  168. package/dist/db/pg/queries/sorts.d.ts +10 -0
  169. package/dist/db/pg/queries/sorts.js +9 -0
  170. package/dist/db/pg/schema/analytics.d.ts +998 -0
  171. package/dist/db/pg/schema/analytics.js +110 -0
  172. package/dist/db/pg/schema/base.d.ts +36 -0
  173. package/dist/db/pg/schema/base.js +23 -0
  174. package/dist/db/pg/schema/documents.d.ts +2002 -0
  175. package/dist/db/pg/schema/documents.js +40 -0
  176. package/dist/db/pg/schema/edges.d.ts +2725 -0
  177. package/dist/db/pg/schema/edges.js +34 -0
  178. package/dist/db/pg/schema/index.d.ts +5724 -0
  179. package/dist/db/pg/schema/index.js +7 -0
  180. package/dist/db/pg/sql/0000_bizarre_chat.sql +456 -0
  181. package/dist/db/pg/sql/0001_search_vector.sql +122 -0
  182. package/dist/db/pg/sql/0002_data_migrations_id_text.sql +1 -0
  183. package/dist/db/pg/sql/0003_fix_group_post_visibility.sql +4 -0
  184. package/dist/db/pg/sql/0004_analytics.sql +90 -0
  185. package/dist/db/pg/sql/meta/0000_snapshot.json +3380 -0
  186. package/dist/db/pg/sql/meta/0004_snapshot.json +4114 -0
  187. package/dist/db/pg/sql/meta/_journal.json +41 -0
  188. package/dist/db/replaceHostname.d.ts +1 -0
  189. package/dist/db/replaceHostname.js +88 -0
  190. package/dist/db/types.d.ts +17 -0
  191. package/dist/db/types.js +1 -0
  192. package/dist/email/index.d.ts +9 -0
  193. package/dist/email/index.js +19 -0
  194. package/dist/email/jobs.d.ts +3 -0
  195. package/dist/email/jobs.js +13 -0
  196. package/dist/email/queueStats.d.ts +2 -0
  197. package/dist/email/queueStats.js +27 -0
  198. package/dist/email/registry.d.ts +3 -0
  199. package/dist/email/registry.js +4 -0
  200. package/dist/email/render.d.ts +8 -0
  201. package/dist/email/render.js +34 -0
  202. package/dist/email/send.d.ts +9 -0
  203. package/dist/email/send.js +97 -0
  204. package/dist/email/smtpTest.d.ts +2 -0
  205. package/dist/email/smtpTest.js +26 -0
  206. package/dist/errors/index.d.ts +8 -0
  207. package/dist/errors/index.js +13 -0
  208. package/dist/events/index.d.ts +31 -0
  209. package/dist/events/index.js +66 -0
  210. package/dist/events/once.d.ts +4 -0
  211. package/dist/events/once.js +23 -0
  212. package/dist/groups/finders.d.ts +125 -0
  213. package/dist/groups/finders.js +18 -0
  214. package/dist/groups/helpers.d.ts +227 -0
  215. package/dist/groups/helpers.js +17 -0
  216. package/dist/groups/index.d.ts +3 -0
  217. package/dist/groups/index.js +3 -0
  218. package/dist/groups/mapping.d.ts +188 -0
  219. package/dist/groups/mapping.js +47 -0
  220. package/dist/groups/mutations.d.ts +26 -0
  221. package/dist/groups/mutations.js +41 -0
  222. package/dist/hashtags/finders.d.ts +3 -0
  223. package/dist/hashtags/finders.js +22 -0
  224. package/dist/hashtags/index.d.ts +2 -0
  225. package/dist/hashtags/index.js +2 -0
  226. package/dist/hashtags/mapping.d.ts +4 -0
  227. package/dist/hashtags/mapping.js +5 -0
  228. package/dist/hashtags/mutations.d.ts +0 -0
  229. package/dist/hashtags/mutations.js +1 -0
  230. package/dist/i18n/index.d.ts +14 -0
  231. package/dist/i18n/index.js +53 -0
  232. package/dist/index.d.ts +0 -0
  233. package/dist/index.js +1 -0
  234. package/dist/inviteLinks/finders.d.ts +3 -0
  235. package/dist/inviteLinks/finders.js +5 -0
  236. package/dist/inviteLinks/helpers.d.ts +20 -0
  237. package/dist/inviteLinks/helpers.js +4 -0
  238. package/dist/inviteLinks/index.d.ts +3 -0
  239. package/dist/inviteLinks/index.js +3 -0
  240. package/dist/inviteLinks/mapping.d.ts +10 -0
  241. package/dist/inviteLinks/mapping.js +35 -0
  242. package/dist/inviteLinks/mutations.d.ts +4 -0
  243. package/dist/inviteLinks/mutations.js +39 -0
  244. package/dist/jams/cache.d.ts +9 -0
  245. package/dist/jams/cache.js +13 -0
  246. package/dist/jams/finders.d.ts +23 -0
  247. package/dist/jams/finders.js +24 -0
  248. package/dist/jams/helpers.d.ts +70 -0
  249. package/dist/jams/helpers.js +29 -0
  250. package/dist/jams/index.d.ts +15 -0
  251. package/dist/jams/index.js +108 -0
  252. package/dist/jams/jobs.d.ts +9 -0
  253. package/dist/jams/jobs.js +42 -0
  254. package/dist/jams/livekit.d.ts +24 -0
  255. package/dist/jams/livekit.js +220 -0
  256. package/dist/jams/mapping.d.ts +137 -0
  257. package/dist/jams/mapping.js +35 -0
  258. package/dist/jams/mutations.d.ts +40 -0
  259. package/dist/jams/mutations.js +4 -0
  260. package/dist/jams/recording.d.ts +8 -0
  261. package/dist/jams/recording.js +67 -0
  262. package/dist/jams/recordingUploadAuth.d.ts +9 -0
  263. package/dist/jams/recordingUploadAuth.js +19 -0
  264. package/dist/jams/token.d.ts +4 -0
  265. package/dist/jams/token.js +129 -0
  266. package/dist/jams/waitingRoom.d.ts +5 -0
  267. package/dist/jams/waitingRoom.js +71 -0
  268. package/dist/jobs/index.d.ts +10 -0
  269. package/dist/jobs/index.js +60 -0
  270. package/dist/jobs/jobDetail.d.ts +2 -0
  271. package/dist/jobs/jobDetail.js +31 -0
  272. package/dist/jobs/jobLog.d.ts +18 -0
  273. package/dist/jobs/jobLog.js +61 -0
  274. package/dist/jwt/index.d.ts +10 -0
  275. package/dist/jwt/index.js +43 -0
  276. package/dist/lib/index.d.ts +2 -0
  277. package/dist/lib/index.js +2 -0
  278. package/dist/lib/streams.d.ts +2 -0
  279. package/dist/lib/streams.js +56 -0
  280. package/dist/lib/utils.d.ts +2 -0
  281. package/dist/lib/utils.js +17 -0
  282. package/dist/lib/zodDeepPartial.d.ts +3 -0
  283. package/dist/lib/zodDeepPartial.js +26 -0
  284. package/dist/location/index.d.ts +2 -0
  285. package/dist/location/index.js +28 -0
  286. package/dist/log/index.d.ts +3 -0
  287. package/dist/log/index.js +97 -0
  288. package/dist/mastodon/index.d.ts +4 -0
  289. package/dist/mastodon/index.js +51 -0
  290. package/dist/mastodon/types.d.ts +7579 -0
  291. package/dist/mastodon/types.js +523 -0
  292. package/dist/mastodon/typescript.d.ts +1578 -0
  293. package/dist/mastodon/typescript.js +1 -0
  294. package/dist/media/index.d.ts +40 -0
  295. package/dist/media/index.js +248 -0
  296. package/dist/media/ipfs/index.d.ts +0 -0
  297. package/dist/media/ipfs/index.js +39 -0
  298. package/dist/media/jobs.d.ts +19 -0
  299. package/dist/media/jobs.js +90 -0
  300. package/dist/media/openpeeps/index.d.ts +3 -0
  301. package/dist/media/openpeeps/index.js +131 -0
  302. package/dist/media/processing.d.ts +19 -0
  303. package/dist/media/processing.js +83 -0
  304. package/dist/media/streaming.d.ts +77 -0
  305. package/dist/media/streaming.js +257 -0
  306. package/dist/media/streamingCleanupJobs.d.ts +14 -0
  307. package/dist/media/streamingCleanupJobs.js +47 -0
  308. package/dist/media/streamingJobs.d.ts +5 -0
  309. package/dist/media/streamingJobs.js +329 -0
  310. package/dist/media/streamingPrewarm.d.ts +36 -0
  311. package/dist/media/streamingPrewarm.js +109 -0
  312. package/dist/mediaAttachments/finders.d.ts +1 -0
  313. package/dist/mediaAttachments/finders.js +3 -0
  314. package/dist/mediaAttachments/index.d.ts +5 -0
  315. package/dist/mediaAttachments/index.js +12 -0
  316. package/dist/mediaAttachments/mapping.d.ts +21 -0
  317. package/dist/mediaAttachments/mapping.js +4 -0
  318. package/dist/mediaAttachments/mutations.d.ts +3 -0
  319. package/dist/mediaAttachments/mutations.js +10 -0
  320. package/dist/notifications/defaultNotifications/announcement/index.d.ts +24 -0
  321. package/dist/notifications/defaultNotifications/announcement/index.js +42 -0
  322. package/dist/notifications/defaultNotifications/directMessage/index.d.ts +28 -0
  323. package/dist/notifications/defaultNotifications/directMessage/index.js +69 -0
  324. package/dist/notifications/defaultNotifications/follow/index.d.ts +24 -0
  325. package/dist/notifications/defaultNotifications/follow/index.js +31 -0
  326. package/dist/notifications/defaultNotifications/groupAdded/index.d.ts +18 -0
  327. package/dist/notifications/defaultNotifications/groupAdded/index.js +33 -0
  328. package/dist/notifications/defaultNotifications/groupMemberJoined/index.d.ts +18 -0
  329. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +36 -0
  330. package/dist/notifications/defaultNotifications/groupMemberLeft/index.d.ts +18 -0
  331. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +36 -0
  332. package/dist/notifications/defaultNotifications/index.d.ts +3 -0
  333. package/dist/notifications/defaultNotifications/index.js +43 -0
  334. package/dist/notifications/defaultNotifications/jamModerator/index.d.ts +23 -0
  335. package/dist/notifications/defaultNotifications/jamModerator/index.js +49 -0
  336. package/dist/notifications/defaultNotifications/jamSpeaker/index.d.ts +23 -0
  337. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +47 -0
  338. package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +18 -0
  339. package/dist/notifications/defaultNotifications/jamStarted/index.js +82 -0
  340. package/dist/notifications/defaultNotifications/mention/index.d.ts +24 -0
  341. package/dist/notifications/defaultNotifications/mention/index.js +89 -0
  342. package/dist/notifications/defaultNotifications/newGroupPost/index.d.ts +24 -0
  343. package/dist/notifications/defaultNotifications/newGroupPost/index.js +47 -0
  344. package/dist/notifications/defaultNotifications/newProfile/index.d.ts +24 -0
  345. package/dist/notifications/defaultNotifications/newProfile/index.js +40 -0
  346. package/dist/notifications/defaultNotifications/pollVote/index.d.ts +19 -0
  347. package/dist/notifications/defaultNotifications/pollVote/index.js +40 -0
  348. package/dist/notifications/defaultNotifications/reaction/index.d.ts +18 -0
  349. package/dist/notifications/defaultNotifications/reaction/index.js +43 -0
  350. package/dist/notifications/defaultNotifications/reply/index.d.ts +25 -0
  351. package/dist/notifications/defaultNotifications/reply/index.js +57 -0
  352. package/dist/notifications/defaultNotifications/repost/index.d.ts +18 -0
  353. package/dist/notifications/defaultNotifications/repost/index.js +42 -0
  354. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +19 -0
  355. package/dist/notifications/defaultNotifications/rsvp/index.js +40 -0
  356. package/dist/notifications/fcmCredential.d.ts +14 -0
  357. package/dist/notifications/fcmCredential.js +68 -0
  358. package/dist/notifications/finders.d.ts +7 -0
  359. package/dist/notifications/finders.js +13 -0
  360. package/dist/notifications/firebase.d.ts +1 -0
  361. package/dist/notifications/firebase.js +33 -0
  362. package/dist/notifications/handlers.d.ts +3 -0
  363. package/dist/notifications/handlers.js +6 -0
  364. package/dist/notifications/helpers.d.ts +7 -0
  365. package/dist/notifications/helpers.js +31 -0
  366. package/dist/notifications/index.d.ts +9 -0
  367. package/dist/notifications/index.js +43 -0
  368. package/dist/notifications/jobs.d.ts +2 -0
  369. package/dist/notifications/jobs.js +75 -0
  370. package/dist/notifications/mapping.d.ts +25 -0
  371. package/dist/notifications/mapping.js +25 -0
  372. package/dist/notifications/mutations.d.ts +6 -0
  373. package/dist/notifications/mutations.js +40 -0
  374. package/dist/notifications/push.d.ts +9 -0
  375. package/dist/notifications/push.js +261 -0
  376. package/dist/notifications/pushInvalidation.d.ts +10 -0
  377. package/dist/notifications/pushInvalidation.js +10 -0
  378. package/dist/performance/index.d.ts +24 -0
  379. package/dist/performance/index.js +61 -0
  380. package/dist/plugins/helpers.d.ts +3 -0
  381. package/dist/plugins/helpers.js +72 -0
  382. package/dist/plugins/index.d.ts +10 -0
  383. package/dist/plugins/index.js +84 -0
  384. package/dist/plugins/pluginAuth.d.ts +30 -0
  385. package/dist/plugins/pluginAuth.js +44 -0
  386. package/dist/posts/contextClosure.d.ts +16 -0
  387. package/dist/posts/contextClosure.js +66 -0
  388. package/dist/posts/finders.d.ts +298 -0
  389. package/dist/posts/finders.js +259 -0
  390. package/dist/posts/helpers/filters.d.ts +14 -0
  391. package/dist/posts/helpers/filters.js +39 -0
  392. package/dist/posts/helpers/index.d.ts +837 -0
  393. package/dist/posts/helpers/index.js +117 -0
  394. package/dist/posts/index.d.ts +6 -0
  395. package/dist/posts/index.js +6 -0
  396. package/dist/posts/mapping.d.ts +2187 -0
  397. package/dist/posts/mapping.js +222 -0
  398. package/dist/posts/mutations.d.ts +19 -0
  399. package/dist/posts/mutations.js +202 -0
  400. package/dist/posts/rsvpConfirmationEmail.d.ts +2 -0
  401. package/dist/posts/rsvpConfirmationEmail.js +82 -0
  402. package/dist/processingStats/index.d.ts +3 -0
  403. package/dist/processingStats/index.js +3 -0
  404. package/dist/processingStats/mapping.d.ts +7 -0
  405. package/dist/processingStats/mapping.js +4 -0
  406. package/dist/processingStats/mutations.d.ts +2 -0
  407. package/dist/processingStats/mutations.js +6 -0
  408. package/dist/processingStats/queries.d.ts +4 -0
  409. package/dist/processingStats/queries.js +46 -0
  410. package/dist/profileSettings/cache.d.ts +2 -0
  411. package/dist/profileSettings/cache.js +24 -0
  412. package/dist/profileSettings/finders.d.ts +1 -0
  413. package/dist/profileSettings/finders.js +2 -0
  414. package/dist/profileSettings/index.d.ts +3 -0
  415. package/dist/profileSettings/index.js +3 -0
  416. package/dist/profileSettings/mapping.d.ts +38 -0
  417. package/dist/profileSettings/mapping.js +5 -0
  418. package/dist/profileSettings/mutations.d.ts +3 -0
  419. package/dist/profileSettings/mutations.js +24 -0
  420. package/dist/profiles/cache.d.ts +5 -0
  421. package/dist/profiles/cache.js +19 -0
  422. package/dist/profiles/capacity.d.ts +2 -0
  423. package/dist/profiles/capacity.js +20 -0
  424. package/dist/profiles/export.d.ts +3 -0
  425. package/dist/profiles/export.js +85 -0
  426. package/dist/profiles/finders.d.ts +11 -0
  427. package/dist/profiles/finders.js +39 -0
  428. package/dist/profiles/helpers.d.ts +35 -0
  429. package/dist/profiles/helpers.js +10 -0
  430. package/dist/profiles/index.d.ts +5 -0
  431. package/dist/profiles/index.js +18 -0
  432. package/dist/profiles/mapping.d.ts +157 -0
  433. package/dist/profiles/mapping.js +132 -0
  434. package/dist/profiles/mutations.d.ts +9 -0
  435. package/dist/profiles/mutations.js +75 -0
  436. package/dist/pushSubscriptions/finders.d.ts +187 -0
  437. package/dist/pushSubscriptions/finders.js +6 -0
  438. package/dist/pushSubscriptions/helpers.d.ts +99 -0
  439. package/dist/pushSubscriptions/helpers.js +3 -0
  440. package/dist/pushSubscriptions/index.d.ts +3 -0
  441. package/dist/pushSubscriptions/index.js +3 -0
  442. package/dist/pushSubscriptions/mapping.d.ts +261 -0
  443. package/dist/pushSubscriptions/mapping.js +6 -0
  444. package/dist/pushSubscriptions/mutations.d.ts +95 -0
  445. package/dist/pushSubscriptions/mutations.js +21 -0
  446. package/dist/redis/connection.d.ts +4 -0
  447. package/dist/redis/connection.js +17 -0
  448. package/dist/redis/index.d.ts +1 -0
  449. package/dist/redis/index.js +1 -0
  450. package/dist/reports/finders.d.ts +6 -0
  451. package/dist/reports/finders.js +44 -0
  452. package/dist/reports/helpers.d.ts +21 -0
  453. package/dist/reports/helpers.js +12 -0
  454. package/dist/reports/index.d.ts +3 -0
  455. package/dist/reports/index.js +3 -0
  456. package/dist/reports/mapping.d.ts +9 -0
  457. package/dist/reports/mapping.js +34 -0
  458. package/dist/reports/mutations.d.ts +5 -0
  459. package/dist/reports/mutations.js +16 -0
  460. package/dist/roles/defaults.d.ts +2 -0
  461. package/dist/roles/defaults.js +94 -0
  462. package/dist/roles/finders.d.ts +5 -0
  463. package/dist/roles/finders.js +9 -0
  464. package/dist/roles/index.d.ts +4 -0
  465. package/dist/roles/index.js +4 -0
  466. package/dist/roles/mapping.d.ts +11 -0
  467. package/dist/roles/mapping.js +5 -0
  468. package/dist/roles/mutations.d.ts +4 -0
  469. package/dist/roles/mutations.js +30 -0
  470. package/dist/search/finders.d.ts +47 -0
  471. package/dist/search/finders.js +59 -0
  472. package/dist/search/helpers.d.ts +3 -0
  473. package/dist/search/helpers.js +1 -0
  474. package/dist/search/index.d.ts +1 -0
  475. package/dist/search/index.js +1 -0
  476. package/dist/search/mapping.d.ts +40 -0
  477. package/dist/search/mapping.js +43 -0
  478. package/dist/sentry/index.d.ts +34 -0
  479. package/dist/sentry/index.js +113 -0
  480. package/dist/server/helpers.d.ts +0 -0
  481. package/dist/server/helpers.js +1 -0
  482. package/dist/server/index.d.ts +105 -0
  483. package/dist/server/index.js +64 -0
  484. package/dist/stats/finders.d.ts +16156 -0
  485. package/dist/stats/finders.js +167 -0
  486. package/dist/stats/helpers.d.ts +17 -0
  487. package/dist/stats/helpers.js +34 -0
  488. package/dist/stats/index.d.ts +1 -0
  489. package/dist/stats/index.js +1 -0
  490. package/dist/stats/mapping.d.ts +188 -0
  491. package/dist/stats/mapping.js +19 -0
  492. package/dist/stripe/cache.d.ts +30 -0
  493. package/dist/stripe/cache.js +37 -0
  494. package/dist/stripe/connection.d.ts +5 -0
  495. package/dist/stripe/connection.js +23 -0
  496. package/dist/stripe/helpers.d.ts +25 -0
  497. package/dist/stripe/helpers.js +211 -0
  498. package/dist/stripe/index.d.ts +3 -0
  499. package/dist/stripe/index.js +3 -0
  500. package/package.json +99 -0
@@ -0,0 +1,6 @@
1
+ export { listExplorerTables, getExplorerTable, describeExplorerTable, quoteIdent, assertKnownColumns, primaryKeyColumns, } from './tables';
2
+ export { listExplorerRows, DEFAULT_ROW_LIMIT, MAX_ROW_LIMIT, MAX_EXPORT_LIMIT, clampLimit, buildFilterClause, } from './query';
3
+ export type { ListRowsInput } from './query';
4
+ export { updateExplorerRow } from './mutate';
5
+ export { runExplorerSql, SQL_STATEMENT_TIMEOUT_MS, SQL_MAX_ROWS, SQL_HARD_MAX_ROWS, SQL_DEFAULT_MAX_ROWS } from './sql';
6
+ export { rowsToCsv } from './csv';
@@ -0,0 +1,5 @@
1
+ export { listExplorerTables, getExplorerTable, describeExplorerTable, quoteIdent, assertKnownColumns, primaryKeyColumns, } from './tables.js';
2
+ export { listExplorerRows, DEFAULT_ROW_LIMIT, MAX_ROW_LIMIT, MAX_EXPORT_LIMIT, clampLimit, buildFilterClause, } from './query.js';
3
+ export { updateExplorerRow } from './mutate.js';
4
+ export { runExplorerSql, SQL_STATEMENT_TIMEOUT_MS, SQL_MAX_ROWS, SQL_HARD_MAX_ROWS, SQL_DEFAULT_MAX_ROWS } from './sql.js';
5
+ export { rowsToCsv } from './csv.js';
@@ -0,0 +1,6 @@
1
+ import type { ExplorerUpdateRowResponse } from '@openpeepshq/common/types';
2
+ export declare const updateExplorerRow: (input: {
3
+ table: string;
4
+ primaryKey: Record<string, unknown>;
5
+ patch: Record<string, unknown>;
6
+ }) => Promise<ExplorerUpdateRowResponse>;
@@ -0,0 +1,66 @@
1
+ import { pgPool } from '../pg/client.js';
2
+ import { assertKnownColumns, describeExplorerTable, getExplorerTable, primaryKeyColumns, quoteIdent, } from './tables.js';
3
+ const coercePatchValue = (dataType, value) => {
4
+ if (value === null || value === undefined)
5
+ return value;
6
+ if (dataType.includes('json')) {
7
+ if (typeof value === 'string') {
8
+ return JSON.parse(value);
9
+ }
10
+ return value;
11
+ }
12
+ if (dataType.includes('bool') && typeof value === 'string') {
13
+ if (value === 'true')
14
+ return true;
15
+ if (value === 'false')
16
+ return false;
17
+ }
18
+ if ((dataType.includes('int') || dataType.includes('numeric')) &&
19
+ typeof value === 'string' &&
20
+ value !== '' &&
21
+ !Number.isNaN(Number(value))) {
22
+ return Number(value);
23
+ }
24
+ return value;
25
+ };
26
+ export const updateExplorerRow = async (input) => {
27
+ const { table: tableName, primaryKey, patch } = input;
28
+ getExplorerTable(tableName);
29
+ const meta = describeExplorerTable(getExplorerTable(tableName));
30
+ const colByName = new Map(meta.columns.map((c) => [c.name, c]));
31
+ const pkCols = primaryKeyColumns(tableName);
32
+ const pkNames = pkCols.map((c) => c.name);
33
+ for (const name of pkNames) {
34
+ if (!(name in primaryKey)) {
35
+ throw new Error(`Missing primary key field: ${name}`);
36
+ }
37
+ }
38
+ assertKnownColumns(tableName, Object.keys(primaryKey));
39
+ const patchKeys = Object.keys(patch);
40
+ if (!patchKeys.length) {
41
+ throw new Error('patch must include at least one column');
42
+ }
43
+ assertKnownColumns(tableName, patchKeys);
44
+ for (const key of patchKeys) {
45
+ if (pkNames.includes(key)) {
46
+ throw new Error(`Cannot patch primary key column: ${key}`);
47
+ }
48
+ }
49
+ const params = [];
50
+ const setClauses = patchKeys.map((key) => {
51
+ const col = colByName.get(key);
52
+ params.push(coercePatchValue(col.dataType, patch[key]));
53
+ return `${quoteIdent(key)} = $${params.length}`;
54
+ });
55
+ const whereClauses = pkNames.map((key) => {
56
+ params.push(primaryKey[key]);
57
+ return `${quoteIdent(key)} = $${params.length}`;
58
+ });
59
+ const result = await pgPool().query(`UPDATE ${quoteIdent(tableName)} SET ${setClauses.join(', ')} WHERE ${whereClauses.join(' AND ')} RETURNING *`, params);
60
+ if (!result.rows[0]) {
61
+ throw new Error(`No row updated in ${tableName}`);
62
+ }
63
+ return {
64
+ row: result.rows[0],
65
+ };
66
+ };
@@ -0,0 +1,17 @@
1
+ import type { ExplorerRowsResponse } from '@openpeepshq/common/types';
2
+ export declare const DEFAULT_ROW_LIMIT = 100;
3
+ /** Hard cap for browse page sizes (50 / 200 / 1000 / All). */
4
+ export declare const MAX_ROW_LIMIT = 10000;
5
+ export declare const MAX_EXPORT_LIMIT = 10000;
6
+ export type ListRowsInput = {
7
+ table: string;
8
+ filters?: Record<string, string>;
9
+ limit?: number;
10
+ offset?: number;
11
+ orderBy?: string;
12
+ };
13
+ export declare const clampLimit: (limit: number | undefined, max: number) => number;
14
+ export declare const buildFilterClause: (tableName: string, filters: Record<string, string> | undefined, params: unknown[]) => string;
15
+ export declare const listExplorerRows: (input: ListRowsInput, options?: {
16
+ maxLimit?: number;
17
+ }) => Promise<ExplorerRowsResponse>;
@@ -0,0 +1,48 @@
1
+ import { pgPool } from '../pg/client.js';
2
+ import { assertKnownColumns, describeExplorerTable, getExplorerTable, primaryKeyColumns, quoteIdent, } from './tables.js';
3
+ export const DEFAULT_ROW_LIMIT = 100;
4
+ /** Hard cap for browse page sizes (50 / 200 / 1000 / All). */
5
+ export const MAX_ROW_LIMIT = 10000;
6
+ export const MAX_EXPORT_LIMIT = 10000;
7
+ export const clampLimit = (limit, max) => {
8
+ const n = limit !== null && limit !== void 0 ? limit : DEFAULT_ROW_LIMIT;
9
+ if (!Number.isFinite(n) || n < 1)
10
+ return DEFAULT_ROW_LIMIT;
11
+ return Math.min(Math.floor(n), max);
12
+ };
13
+ export const buildFilterClause = (tableName, filters, params) => {
14
+ if (!filters || !Object.keys(filters).length)
15
+ return '';
16
+ assertKnownColumns(tableName, Object.keys(filters));
17
+ const parts = Object.entries(filters).map(([col, value]) => {
18
+ params.push(`%${value}%`);
19
+ return `${quoteIdent(col)}::text ILIKE $${params.length}`;
20
+ });
21
+ return ` WHERE ${parts.join(' AND ')}`;
22
+ };
23
+ export const listExplorerRows = async (input, options) => {
24
+ var _a, _b, _c, _d, _e, _f, _g, _h;
25
+ const tableName = input.table;
26
+ const meta = describeExplorerTable(getExplorerTable(tableName));
27
+ const maxLimit = (_a = options === null || options === void 0 ? void 0 : options.maxLimit) !== null && _a !== void 0 ? _a : MAX_ROW_LIMIT;
28
+ const limit = clampLimit(input.limit, maxLimit);
29
+ const offset = Math.max(0, Math.floor((_b = input.offset) !== null && _b !== void 0 ? _b : 0));
30
+ const orderCol = (_e = (_c = input.orderBy) !== null && _c !== void 0 ? _c : (_d = primaryKeyColumns(tableName)[0]) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : (_f = meta.columns[0]) === null || _f === void 0 ? void 0 : _f.name;
31
+ if (!orderCol) {
32
+ throw new Error(`Table ${tableName} has no columns`);
33
+ }
34
+ assertKnownColumns(tableName, [orderCol]);
35
+ const filterParams = [];
36
+ const where = buildFilterClause(tableName, input.filters, filterParams);
37
+ const tableSql = quoteIdent(tableName);
38
+ const countResult = await pgPool().query(`SELECT count(*)::text AS count FROM ${tableSql}${where}`, filterParams);
39
+ const total = Number((_h = (_g = countResult.rows[0]) === null || _g === void 0 ? void 0 : _g.count) !== null && _h !== void 0 ? _h : 0);
40
+ const result = await pgPool().query(`SELECT * FROM ${tableSql}${where} ORDER BY ${quoteIdent(orderCol)} LIMIT $${filterParams.length + 1} OFFSET $${filterParams.length + 2}`, [...filterParams, limit, offset]);
41
+ return {
42
+ columns: meta.columns.map((c) => c.name),
43
+ rows: result.rows,
44
+ total,
45
+ limit,
46
+ offset,
47
+ };
48
+ };
@@ -0,0 +1,11 @@
1
+ import type { ExplorerSqlResponse } from '@openpeepshq/common/types';
2
+ export declare const SQL_STATEMENT_TIMEOUT_MS = 15000;
3
+ /** Absolute cap for returned SQL rows (All). */
4
+ export declare const SQL_HARD_MAX_ROWS = 100000;
5
+ /** Default cap when the client does not request a limit. */
6
+ export declare const SQL_DEFAULT_MAX_ROWS = 1000;
7
+ /** @deprecated Use SQL_HARD_MAX_ROWS */
8
+ export declare const SQL_MAX_ROWS = 100000;
9
+ export declare const runExplorerSql: (statement: string, options?: {
10
+ limit?: number;
11
+ }) => Promise<ExplorerSqlResponse>;
@@ -0,0 +1,42 @@
1
+ import { pgPool } from '../pg/client.js';
2
+ export const SQL_STATEMENT_TIMEOUT_MS = 15000;
3
+ /** Absolute cap for returned SQL rows (All). */
4
+ export const SQL_HARD_MAX_ROWS = 100000;
5
+ /** Default cap when the client does not request a limit. */
6
+ export const SQL_DEFAULT_MAX_ROWS = 1000;
7
+ /** @deprecated Use SQL_HARD_MAX_ROWS */
8
+ export const SQL_MAX_ROWS = SQL_HARD_MAX_ROWS;
9
+ export const runExplorerSql = async (statement, options) => {
10
+ var _a, _b, _c;
11
+ const trimmed = statement.trim();
12
+ if (!trimmed) {
13
+ throw new Error('SQL statement is empty');
14
+ }
15
+ const requested = options === null || options === void 0 ? void 0 : options.limit;
16
+ const maxRows = requested != null && Number.isFinite(requested) && requested > 0
17
+ ? Math.min(Math.floor(requested), SQL_HARD_MAX_ROWS)
18
+ : SQL_DEFAULT_MAX_ROWS;
19
+ const client = await pgPool().connect();
20
+ try {
21
+ await client.query(`SET statement_timeout = ${SQL_STATEMENT_TIMEOUT_MS}`);
22
+ const result = await client.query(trimmed);
23
+ const allRows = result.rows;
24
+ const rows = allRows.slice(0, maxRows);
25
+ const columns = (_b = (_a = result.fields) === null || _a === void 0 ? void 0 : _a.map((f) => f.name)) !== null && _b !== void 0 ? _b : (rows[0] ? Object.keys(rows[0]) : []);
26
+ return {
27
+ columns,
28
+ rows,
29
+ rowCount: (_c = result.rowCount) !== null && _c !== void 0 ? _c : allRows.length,
30
+ command: result.command,
31
+ };
32
+ }
33
+ finally {
34
+ try {
35
+ await client.query('SET statement_timeout = 0');
36
+ }
37
+ catch (_d) {
38
+ // ignore reset failures on a broken connection
39
+ }
40
+ client.release();
41
+ }
42
+ };
@@ -0,0 +1,9 @@
1
+ import { type Table } from 'drizzle-orm';
2
+ import type { ExplorerColumn, ExplorerTable } from '@openpeepshq/common/types';
3
+ export declare const getExplorerTableMap: () => Map<string, Table>;
4
+ export declare const getExplorerTable: (tableName: string) => Table;
5
+ export declare const describeExplorerTable: (table: Table) => ExplorerTable;
6
+ export declare const listExplorerTables: () => ExplorerTable[];
7
+ export declare const quoteIdent: (ident: string) => string;
8
+ export declare const assertKnownColumns: (tableName: string, columnNames: string[]) => ExplorerColumn[];
9
+ export declare const primaryKeyColumns: (tableName: string) => ExplorerColumn[];
@@ -0,0 +1,65 @@
1
+ import { getTableColumns, getTableName, isTable, } from 'drizzle-orm';
2
+ import { schema } from '../pg/schema/index.js';
3
+ const tableBySqlName = () => {
4
+ const map = new Map();
5
+ for (const value of Object.values(schema)) {
6
+ if (!isTable(value))
7
+ continue;
8
+ map.set(getTableName(value), value);
9
+ }
10
+ return map;
11
+ };
12
+ let cachedTables;
13
+ export const getExplorerTableMap = () => {
14
+ if (!cachedTables) {
15
+ cachedTables = tableBySqlName();
16
+ }
17
+ return cachedTables;
18
+ };
19
+ export const getExplorerTable = (tableName) => {
20
+ const table = getExplorerTableMap().get(tableName);
21
+ if (!table) {
22
+ throw new Error(`Unknown table: ${tableName}`);
23
+ }
24
+ return table;
25
+ };
26
+ export const describeExplorerTable = (table) => {
27
+ const columns = getTableColumns(table);
28
+ return {
29
+ name: getTableName(table),
30
+ columns: Object.values(columns).map((col) => ({
31
+ name: col.name,
32
+ dataType: col.getSQLType(),
33
+ primaryKey: col.primary,
34
+ notNull: col.notNull,
35
+ })),
36
+ };
37
+ };
38
+ export const listExplorerTables = () => [...getExplorerTableMap().values()]
39
+ .map(describeExplorerTable)
40
+ .sort((a, b) => a.name.localeCompare(b.name));
41
+ export const quoteIdent = (ident) => {
42
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(ident)) {
43
+ throw new Error(`Invalid identifier: ${ident}`);
44
+ }
45
+ return `"${ident}"`;
46
+ };
47
+ export const assertKnownColumns = (tableName, columnNames) => {
48
+ const meta = describeExplorerTable(getExplorerTable(tableName));
49
+ const byName = new Map(meta.columns.map((c) => [c.name, c]));
50
+ return columnNames.map((name) => {
51
+ const col = byName.get(name);
52
+ if (!col) {
53
+ throw new Error(`Unknown column ${name} on table ${tableName}`);
54
+ }
55
+ return col;
56
+ });
57
+ };
58
+ export const primaryKeyColumns = (tableName) => {
59
+ const meta = describeExplorerTable(getExplorerTable(tableName));
60
+ const pks = meta.columns.filter((c) => c.primaryKey);
61
+ if (!pks.length) {
62
+ throw new Error(`Table ${tableName} has no primary key`);
63
+ }
64
+ return pks;
65
+ };
@@ -0,0 +1,64 @@
1
+ import { Database } from 'arangojs';
2
+ import { DocumentCollection, EdgeCollection } from 'arangojs/collections';
3
+ import { Document, DocumentMetadata, Edge, EdgeMetadata, Patch } from 'arangojs/documents';
4
+ import type { Base } from '@openpeepshq/common/types';
5
+ import { type Filter } from '@openpeepshq/arango-querybuilder';
6
+ import type { CollectionInfo, ViewInfo } from './pg/map/queryTypes';
7
+ import type { Mapping, ObjectSort, WithId } from './pg/map';
8
+ import type { PgQueryResult } from './pg/map/types';
9
+ import type { PgDb } from './pg/client';
10
+ import { EdgeDefinitionOptions } from 'arangojs/graphs';
11
+ import { EnsureIndexOptions } from 'arangojs/indexes';
12
+ import { FilterAndTransformOptions, ObjectFilter, UserFunctionDefinition } from './types';
13
+ export declare const addModificationDates: (collection: DocumentCollection) => Promise<void>;
14
+ export declare const addIndices: (collection: DocumentCollection | EdgeCollection, indices: EnsureIndexOptions[]) => Promise<void>;
15
+ export declare const ensureIndexedCollection: <T extends Record<string, unknown>>(db: Database, collectionInfo: CollectionInfo) => Promise<DocumentCollection<Base<T>, T>>;
16
+ export declare const ensureView: (db: Database, viewInfo: ViewInfo) => Promise<import("arangojs/views").View | undefined>;
17
+ export declare const ensureGraph: (db: Database, name: string, edgeDefinitions: EdgeDefinitionOptions[]) => Promise<import("arangojs/graphs").Graph>;
18
+ export declare const ensureFunction: (db: Database, { name, dbFunction }: UserFunctionDefinition) => Promise<void>;
19
+ export declare const createEdge: <T extends object | {} = {}>(collection: EdgeCollection<Base<T>, T>, document: T & EdgeMetadata & {
20
+ id?: string;
21
+ }) => Promise<WithId<Base<T>>>;
22
+ export declare const updateEdge: <T extends Record<string, unknown> & EdgeMetadata>(collection: EdgeCollection<Base<T>>, documentKey: string, document: Patch<Document<Base<T>>>) => Promise<Document<Base<T>> | undefined>;
23
+ export declare const deleteEdge: <T extends Record<string, unknown> & Base<EdgeMetadata>>(collection: EdgeCollection<Base<T>>, documentKey: string) => Promise<DocumentMetadata & {
24
+ old?: Edge<Base<T>> | undefined;
25
+ }>;
26
+ export declare const findOneBy: <O extends object>(db: Database, collectionInfo: CollectionInfo) => (filter: Filter) => Promise<O | undefined>;
27
+ export declare const edgeCollections: (database: Database) => Promise<(DocumentCollection<any, any> & EdgeCollection<any, any>)[]>;
28
+ export declare const connector: <F extends {
29
+ id: string;
30
+ }, T extends {
31
+ id: string;
32
+ }, E extends object | {} = {}>(fromCollectionInfo: CollectionInfo, toCollectionInfo: CollectionInfo, edgeCollectionInfo: CollectionInfo) => (db: PgDb, from: F, to: T, data?: E & {
33
+ id?: string;
34
+ }) => Promise<WithId<E & {
35
+ _from: string;
36
+ _to: string;
37
+ }>>;
38
+ export declare const disconnector: <F extends {
39
+ id: string;
40
+ }, T extends {
41
+ id: string;
42
+ }>(fromCollectionInfo: CollectionInfo, toCollectionInfo: CollectionInfo, edgeCollectionInfo: CollectionInfo) => (db: PgDb, from: F, to: T) => Promise<void>;
43
+ export declare const connectionUpdater: <F extends {
44
+ id: string;
45
+ }, T extends {
46
+ id: string;
47
+ }, C extends Record<string, unknown> | undefined = {}>(fromCollectionInfo: CollectionInfo, toCollectionInfo: CollectionInfo, edgeCollectionInfo: CollectionInfo) => (db: PgDb, from: F, to: T, data?: C) => Promise<void>;
48
+ export declare const connectionFinder: <F extends {
49
+ id: string;
50
+ }, T extends {
51
+ id: string;
52
+ }, C extends Record<string, unknown> = {}>(_fromCollectionInfo: CollectionInfo, _toCollectionInfo: CollectionInfo, edgeCollectionInfo: CollectionInfo) => (db: PgDb, from: F, to: T) => Promise<C | undefined>;
53
+ export declare const filterBefore: <T extends object>(mapping: Mapping<T>, id?: string) => Mapping<T>;
54
+ export declare const filterAfter: <T extends object>(mapping: Mapping<T>, id?: string) => Mapping<T>;
55
+ export declare const addQuerySort: <T extends object>(mapping: Mapping<T>, sort?: ObjectSort) => Mapping<T>;
56
+ export declare const sortNewestFirst: <T extends object>(mapping: Mapping<T>) => Mapping<T, WithId<T>, WithId<T>>;
57
+ export declare const sortOldestFirst: <T extends object>(mapping: Mapping<T>) => Mapping<T, WithId<T>, WithId<T>>;
58
+ export declare const addStartLimit: <T extends object>(mapping: Mapping<T>, start?: string, limit?: number) => Mapping<T>;
59
+ export declare const addStart: <T extends object>(mapping: Mapping<T>, start?: string) => Mapping<T>;
60
+ export declare const filterAndTransform: <I extends object, O extends object = I>(queryResult: PgQueryResult<I>, db: PgDb, options: FilterAndTransformOptions<I, O>) => Promise<O[]>;
61
+ export declare const composeFilters: <O extends object>(...filters: ObjectFilter<O>[]) => ObjectFilter<O>;
62
+ export declare const retrievePaged: <T extends object>(queryResult: PgQueryResult<T>, db: PgDb, options?: {
63
+ limit: number;
64
+ }) => Promise<T[]>;
@@ -0,0 +1,240 @@
1
+ import { CollectionType, } from 'arangojs/collections';
2
+ import { uuidv7 } from 'uuidv7';
3
+ import { collectionElement, query, literal, } from '@openpeepshq/arango-querybuilder';
4
+ import { deleteEdge as deletePgEdge, insertEdge } from './pg/helpers.js';
5
+ import { asTable, edgeRegistry } from './pg/map/registry.js';
6
+ import { nowIso } from './pg/mappers.js';
7
+ import { and, eq } from 'drizzle-orm';
8
+ import { documentKeyAfter, documentKeyBefore } from './pg/filters/index.js';
9
+ import { sorts } from './pg/queries/index.js';
10
+ import { asyncFilter } from '@openpeepshq/common/lib';
11
+ import { logger } from '../log/index.js';
12
+ const log = logger('openpeeps:db');
13
+ const collectionName = (collectionOrName) => typeof collectionOrName === 'string'
14
+ ? collectionOrName
15
+ : collectionOrName.name;
16
+ export const addModificationDates = async (collection) => {
17
+ await collection.properties({
18
+ computedValues: [
19
+ {
20
+ name: 'createdAt',
21
+ expression: 'RETURN DATE_ISO8601(DATE_NOW())',
22
+ computeOn: ['insert'],
23
+ overwrite: false,
24
+ failOnWarning: false,
25
+ keepNull: true,
26
+ },
27
+ {
28
+ name: 'updatedAt',
29
+ expression: 'RETURN DATE_ISO8601(DATE_NOW())',
30
+ computeOn: ['update', 'replace', 'insert'],
31
+ overwrite: false,
32
+ failOnWarning: false,
33
+ keepNull: true,
34
+ },
35
+ ],
36
+ });
37
+ };
38
+ export const addIndices = async (collection, indices) => {
39
+ for (const index of indices) {
40
+ if (!index.name) {
41
+ return;
42
+ }
43
+ try {
44
+ log.info('ensuring index', index.name);
45
+ await collection.ensureIndex(index);
46
+ }
47
+ catch (error) {
48
+ const message = error.message;
49
+ if (message.includes('duplicate value')) {
50
+ log.info('index already exists', index.name);
51
+ log.info('dropping and recreating...');
52
+ await collection.dropIndex(index.name);
53
+ await collection.ensureIndex(index);
54
+ log.info('index recreated');
55
+ }
56
+ else {
57
+ log.error('error ensuring index', index.name, message);
58
+ }
59
+ }
60
+ }
61
+ };
62
+ export const ensureIndexedCollection = async (db, collectionInfo) => {
63
+ var _a;
64
+ const maybeCollection = db.collection(collectionInfo.name);
65
+ const collection = (await maybeCollection.exists())
66
+ ? maybeCollection
67
+ : collectionInfo.edge
68
+ ? await db.createEdgeCollection(collectionInfo.name)
69
+ : await db.createCollection(collectionInfo.name);
70
+ await addModificationDates(collection);
71
+ await addIndices(collection, ((_a = collectionInfo.indices) !== null && _a !== void 0 ? _a : []));
72
+ return collection;
73
+ };
74
+ const isEqualView = (viewInfo1, viewInfo2) => viewInfo1.indexes.length === viewInfo2.indexes.length &&
75
+ viewInfo1.indexes.every((index1) => viewInfo2.indexes.find((index2) => index1.collection === index2.collection &&
76
+ index1.index === index2.index)) &&
77
+ viewInfo2.indexes.every((index2) => viewInfo1.indexes.find((index1) => index1.collection === index2.collection &&
78
+ index1.index === index2.index));
79
+ export const ensureView = async (db, viewInfo) => {
80
+ const view = db.view(viewInfo.name);
81
+ if (await view.exists()) {
82
+ const viewData = await view.properties();
83
+ if (viewData.type === 'search-alias' && isEqualView(viewData, viewInfo)) {
84
+ return view;
85
+ }
86
+ else {
87
+ await view.drop();
88
+ }
89
+ }
90
+ await view.create(viewInfo);
91
+ };
92
+ const replaceEdgeDefinition = (db) => (edgeDefinition) => db
93
+ .listGraphs()
94
+ .then((graphInfos) => graphInfos.map((gi) => gi.edgeDefinitions).flat())
95
+ .then((edgeDefinitions) => edgeDefinitions.find((ed) => ed.collection === edgeDefinition.collection) || edgeDefinition);
96
+ export const ensureGraph = async (db, name, edgeDefinitions) => {
97
+ const replacedEdgeDefinitions = await Promise.all(edgeDefinitions.map(replaceEdgeDefinition(db)));
98
+ const graph = db.graph(name);
99
+ if (await graph.exists()) {
100
+ const edgeDefinitionsToAdd = await asyncFilter(replacedEdgeDefinitions, (ed) => graph
101
+ .listEdgeCollections()
102
+ .then((ecs) => !ecs.includes(collectionName(ed.collection))));
103
+ const edgeDefinitionsToRemove = await graph
104
+ .listEdgeCollections()
105
+ .then((ecs) => ecs.filter((ec) => !replacedEdgeDefinitions
106
+ .map((ed) => collectionName(ed.collection))
107
+ .includes(ec)));
108
+ for (const edgeDefinition of edgeDefinitionsToAdd) {
109
+ await graph.addEdgeDefinition(edgeDefinition);
110
+ }
111
+ for (const edgeDefinitionCollectionName of edgeDefinitionsToRemove) {
112
+ await graph.removeEdgeDefinition(edgeDefinitionCollectionName);
113
+ }
114
+ }
115
+ else {
116
+ return await db.createGraph(name, replacedEdgeDefinitions);
117
+ }
118
+ return graph;
119
+ };
120
+ export const ensureFunction = async (db, { name, dbFunction }) => {
121
+ console.log('--------------------------------');
122
+ console.log('ensureFunction', name);
123
+ console.log('--------------------------------');
124
+ console.log(dbFunction.toString());
125
+ console.log('--------------------------------');
126
+ db.createUserFunction(`ALLPEEP::${name}`, dbFunction.toString(), true);
127
+ };
128
+ const setId = (document) => (Object.assign(Object.assign({}, document), { id: document._key }));
129
+ export const createEdge = async (collection, document) => {
130
+ var _a;
131
+ const data = Object.assign(Object.assign({}, document), { _key: (_a = document.id) !== null && _a !== void 0 ? _a : uuidv7() });
132
+ const createdEdge = (await collection.save(data, { returnNew: true })).new;
133
+ if (createdEdge) {
134
+ return setId(createdEdge);
135
+ }
136
+ else {
137
+ throw Error(`Edge in collection ${collection.name} could not be created.`);
138
+ }
139
+ };
140
+ export const updateEdge = async (collection, documentKey, document) => (await collection.update(documentKey, document, { returnNew: true })).new;
141
+ export const deleteEdge = async (collection, documentKey) => await collection.remove(documentKey);
142
+ export const findOneBy = (db, collectionInfo) => (filter) => query().collection(collectionInfo.name).filter(filter).first(db);
143
+ export const edgeCollections = async (database) => database
144
+ .collections()
145
+ .then((collections) => asyncFilter(collections, async (c) => c.properties().then((p) => p.type === CollectionType.EDGE_COLLECTION)));
146
+ const getEdge = async (db, collection, from, to) => findOneBy(db, collection)({
147
+ name: literal(collectionElement(collection)),
148
+ matches: { _from: from, _to: to },
149
+ });
150
+ const getPgEdge = async (db, edgeCollectionName, fromId, toId) => {
151
+ const edgeConfig = edgeRegistry[edgeCollectionName];
152
+ if (!edgeConfig) {
153
+ throw new Error(`Unknown edge collection: ${edgeCollectionName}`);
154
+ }
155
+ const table = asTable(edgeConfig.table);
156
+ const rows = await db
157
+ .select()
158
+ .from(edgeConfig.table)
159
+ .where(and(eq(table.fromId, fromId), eq(table.toId, toId)))
160
+ .limit(1);
161
+ const row = rows[0];
162
+ if (!row)
163
+ return undefined;
164
+ return Object.assign(Object.assign({}, row.body), { id: row.id, _from: `${edgeConfig.fromCollection}/${row.fromId}`, _to: `${edgeConfig.toCollection}/${row.toId}` });
165
+ };
166
+ export const connector = (fromCollectionInfo, toCollectionInfo, edgeCollectionInfo) => async (db, from, to, data = {}) => {
167
+ const edgeConfig = edgeRegistry[edgeCollectionInfo.name];
168
+ if (!edgeConfig) {
169
+ throw new Error(`Unknown edge collection: ${edgeCollectionInfo.name}`);
170
+ }
171
+ const id = await insertEdge(db, edgeConfig.table, from.id, to.id, data);
172
+ return Object.assign(Object.assign({}, data), { id, _from: `${fromCollectionInfo.name}/${from.id}`, _to: `${toCollectionInfo.name}/${to.id}` });
173
+ };
174
+ export const disconnector = (fromCollectionInfo, toCollectionInfo, edgeCollectionInfo) => async (db, from, to) => {
175
+ const edgeConfig = edgeRegistry[edgeCollectionInfo.name];
176
+ if (!edgeConfig) {
177
+ throw new Error(`Unknown edge collection: ${edgeCollectionInfo.name}`);
178
+ }
179
+ await deletePgEdge(db, edgeConfig.table, from.id, to.id);
180
+ };
181
+ export const connectionUpdater = (fromCollectionInfo, toCollectionInfo, edgeCollectionInfo) => async (db, from, to, data) => {
182
+ const edgeConfig = edgeRegistry[edgeCollectionInfo.name];
183
+ if (!edgeConfig) {
184
+ throw new Error(`Unknown edge collection: ${edgeCollectionInfo.name}`);
185
+ }
186
+ const table = asTable(edgeConfig.table);
187
+ await db
188
+ .update(edgeConfig.table)
189
+ .set({
190
+ body: data !== null && data !== void 0 ? data : {},
191
+ updatedAt: nowIso(),
192
+ })
193
+ .where(and(eq(table.fromId, from.id), eq(table.toId, to.id)));
194
+ };
195
+ export const connectionFinder = (_fromCollectionInfo, _toCollectionInfo, edgeCollectionInfo) => async (db, from, to) => getPgEdge(db, edgeCollectionInfo.name, from.id, to.id);
196
+ export const filterBefore = (mapping, id) => id
197
+ ? mapping.filter(documentKeyBefore(mapping.data().collection, id))
198
+ : mapping;
199
+ export const filterAfter = (mapping, id) => id
200
+ ? mapping.filter(documentKeyAfter(mapping.data().collection, id))
201
+ : mapping;
202
+ export const addQuerySort = (mapping, sort) => ((sort === null || sort === void 0 ? void 0 : sort.length) ? mapping.sort(sort) : mapping);
203
+ export const sortNewestFirst = (mapping) => mapping.sort(sorts.idDesc);
204
+ export const sortOldestFirst = (mapping) => mapping.sort(sorts.idAsc);
205
+ export const addStartLimit = (mapping, start, limit = 100) => filterBefore(sortNewestFirst(mapping.limit(limit)), start);
206
+ export const addStart = (mapping, start) => filterBefore(sortNewestFirst(mapping), start);
207
+ const buildLimit = (limit, offset) => limit && offset ? [offset, limit] : limit;
208
+ export const filterAndTransform = async (queryResult, db, options) => {
209
+ const { filter = (_) => true, transform = async (i) => i, limit = 100, offset = 0, } = options;
210
+ const result = [];
211
+ let pageOffset = 0;
212
+ while (result.length < limit) {
213
+ const nextPageLength = (limit - result.length) * 2;
214
+ const list = await queryResult
215
+ .limit(buildLimit(nextPageLength, offset + pageOffset))
216
+ .all(db);
217
+ const filteredList = await Promise.all(list.map(transform)).then((items) => items.filter(filter));
218
+ result.push(...filteredList.slice(0, limit - result.length));
219
+ if (list.length < nextPageLength) {
220
+ break;
221
+ }
222
+ pageOffset += nextPageLength;
223
+ }
224
+ return result;
225
+ };
226
+ export const composeFilters = (...filters) => (item) => filters.every((filter) => filter(item));
227
+ export const retrievePaged = async (queryResult, db, options = { limit: 100 }) => {
228
+ const { limit } = options;
229
+ const result = [];
230
+ let pageOffset = 0;
231
+ while (true) {
232
+ const list = await queryResult.limit(buildLimit(limit, pageOffset)).all(db);
233
+ result.push(...list);
234
+ if (list.length < limit) {
235
+ break;
236
+ }
237
+ pageOffset += limit;
238
+ }
239
+ return result;
240
+ };
@@ -0,0 +1,13 @@
1
+ import type { PgDb } from './pg/client';
2
+ import { OpenpeepsDatabase } from './types';
3
+ export { empty } from './examples';
4
+ export * from './explorer';
5
+ export { map } from './pg/map';
6
+ export { collectionInfos } from './pg/collections';
7
+ export type { CollectionInfoKey } from './pg/collections';
8
+ export type { PgDb } from './pg/client';
9
+ export type { PgFilter, SqlFilter } from './pg/map/queryTypes';
10
+ export { combine, createdAtBetween, documentKeyAfter, documentKeyBefore, edgeFilters, eventTimeFilters, groupFilters, isSqlFilter, notificationFilters, pgSql, postFilters, profileFilters, } from './pg/filters';
11
+ export { computedFields, sorts } from './pg/queries';
12
+ export declare const allpeepDb: () => Promise<OpenpeepsDatabase>;
13
+ export declare const database: () => Promise<PgDb>;
@@ -0,0 +1,15 @@
1
+ import { initDb } from './init.js';
2
+ export { empty } from './examples.js';
3
+ export * from './explorer/index.js';
4
+ export { map } from './pg/map/index.js';
5
+ export { collectionInfos } from './pg/collections.js';
6
+ export { combine, createdAtBetween, documentKeyAfter, documentKeyBefore, edgeFilters, eventTimeFilters, groupFilters, isSqlFilter, notificationFilters, pgSql, postFilters, profileFilters, } from './pg/filters/index.js';
7
+ export { computedFields, sorts } from './pg/queries/index.js';
8
+ let dbPromise;
9
+ export const allpeepDb = () => {
10
+ if (!dbPromise) {
11
+ dbPromise = initDb();
12
+ }
13
+ return dbPromise;
14
+ };
15
+ export const database = () => allpeepDb().then(({ db }) => db);
@@ -0,0 +1,2 @@
1
+ import { OpenpeepsDatabase } from './types';
2
+ export declare const initDb: () => Promise<OpenpeepsDatabase>;
@@ -0,0 +1,10 @@
1
+ import { logger } from '../log/index.js';
2
+ import { maybeAutoMigrateFromArango } from './migration/autoMigrate.js';
3
+ import { initPostgres } from './pg/client.js';
4
+ const log = logger('openpeeps:db');
5
+ export const initDb = async () => {
6
+ log.info('Initializing Postgres');
7
+ const db = await initPostgres();
8
+ await maybeAutoMigrateFromArango();
9
+ return { db };
10
+ };
@@ -0,0 +1,2 @@
1
+ export declare const autoMigrateFailureMarkerPath: () => string;
2
+ export declare const maybeAutoMigrateFromArango: () => Promise<void>;