@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.
- package/LICENSE +674 -0
- package/dist/accessTokens/finders.d.ts +11 -0
- package/dist/accessTokens/finders.js +43 -0
- package/dist/accessTokens/helpers.d.ts +13 -0
- package/dist/accessTokens/helpers.js +15 -0
- package/dist/accessTokens/index.d.ts +4 -0
- package/dist/accessTokens/index.js +4 -0
- package/dist/accessTokens/mapping.d.ts +10 -0
- package/dist/accessTokens/mapping.js +25 -0
- package/dist/accessTokens/mutations.d.ts +4 -0
- package/dist/accessTokens/mutations.js +24 -0
- package/dist/accessTokens/revokations.d.ts +2 -0
- package/dist/accessTokens/revokations.js +18 -0
- package/dist/accessTokens/tokens.d.ts +31 -0
- package/dist/accessTokens/tokens.js +174 -0
- package/dist/accounts/cache.d.ts +3 -0
- package/dist/accounts/cache.js +13 -0
- package/dist/accounts/finders.d.ts +6 -0
- package/dist/accounts/finders.js +17 -0
- package/dist/accounts/helpers.d.ts +7 -0
- package/dist/accounts/helpers.js +36 -0
- package/dist/accounts/index.d.ts +6 -0
- package/dist/accounts/index.js +6 -0
- package/dist/accounts/mapping.d.ts +10 -0
- package/dist/accounts/mapping.js +28 -0
- package/dist/accounts/mutations.d.ts +21 -0
- package/dist/accounts/mutations.js +204 -0
- package/dist/analytics/cache.d.ts +6 -0
- package/dist/analytics/cache.js +29 -0
- package/dist/analytics/compile.d.ts +4 -0
- package/dist/analytics/compile.js +296 -0
- package/dist/analytics/dateRange.d.ts +39 -0
- package/dist/analytics/dateRange.js +181 -0
- package/dist/analytics/index.d.ts +8 -0
- package/dist/analytics/index.js +8 -0
- package/dist/analytics/jobs.d.ts +20 -0
- package/dist/analytics/jobs.js +84 -0
- package/dist/analytics/metrics.d.ts +4 -0
- package/dist/analytics/metrics.js +13 -0
- package/dist/analytics/pdfReport.d.ts +8 -0
- package/dist/analytics/pdfReport.js +821 -0
- package/dist/analytics/read.d.ts +6 -0
- package/dist/analytics/read.js +696 -0
- package/dist/analytics/report.d.ts +293 -0
- package/dist/analytics/report.js +153 -0
- package/dist/analytics/settings.d.ts +3 -0
- package/dist/analytics/settings.js +37 -0
- package/dist/backups/index.d.ts +5 -0
- package/dist/backups/index.js +260 -0
- package/dist/backups/metadata.d.ts +9 -0
- package/dist/backups/metadata.js +2 -0
- package/dist/config/db.d.ts +7 -0
- package/dist/config/db.js +26 -0
- package/dist/config/defaults/capabilities.d.ts +2 -0
- package/dist/config/defaults/capabilities.js +47 -0
- package/dist/config/defaults/community.d.ts +2 -0
- package/dist/config/defaults/community.js +41 -0
- package/dist/config/defaults/core.d.ts +2 -0
- package/dist/config/defaults/core.js +113 -0
- package/dist/config/defaults/db.d.ts +6 -0
- package/dist/config/defaults/db.js +8 -0
- package/dist/config/defaults/logs.d.ts +6 -0
- package/dist/config/defaults/logs.js +7 -0
- package/dist/config/defaults/redis.d.ts +4 -0
- package/dist/config/defaults/redis.js +5 -0
- package/dist/config/helpers.d.ts +11 -0
- package/dist/config/helpers.js +31 -0
- package/dist/config/index.d.ts +392 -0
- package/dist/config/index.js +83 -0
- package/dist/config/pruneEmptyConfigStrings.d.ts +7 -0
- package/dist/config/pruneEmptyConfigStrings.js +29 -0
- package/dist/db/aql.d.ts +0 -0
- package/dist/db/aql.js +1 -0
- package/dist/db/arango.d.ts +2 -0
- package/dist/db/arango.js +110 -0
- package/dist/db/bootMigrate.d.ts +1 -0
- package/dist/db/bootMigrate.js +15 -0
- package/dist/db/examples.d.ts +1 -0
- package/dist/db/examples.js +13 -0
- package/dist/db/explorer/csv.d.ts +1 -0
- package/dist/db/explorer/csv.js +18 -0
- package/dist/db/explorer/index.d.ts +6 -0
- package/dist/db/explorer/index.js +5 -0
- package/dist/db/explorer/mutate.d.ts +6 -0
- package/dist/db/explorer/mutate.js +66 -0
- package/dist/db/explorer/query.d.ts +17 -0
- package/dist/db/explorer/query.js +48 -0
- package/dist/db/explorer/sql.d.ts +11 -0
- package/dist/db/explorer/sql.js +42 -0
- package/dist/db/explorer/tables.d.ts +9 -0
- package/dist/db/explorer/tables.js +65 -0
- package/dist/db/helpers.d.ts +64 -0
- package/dist/db/helpers.js +240 -0
- package/dist/db/index.d.ts +13 -0
- package/dist/db/index.js +15 -0
- package/dist/db/init.d.ts +2 -0
- package/dist/db/init.js +10 -0
- package/dist/db/migration/autoMigrate.d.ts +2 -0
- package/dist/db/migration/autoMigrate.js +111 -0
- package/dist/db/migration/cli.d.ts +1 -0
- package/dist/db/migration/cli.js +56 -0
- package/dist/db/migration/detect.d.ts +6 -0
- package/dist/db/migration/detect.js +87 -0
- package/dist/db/migration/exportArango.d.ts +4 -0
- package/dist/db/migration/exportArango.js +80 -0
- package/dist/db/migration/importCollections.d.ts +19 -0
- package/dist/db/migration/importCollections.js +280 -0
- package/dist/db/migration/importPostgres.d.ts +3 -0
- package/dist/db/migration/importPostgres.js +18 -0
- package/dist/db/migration/shared.d.ts +39 -0
- package/dist/db/migration/shared.js +158 -0
- package/dist/db/migration/transform.d.ts +18 -0
- package/dist/db/migration/transform.js +209 -0
- package/dist/db/migration/validate.d.ts +18 -0
- package/dist/db/migration/validate.js +69 -0
- package/dist/db/pg/client.d.ts +35 -0
- package/dist/db/pg/client.js +126 -0
- package/dist/db/pg/collections.d.ts +48 -0
- package/dist/db/pg/collections.js +53 -0
- package/dist/db/pg/filters/common.d.ts +21 -0
- package/dist/db/pg/filters/common.js +48 -0
- package/dist/db/pg/filters/edges.d.ts +9 -0
- package/dist/db/pg/filters/edges.js +10 -0
- package/dist/db/pg/filters/groups.d.ts +7 -0
- package/dist/db/pg/filters/groups.js +15 -0
- package/dist/db/pg/filters/index.d.ts +22 -0
- package/dist/db/pg/filters/index.js +35 -0
- package/dist/db/pg/filters/notifications.d.ts +6 -0
- package/dist/db/pg/filters/notifications.js +10 -0
- package/dist/db/pg/filters/posts.d.ts +18 -0
- package/dist/db/pg/filters/posts.js +25 -0
- package/dist/db/pg/filters/profiles.d.ts +6 -0
- package/dist/db/pg/filters/profiles.js +9 -0
- package/dist/db/pg/filters/types.d.ts +7 -0
- package/dist/db/pg/filters/types.js +5 -0
- package/dist/db/pg/helpers.d.ts +19 -0
- package/dist/db/pg/helpers.js +67 -0
- package/dist/db/pg/map/filters.d.ts +22 -0
- package/dist/db/pg/map/filters.js +566 -0
- package/dist/db/pg/map/helpers.d.ts +2 -0
- package/dist/db/pg/map/helpers.js +2 -0
- package/dist/db/pg/map/index.d.ts +46 -0
- package/dist/db/pg/map/index.js +93 -0
- package/dist/db/pg/map/mutations.d.ts +11 -0
- package/dist/db/pg/map/mutations.js +135 -0
- package/dist/db/pg/map/queryTypes.d.ts +115 -0
- package/dist/db/pg/map/queryTypes.js +1 -0
- package/dist/db/pg/map/registry.d.ts +29 -0
- package/dist/db/pg/map/registry.js +413 -0
- package/dist/db/pg/map/relations.d.ts +28 -0
- package/dist/db/pg/map/relations.js +399 -0
- package/dist/db/pg/map/search.d.ts +6 -0
- package/dist/db/pg/map/search.js +190 -0
- package/dist/db/pg/map/types.d.ts +11 -0
- package/dist/db/pg/map/types.js +1 -0
- package/dist/db/pg/mappers.d.ts +28 -0
- package/dist/db/pg/mappers.js +29 -0
- package/dist/db/pg/migrate.d.ts +14 -0
- package/dist/db/pg/migrate.js +134 -0
- package/dist/db/pg/queries/activity.d.ts +10 -0
- package/dist/db/pg/queries/activity.js +47 -0
- package/dist/db/pg/queries/computed.d.ts +7 -0
- package/dist/db/pg/queries/computed.js +19 -0
- package/dist/db/pg/queries/derived.d.ts +22 -0
- package/dist/db/pg/queries/derived.js +100 -0
- package/dist/db/pg/queries/index.d.ts +4 -0
- package/dist/db/pg/queries/index.js +4 -0
- package/dist/db/pg/queries/sorts.d.ts +10 -0
- package/dist/db/pg/queries/sorts.js +9 -0
- package/dist/db/pg/schema/analytics.d.ts +998 -0
- package/dist/db/pg/schema/analytics.js +110 -0
- package/dist/db/pg/schema/base.d.ts +36 -0
- package/dist/db/pg/schema/base.js +23 -0
- package/dist/db/pg/schema/documents.d.ts +2002 -0
- package/dist/db/pg/schema/documents.js +40 -0
- package/dist/db/pg/schema/edges.d.ts +2725 -0
- package/dist/db/pg/schema/edges.js +34 -0
- package/dist/db/pg/schema/index.d.ts +5724 -0
- package/dist/db/pg/schema/index.js +7 -0
- package/dist/db/pg/sql/0000_bizarre_chat.sql +456 -0
- package/dist/db/pg/sql/0001_search_vector.sql +122 -0
- package/dist/db/pg/sql/0002_data_migrations_id_text.sql +1 -0
- package/dist/db/pg/sql/0003_fix_group_post_visibility.sql +4 -0
- package/dist/db/pg/sql/0004_analytics.sql +90 -0
- package/dist/db/pg/sql/meta/0000_snapshot.json +3380 -0
- package/dist/db/pg/sql/meta/0004_snapshot.json +4114 -0
- package/dist/db/pg/sql/meta/_journal.json +41 -0
- package/dist/db/replaceHostname.d.ts +1 -0
- package/dist/db/replaceHostname.js +88 -0
- package/dist/db/types.d.ts +17 -0
- package/dist/db/types.js +1 -0
- package/dist/email/index.d.ts +9 -0
- package/dist/email/index.js +19 -0
- package/dist/email/jobs.d.ts +3 -0
- package/dist/email/jobs.js +13 -0
- package/dist/email/queueStats.d.ts +2 -0
- package/dist/email/queueStats.js +27 -0
- package/dist/email/registry.d.ts +3 -0
- package/dist/email/registry.js +4 -0
- package/dist/email/render.d.ts +8 -0
- package/dist/email/render.js +34 -0
- package/dist/email/send.d.ts +9 -0
- package/dist/email/send.js +97 -0
- package/dist/email/smtpTest.d.ts +2 -0
- package/dist/email/smtpTest.js +26 -0
- package/dist/errors/index.d.ts +8 -0
- package/dist/errors/index.js +13 -0
- package/dist/events/index.d.ts +31 -0
- package/dist/events/index.js +66 -0
- package/dist/events/once.d.ts +4 -0
- package/dist/events/once.js +23 -0
- package/dist/groups/finders.d.ts +125 -0
- package/dist/groups/finders.js +18 -0
- package/dist/groups/helpers.d.ts +227 -0
- package/dist/groups/helpers.js +17 -0
- package/dist/groups/index.d.ts +3 -0
- package/dist/groups/index.js +3 -0
- package/dist/groups/mapping.d.ts +188 -0
- package/dist/groups/mapping.js +47 -0
- package/dist/groups/mutations.d.ts +26 -0
- package/dist/groups/mutations.js +41 -0
- package/dist/hashtags/finders.d.ts +3 -0
- package/dist/hashtags/finders.js +22 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mapping.d.ts +4 -0
- package/dist/hashtags/mapping.js +5 -0
- package/dist/hashtags/mutations.d.ts +0 -0
- package/dist/hashtags/mutations.js +1 -0
- package/dist/i18n/index.d.ts +14 -0
- package/dist/i18n/index.js +53 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +1 -0
- package/dist/inviteLinks/finders.d.ts +3 -0
- package/dist/inviteLinks/finders.js +5 -0
- package/dist/inviteLinks/helpers.d.ts +20 -0
- package/dist/inviteLinks/helpers.js +4 -0
- package/dist/inviteLinks/index.d.ts +3 -0
- package/dist/inviteLinks/index.js +3 -0
- package/dist/inviteLinks/mapping.d.ts +10 -0
- package/dist/inviteLinks/mapping.js +35 -0
- package/dist/inviteLinks/mutations.d.ts +4 -0
- package/dist/inviteLinks/mutations.js +39 -0
- package/dist/jams/cache.d.ts +9 -0
- package/dist/jams/cache.js +13 -0
- package/dist/jams/finders.d.ts +23 -0
- package/dist/jams/finders.js +24 -0
- package/dist/jams/helpers.d.ts +70 -0
- package/dist/jams/helpers.js +29 -0
- package/dist/jams/index.d.ts +15 -0
- package/dist/jams/index.js +108 -0
- package/dist/jams/jobs.d.ts +9 -0
- package/dist/jams/jobs.js +42 -0
- package/dist/jams/livekit.d.ts +24 -0
- package/dist/jams/livekit.js +220 -0
- package/dist/jams/mapping.d.ts +137 -0
- package/dist/jams/mapping.js +35 -0
- package/dist/jams/mutations.d.ts +40 -0
- package/dist/jams/mutations.js +4 -0
- package/dist/jams/recording.d.ts +8 -0
- package/dist/jams/recording.js +67 -0
- package/dist/jams/recordingUploadAuth.d.ts +9 -0
- package/dist/jams/recordingUploadAuth.js +19 -0
- package/dist/jams/token.d.ts +4 -0
- package/dist/jams/token.js +129 -0
- package/dist/jams/waitingRoom.d.ts +5 -0
- package/dist/jams/waitingRoom.js +71 -0
- package/dist/jobs/index.d.ts +10 -0
- package/dist/jobs/index.js +60 -0
- package/dist/jobs/jobDetail.d.ts +2 -0
- package/dist/jobs/jobDetail.js +31 -0
- package/dist/jobs/jobLog.d.ts +18 -0
- package/dist/jobs/jobLog.js +61 -0
- package/dist/jwt/index.d.ts +10 -0
- package/dist/jwt/index.js +43 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/streams.d.ts +2 -0
- package/dist/lib/streams.js +56 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +17 -0
- package/dist/lib/zodDeepPartial.d.ts +3 -0
- package/dist/lib/zodDeepPartial.js +26 -0
- package/dist/location/index.d.ts +2 -0
- package/dist/location/index.js +28 -0
- package/dist/log/index.d.ts +3 -0
- package/dist/log/index.js +97 -0
- package/dist/mastodon/index.d.ts +4 -0
- package/dist/mastodon/index.js +51 -0
- package/dist/mastodon/types.d.ts +7579 -0
- package/dist/mastodon/types.js +523 -0
- package/dist/mastodon/typescript.d.ts +1578 -0
- package/dist/mastodon/typescript.js +1 -0
- package/dist/media/index.d.ts +40 -0
- package/dist/media/index.js +248 -0
- package/dist/media/ipfs/index.d.ts +0 -0
- package/dist/media/ipfs/index.js +39 -0
- package/dist/media/jobs.d.ts +19 -0
- package/dist/media/jobs.js +90 -0
- package/dist/media/openpeeps/index.d.ts +3 -0
- package/dist/media/openpeeps/index.js +131 -0
- package/dist/media/processing.d.ts +19 -0
- package/dist/media/processing.js +83 -0
- package/dist/media/streaming.d.ts +77 -0
- package/dist/media/streaming.js +257 -0
- package/dist/media/streamingCleanupJobs.d.ts +14 -0
- package/dist/media/streamingCleanupJobs.js +47 -0
- package/dist/media/streamingJobs.d.ts +5 -0
- package/dist/media/streamingJobs.js +329 -0
- package/dist/media/streamingPrewarm.d.ts +36 -0
- package/dist/media/streamingPrewarm.js +109 -0
- package/dist/mediaAttachments/finders.d.ts +1 -0
- package/dist/mediaAttachments/finders.js +3 -0
- package/dist/mediaAttachments/index.d.ts +5 -0
- package/dist/mediaAttachments/index.js +12 -0
- package/dist/mediaAttachments/mapping.d.ts +21 -0
- package/dist/mediaAttachments/mapping.js +4 -0
- package/dist/mediaAttachments/mutations.d.ts +3 -0
- package/dist/mediaAttachments/mutations.js +10 -0
- package/dist/notifications/defaultNotifications/announcement/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/announcement/index.js +42 -0
- package/dist/notifications/defaultNotifications/directMessage/index.d.ts +28 -0
- package/dist/notifications/defaultNotifications/directMessage/index.js +69 -0
- package/dist/notifications/defaultNotifications/follow/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/follow/index.js +31 -0
- package/dist/notifications/defaultNotifications/groupAdded/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupAdded/index.js +33 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +36 -0
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +36 -0
- package/dist/notifications/defaultNotifications/index.d.ts +3 -0
- package/dist/notifications/defaultNotifications/index.js +43 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.d.ts +23 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +49 -0
- package/dist/notifications/defaultNotifications/jamSpeaker/index.d.ts +23 -0
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +47 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.js +82 -0
- package/dist/notifications/defaultNotifications/mention/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/mention/index.js +89 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +47 -0
- package/dist/notifications/defaultNotifications/newProfile/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/newProfile/index.js +40 -0
- package/dist/notifications/defaultNotifications/pollVote/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +40 -0
- package/dist/notifications/defaultNotifications/reaction/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/reaction/index.js +43 -0
- package/dist/notifications/defaultNotifications/reply/index.d.ts +25 -0
- package/dist/notifications/defaultNotifications/reply/index.js +57 -0
- package/dist/notifications/defaultNotifications/repost/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/repost/index.js +42 -0
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/rsvp/index.js +40 -0
- package/dist/notifications/fcmCredential.d.ts +14 -0
- package/dist/notifications/fcmCredential.js +68 -0
- package/dist/notifications/finders.d.ts +7 -0
- package/dist/notifications/finders.js +13 -0
- package/dist/notifications/firebase.d.ts +1 -0
- package/dist/notifications/firebase.js +33 -0
- package/dist/notifications/handlers.d.ts +3 -0
- package/dist/notifications/handlers.js +6 -0
- package/dist/notifications/helpers.d.ts +7 -0
- package/dist/notifications/helpers.js +31 -0
- package/dist/notifications/index.d.ts +9 -0
- package/dist/notifications/index.js +43 -0
- package/dist/notifications/jobs.d.ts +2 -0
- package/dist/notifications/jobs.js +75 -0
- package/dist/notifications/mapping.d.ts +25 -0
- package/dist/notifications/mapping.js +25 -0
- package/dist/notifications/mutations.d.ts +6 -0
- package/dist/notifications/mutations.js +40 -0
- package/dist/notifications/push.d.ts +9 -0
- package/dist/notifications/push.js +261 -0
- package/dist/notifications/pushInvalidation.d.ts +10 -0
- package/dist/notifications/pushInvalidation.js +10 -0
- package/dist/performance/index.d.ts +24 -0
- package/dist/performance/index.js +61 -0
- package/dist/plugins/helpers.d.ts +3 -0
- package/dist/plugins/helpers.js +72 -0
- package/dist/plugins/index.d.ts +10 -0
- package/dist/plugins/index.js +84 -0
- package/dist/plugins/pluginAuth.d.ts +30 -0
- package/dist/plugins/pluginAuth.js +44 -0
- package/dist/posts/contextClosure.d.ts +16 -0
- package/dist/posts/contextClosure.js +66 -0
- package/dist/posts/finders.d.ts +298 -0
- package/dist/posts/finders.js +259 -0
- package/dist/posts/helpers/filters.d.ts +14 -0
- package/dist/posts/helpers/filters.js +39 -0
- package/dist/posts/helpers/index.d.ts +837 -0
- package/dist/posts/helpers/index.js +117 -0
- package/dist/posts/index.d.ts +6 -0
- package/dist/posts/index.js +6 -0
- package/dist/posts/mapping.d.ts +2187 -0
- package/dist/posts/mapping.js +222 -0
- package/dist/posts/mutations.d.ts +19 -0
- package/dist/posts/mutations.js +202 -0
- package/dist/posts/rsvpConfirmationEmail.d.ts +2 -0
- package/dist/posts/rsvpConfirmationEmail.js +82 -0
- package/dist/processingStats/index.d.ts +3 -0
- package/dist/processingStats/index.js +3 -0
- package/dist/processingStats/mapping.d.ts +7 -0
- package/dist/processingStats/mapping.js +4 -0
- package/dist/processingStats/mutations.d.ts +2 -0
- package/dist/processingStats/mutations.js +6 -0
- package/dist/processingStats/queries.d.ts +4 -0
- package/dist/processingStats/queries.js +46 -0
- package/dist/profileSettings/cache.d.ts +2 -0
- package/dist/profileSettings/cache.js +24 -0
- package/dist/profileSettings/finders.d.ts +1 -0
- package/dist/profileSettings/finders.js +2 -0
- package/dist/profileSettings/index.d.ts +3 -0
- package/dist/profileSettings/index.js +3 -0
- package/dist/profileSettings/mapping.d.ts +38 -0
- package/dist/profileSettings/mapping.js +5 -0
- package/dist/profileSettings/mutations.d.ts +3 -0
- package/dist/profileSettings/mutations.js +24 -0
- package/dist/profiles/cache.d.ts +5 -0
- package/dist/profiles/cache.js +19 -0
- package/dist/profiles/capacity.d.ts +2 -0
- package/dist/profiles/capacity.js +20 -0
- package/dist/profiles/export.d.ts +3 -0
- package/dist/profiles/export.js +85 -0
- package/dist/profiles/finders.d.ts +11 -0
- package/dist/profiles/finders.js +39 -0
- package/dist/profiles/helpers.d.ts +35 -0
- package/dist/profiles/helpers.js +10 -0
- package/dist/profiles/index.d.ts +5 -0
- package/dist/profiles/index.js +18 -0
- package/dist/profiles/mapping.d.ts +157 -0
- package/dist/profiles/mapping.js +132 -0
- package/dist/profiles/mutations.d.ts +9 -0
- package/dist/profiles/mutations.js +75 -0
- package/dist/pushSubscriptions/finders.d.ts +187 -0
- package/dist/pushSubscriptions/finders.js +6 -0
- package/dist/pushSubscriptions/helpers.d.ts +99 -0
- package/dist/pushSubscriptions/helpers.js +3 -0
- package/dist/pushSubscriptions/index.d.ts +3 -0
- package/dist/pushSubscriptions/index.js +3 -0
- package/dist/pushSubscriptions/mapping.d.ts +261 -0
- package/dist/pushSubscriptions/mapping.js +6 -0
- package/dist/pushSubscriptions/mutations.d.ts +95 -0
- package/dist/pushSubscriptions/mutations.js +21 -0
- package/dist/redis/connection.d.ts +4 -0
- package/dist/redis/connection.js +17 -0
- package/dist/redis/index.d.ts +1 -0
- package/dist/redis/index.js +1 -0
- package/dist/reports/finders.d.ts +6 -0
- package/dist/reports/finders.js +44 -0
- package/dist/reports/helpers.d.ts +21 -0
- package/dist/reports/helpers.js +12 -0
- package/dist/reports/index.d.ts +3 -0
- package/dist/reports/index.js +3 -0
- package/dist/reports/mapping.d.ts +9 -0
- package/dist/reports/mapping.js +34 -0
- package/dist/reports/mutations.d.ts +5 -0
- package/dist/reports/mutations.js +16 -0
- package/dist/roles/defaults.d.ts +2 -0
- package/dist/roles/defaults.js +94 -0
- package/dist/roles/finders.d.ts +5 -0
- package/dist/roles/finders.js +9 -0
- package/dist/roles/index.d.ts +4 -0
- package/dist/roles/index.js +4 -0
- package/dist/roles/mapping.d.ts +11 -0
- package/dist/roles/mapping.js +5 -0
- package/dist/roles/mutations.d.ts +4 -0
- package/dist/roles/mutations.js +30 -0
- package/dist/search/finders.d.ts +47 -0
- package/dist/search/finders.js +59 -0
- package/dist/search/helpers.d.ts +3 -0
- package/dist/search/helpers.js +1 -0
- package/dist/search/index.d.ts +1 -0
- package/dist/search/index.js +1 -0
- package/dist/search/mapping.d.ts +40 -0
- package/dist/search/mapping.js +43 -0
- package/dist/sentry/index.d.ts +34 -0
- package/dist/sentry/index.js +113 -0
- package/dist/server/helpers.d.ts +0 -0
- package/dist/server/helpers.js +1 -0
- package/dist/server/index.d.ts +105 -0
- package/dist/server/index.js +64 -0
- package/dist/stats/finders.d.ts +16156 -0
- package/dist/stats/finders.js +167 -0
- package/dist/stats/helpers.d.ts +17 -0
- package/dist/stats/helpers.js +34 -0
- package/dist/stats/index.d.ts +1 -0
- package/dist/stats/index.js +1 -0
- package/dist/stats/mapping.d.ts +188 -0
- package/dist/stats/mapping.js +19 -0
- package/dist/stripe/cache.d.ts +30 -0
- package/dist/stripe/cache.js +37 -0
- package/dist/stripe/connection.d.ts +5 -0
- package/dist/stripe/connection.js +23 -0
- package/dist/stripe/helpers.d.ts +25 -0
- package/dist/stripe/helpers.js +211 -0
- package/dist/stripe/index.d.ts +3 -0
- package/dist/stripe/index.js +3 -0
- package/package.json +99 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/node';
|
|
2
|
+
import { logger } from '../log/index.js';
|
|
3
|
+
const log = logger('openpeeps:performance');
|
|
4
|
+
const envInt = (name, fallback) => {
|
|
5
|
+
const raw = process.env[name];
|
|
6
|
+
if (raw === undefined || raw === '')
|
|
7
|
+
return fallback;
|
|
8
|
+
const n = Number(raw);
|
|
9
|
+
return Number.isFinite(n) ? n : fallback;
|
|
10
|
+
};
|
|
11
|
+
export const slowRequestMs = () => envInt('PERF_SLOW_REQUEST_MS', 1000);
|
|
12
|
+
export const slowQueryMs = () => envInt('PERF_SLOW_QUERY_MS', 200);
|
|
13
|
+
export const slowSpanMs = () => envInt('PERF_SLOW_SPAN_MS', 250);
|
|
14
|
+
export const dbTimingEnabled = () => process.env.PERF_DB_TIMING === '1' || process.env.PERF_DB_TIMING === 'true';
|
|
15
|
+
const SLOW_REQUEST_BUFFER_SIZE = 100;
|
|
16
|
+
const slowRequests = [];
|
|
17
|
+
export const recordSlowRequest = (record) => {
|
|
18
|
+
slowRequests.unshift(Object.assign(Object.assign({}, record), { at: new Date().toISOString() }));
|
|
19
|
+
if (slowRequests.length > SLOW_REQUEST_BUFFER_SIZE) {
|
|
20
|
+
slowRequests.length = SLOW_REQUEST_BUFFER_SIZE;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export const getSlowRequests = () => [...slowRequests];
|
|
24
|
+
export const clearSlowRequests = () => {
|
|
25
|
+
slowRequests.length = 0;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Time an async operation. Logs when over PERF_SLOW_SPAN_MS and creates a
|
|
29
|
+
* Sentry child span when the SDK is initialized (no-ops otherwise).
|
|
30
|
+
*/
|
|
31
|
+
export const withSpan = async (name, fn, attributes) => Sentry.startSpan({ name, op: 'openpeeps', attributes }, async () => {
|
|
32
|
+
const start = performance.now();
|
|
33
|
+
try {
|
|
34
|
+
return await fn();
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
const durationMs = performance.now() - start;
|
|
38
|
+
if (durationMs >= slowSpanMs()) {
|
|
39
|
+
log.warn(Object.assign({ name, durationMs }, attributes), 'slow span');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
/** Legacy wrapper — prefer {@link withSpan} for named spans. */
|
|
44
|
+
export const logTime = (fn, category) => (async (...args) => withSpan(category, () => fn(...args)));
|
|
45
|
+
export const truncateSql = (sqlText, max = 240) => {
|
|
46
|
+
if (typeof sqlText !== 'string') {
|
|
47
|
+
if (sqlText && typeof sqlText === 'object' && 'text' in sqlText) {
|
|
48
|
+
return truncateSql(sqlText.text, max);
|
|
49
|
+
}
|
|
50
|
+
return String(sqlText !== null && sqlText !== void 0 ? sqlText : '');
|
|
51
|
+
}
|
|
52
|
+
const compact = sqlText.replace(/\s+/g, ' ').trim();
|
|
53
|
+
return compact.length > max ? `${compact.slice(0, max)}…` : compact;
|
|
54
|
+
};
|
|
55
|
+
export const maybeLogSlowQuery = (sqlText, durationMs) => {
|
|
56
|
+
if (!dbTimingEnabled())
|
|
57
|
+
return;
|
|
58
|
+
if (durationMs < slowQueryMs())
|
|
59
|
+
return;
|
|
60
|
+
log.warn({ durationMs, sql: truncateSql(sqlText) }, 'slow postgres query');
|
|
61
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { logger } from '../log/index.js';
|
|
4
|
+
const log = logger('core:plugins');
|
|
5
|
+
const isPluginEnabled = (info) => {
|
|
6
|
+
var _a;
|
|
7
|
+
return ((_a = info.openpeeps) === null || _a === void 0 ? void 0 : _a.enabled) !== false;
|
|
8
|
+
};
|
|
9
|
+
export const sortByDependencies = (pluginInfos) => {
|
|
10
|
+
const pluginKeys = pluginInfos.map(([key]) => key);
|
|
11
|
+
const packageNameToKey = new Map(pluginInfos
|
|
12
|
+
.filter(([, info]) => typeof info.name === 'string')
|
|
13
|
+
.map(([key, info]) => [info.name, key]));
|
|
14
|
+
const resolvePluginDependencyKey = (dependencyKey) => {
|
|
15
|
+
if (pluginKeys.includes(dependencyKey)) {
|
|
16
|
+
return dependencyKey;
|
|
17
|
+
}
|
|
18
|
+
return packageNameToKey.get(dependencyKey);
|
|
19
|
+
};
|
|
20
|
+
let addedPluginInfos = [];
|
|
21
|
+
let pluginInfosToAdd = pluginInfos;
|
|
22
|
+
do {
|
|
23
|
+
const addedPluginKeys = addedPluginInfos.map(([key]) => key);
|
|
24
|
+
if (pluginInfosToAdd.length === 0) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
const addablePluginInfos = pluginInfosToAdd.filter(([, info]) => Object.keys(info.dependencies || {}).every((dependencyKey) => {
|
|
28
|
+
const pluginDependencyKey = resolvePluginDependencyKey(dependencyKey);
|
|
29
|
+
return (pluginDependencyKey === undefined ||
|
|
30
|
+
addedPluginKeys.includes(pluginDependencyKey));
|
|
31
|
+
}));
|
|
32
|
+
if (addablePluginInfos.length === 0) {
|
|
33
|
+
log.error(`Dependency cycle or unresolved dependency detected. The following plugins could not be loaded: ${pluginInfosToAdd
|
|
34
|
+
.map(([key]) => key)
|
|
35
|
+
.join(', ')}`);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
addedPluginInfos = addedPluginInfos.concat(addablePluginInfos);
|
|
39
|
+
pluginInfosToAdd = pluginInfos.filter(([key]) => !addedPluginInfos.map(([key]) => key).includes(key));
|
|
40
|
+
} while (pluginInfosToAdd.length > 0);
|
|
41
|
+
return addedPluginInfos;
|
|
42
|
+
};
|
|
43
|
+
const enumeratePluginsForNamespace = (pluginsPath, namespace) => {
|
|
44
|
+
return fs
|
|
45
|
+
.readdirSync(path.join(pluginsPath, namespace))
|
|
46
|
+
.filter((pluginName) => fs.lstatSync(path.join(pluginsPath, namespace, pluginName)).isDirectory())
|
|
47
|
+
.map((name) => {
|
|
48
|
+
const key = path.join(namespace, name);
|
|
49
|
+
const info = JSON.parse(fs.readFileSync(path.join(path.join(pluginsPath, key), 'package.json'), 'utf-8'));
|
|
50
|
+
return [key, info];
|
|
51
|
+
})
|
|
52
|
+
.filter(([key, info]) => {
|
|
53
|
+
if (isPluginEnabled(info)) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
log.info(`Skipping disabled plugin ${key}.`);
|
|
57
|
+
return false;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
export const enumeratePluginInfos = async (pluginsPath) => {
|
|
61
|
+
if (fs.existsSync(pluginsPath)) {
|
|
62
|
+
const namespaces = fs
|
|
63
|
+
.readdirSync(pluginsPath)
|
|
64
|
+
.filter((namespace) => fs.lstatSync(path.join(pluginsPath, namespace)).isDirectory());
|
|
65
|
+
return namespaces
|
|
66
|
+
.map((namespace) => enumeratePluginsForNamespace(pluginsPath, namespace))
|
|
67
|
+
.flat();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PackageJson } from 'type-fest';
|
|
2
|
+
import type { Plugin, PluginManifest } from '@openpeepshq/common';
|
|
3
|
+
export * from './pluginAuth';
|
|
4
|
+
export declare const getPlugins: () => Plugin[];
|
|
5
|
+
export declare const getPluginModule: (key: string) => unknown | undefined;
|
|
6
|
+
export declare const getPluginManifests: () => Record<string, PluginManifest>;
|
|
7
|
+
export declare const initializePlugins: () => Promise<{
|
|
8
|
+
[k: string]: Plugin;
|
|
9
|
+
} | undefined>;
|
|
10
|
+
export declare const sortedPluginInfos: () => Promise<[string, PackageJson][]>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { hub, VALID_EVENT_KEYS } from '../events/index.js';
|
|
3
|
+
import { defaultConfig, registerConfigSchema } from '../config/index.js';
|
|
4
|
+
import { pluginManifestSchema } from '@openpeepshq/common';
|
|
5
|
+
import { enumeratePluginInfos, sortByDependencies } from './helpers.js';
|
|
6
|
+
import { logger } from '../log/index.js';
|
|
7
|
+
export * from './pluginAuth.js';
|
|
8
|
+
const log = logger('core:plugins');
|
|
9
|
+
let initialized = false;
|
|
10
|
+
const loadedPlugins = new Map();
|
|
11
|
+
const loadedModules = new Map();
|
|
12
|
+
const pluginManifests = new Map();
|
|
13
|
+
export const getPlugins = () => Array.from(loadedPlugins.values());
|
|
14
|
+
export const getPluginModule = (key) => loadedModules.get(key);
|
|
15
|
+
export const getPluginManifests = () => Object.fromEntries(pluginManifests.entries());
|
|
16
|
+
export const initializePlugins = async () => {
|
|
17
|
+
if (initialized) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { plugins: { path: pluginsPath }, } = await defaultConfig;
|
|
21
|
+
const loadPlugin = async (pluginsPath, key, info) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const [namespace, name] = key.split('/');
|
|
24
|
+
const pluginPath = path.join(pluginsPath, key);
|
|
25
|
+
const displayName = typeof ((_a = info === null || info === void 0 ? void 0 : info.config) === null || _a === void 0 ? void 0 : _a.displayName) === 'string'
|
|
26
|
+
? info.config.displayName
|
|
27
|
+
: key;
|
|
28
|
+
log.info(`Loading plugin "${displayName}" (key: ${key}) from path ${pluginPath}.`);
|
|
29
|
+
const plugin = {
|
|
30
|
+
key,
|
|
31
|
+
namespace,
|
|
32
|
+
name,
|
|
33
|
+
info,
|
|
34
|
+
path: pluginPath,
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
const pluginModule = await import(
|
|
38
|
+
/* @vite-ignore */ `${pluginPath}/dist/index.js`);
|
|
39
|
+
loadedModules.set(key, pluginModule);
|
|
40
|
+
if ('interceptors' in pluginModule) {
|
|
41
|
+
const interceptors = await pluginModule.interceptors();
|
|
42
|
+
for (const [eventKey, handler] of Object.entries(interceptors)) {
|
|
43
|
+
if (!VALID_EVENT_KEYS.includes(eventKey)) {
|
|
44
|
+
log.warn(`${plugin.key} registered handler for unknown event ${eventKey}. Skipping.`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
log.info(`${plugin.key} listening for event ${eventKey}`);
|
|
48
|
+
hub.on(eventKey, async (...args) => {
|
|
49
|
+
try {
|
|
50
|
+
await handler(...args);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
log.error(e, `${plugin.key} handler for event ${eventKey} failed.`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if ('configSchema' in pluginModule) {
|
|
59
|
+
registerConfigSchema(namespace, name, pluginModule.configSchema.schema, pluginModule.configSchema.defaults);
|
|
60
|
+
}
|
|
61
|
+
if ('manifest' in pluginModule) {
|
|
62
|
+
pluginManifests.set(key, pluginManifestSchema.parse(pluginModule.manifest));
|
|
63
|
+
}
|
|
64
|
+
plugin.status = 'loaded';
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
68
|
+
log.error(e, `Failed to load plugin ${key}.`);
|
|
69
|
+
plugin.status = 'failed';
|
|
70
|
+
plugin.error = message;
|
|
71
|
+
}
|
|
72
|
+
loadedPlugins.set(key, plugin);
|
|
73
|
+
};
|
|
74
|
+
const sortedInfos = sortByDependencies(await enumeratePluginInfos(pluginsPath));
|
|
75
|
+
for (const [key, info] of sortedInfos) {
|
|
76
|
+
await loadPlugin(pluginsPath, key, info);
|
|
77
|
+
}
|
|
78
|
+
initialized = true;
|
|
79
|
+
return Object.fromEntries(loadedPlugins.entries());
|
|
80
|
+
};
|
|
81
|
+
export const sortedPluginInfos = async () => {
|
|
82
|
+
const { plugins: { path: pluginsPath }, } = defaultConfig;
|
|
83
|
+
return sortByDependencies(await enumeratePluginInfos(pluginsPath));
|
|
84
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
+
type PluginProfile = {
|
|
3
|
+
id: string;
|
|
4
|
+
};
|
|
5
|
+
declare global {
|
|
6
|
+
namespace Express {
|
|
7
|
+
interface Request {
|
|
8
|
+
pluginProfile?: PluginProfile;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Express middleware that verifies the `Authorization: Bearer <token>` header
|
|
14
|
+
* and attaches `{ pluginProfile }` to the request if valid.
|
|
15
|
+
*
|
|
16
|
+
* Use in plugin routes:
|
|
17
|
+
* ```ts
|
|
18
|
+
* router.get('/secure', ensurePluginAuth(), handler);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* If no valid token is present, the middleware returns 401 JSON. Plugin authors
|
|
22
|
+
* can use `req.pluginProfile` to identify the caller.
|
|
23
|
+
*
|
|
24
|
+
* Note: this helper validates the JWT signature and the presence of a profile
|
|
25
|
+
* identity only. It does not expose the profile handle, check token revocation,
|
|
26
|
+
* or verify whether the profile/account still exists. Plugin authors that need
|
|
27
|
+
* stronger guarantees or the handle should perform their own lookup.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ensurePluginAuth: () => (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jwtUtil } from '../jwt/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Express middleware that verifies the `Authorization: Bearer <token>` header
|
|
4
|
+
* and attaches `{ pluginProfile }` to the request if valid.
|
|
5
|
+
*
|
|
6
|
+
* Use in plugin routes:
|
|
7
|
+
* ```ts
|
|
8
|
+
* router.get('/secure', ensurePluginAuth(), handler);
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* If no valid token is present, the middleware returns 401 JSON. Plugin authors
|
|
12
|
+
* can use `req.pluginProfile` to identify the caller.
|
|
13
|
+
*
|
|
14
|
+
* Note: this helper validates the JWT signature and the presence of a profile
|
|
15
|
+
* identity only. It does not expose the profile handle, check token revocation,
|
|
16
|
+
* or verify whether the profile/account still exists. Plugin authors that need
|
|
17
|
+
* stronger guarantees or the handle should perform their own lookup.
|
|
18
|
+
*/
|
|
19
|
+
export const ensurePluginAuth = () => async (req, res, next) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const authHeader = req.headers.authorization;
|
|
22
|
+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
23
|
+
return res.status(401).json({ success: false, message: 'Unauthorized' });
|
|
24
|
+
}
|
|
25
|
+
const token = authHeader.slice(7);
|
|
26
|
+
if (!token) {
|
|
27
|
+
return res.status(401).json({ success: false, message: 'Unauthorized' });
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const jwt = await jwtUtil();
|
|
31
|
+
const verified = await jwt.verify(token);
|
|
32
|
+
const payload = verified === null || verified === void 0 ? void 0 : verified.payload;
|
|
33
|
+
if (!((_a = payload === null || payload === void 0 ? void 0 : payload.identities) === null || _a === void 0 ? void 0 : _a.profile)) {
|
|
34
|
+
return res
|
|
35
|
+
.status(401)
|
|
36
|
+
.json({ success: false, message: 'Invalid token' });
|
|
37
|
+
}
|
|
38
|
+
req.pluginProfile = { id: payload.identities.profile };
|
|
39
|
+
next();
|
|
40
|
+
}
|
|
41
|
+
catch (_b) {
|
|
42
|
+
return res.status(401).json({ success: false, message: 'Unauthorized' });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AuthorizationData, DbPost, PostWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
import type { PgDb } from '../db/pg/client';
|
|
3
|
+
import type { Mapping } from '../db/pg/map';
|
|
4
|
+
export declare const CONTEXT_NODE_CAP = 100;
|
|
5
|
+
type ClosureDirection = 'ancestors' | 'descendents';
|
|
6
|
+
/** Collect reply-graph ids via one recursive CTE (capped). */
|
|
7
|
+
export declare const collectReplyClosureIds: (db: PgDb, startId: string, direction: ClosureDirection, { maxDepth, limit, }?: {
|
|
8
|
+
maxDepth?: number;
|
|
9
|
+
limit?: number;
|
|
10
|
+
}) => Promise<string[]>;
|
|
11
|
+
/** Load and hydrate posts in a reply closure, then ACL-filter + transform. */
|
|
12
|
+
export declare const loadReplyContextPosts: (authData: AuthorizationData, startId: string, direction: ClosureDirection, mapping: Mapping<DbPost>, { maxDepth, limit, }?: {
|
|
13
|
+
maxDepth?: number;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}) => Promise<PostWithMeta[]>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { allpeepDb } from '../db/index.js';
|
|
3
|
+
import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
|
|
4
|
+
import { applySort } from '../db/pg/map/filters.js';
|
|
5
|
+
import { capabilitiesConfig } from '../config/index.js';
|
|
6
|
+
import { canReadPost, transformPost } from './helpers/index.js';
|
|
7
|
+
export const CONTEXT_NODE_CAP = 100;
|
|
8
|
+
/** Collect reply-graph ids via one recursive CTE (capped). */
|
|
9
|
+
export const collectReplyClosureIds = async (db, startId, direction, { maxDepth = 9999, limit = CONTEXT_NODE_CAP, } = {}) => {
|
|
10
|
+
if (!startId || limit <= 0)
|
|
11
|
+
return [];
|
|
12
|
+
const query = direction === 'ancestors'
|
|
13
|
+
? sql `
|
|
14
|
+
WITH RECURSIVE t AS (
|
|
15
|
+
SELECT to_id AS id, 1 AS depth
|
|
16
|
+
FROM reply_to
|
|
17
|
+
WHERE from_id = ${startId}
|
|
18
|
+
UNION ALL
|
|
19
|
+
SELECT r.to_id, t.depth + 1
|
|
20
|
+
FROM reply_to r
|
|
21
|
+
INNER JOIN t ON r.from_id = t.id
|
|
22
|
+
WHERE t.depth < ${maxDepth}
|
|
23
|
+
)
|
|
24
|
+
SELECT id FROM t
|
|
25
|
+
LIMIT ${limit}
|
|
26
|
+
`
|
|
27
|
+
: sql `
|
|
28
|
+
WITH RECURSIVE t AS (
|
|
29
|
+
SELECT from_id AS id, 1 AS depth
|
|
30
|
+
FROM reply_to
|
|
31
|
+
WHERE to_id = ${startId}
|
|
32
|
+
UNION ALL
|
|
33
|
+
SELECT r.from_id, t.depth + 1
|
|
34
|
+
FROM reply_to r
|
|
35
|
+
INNER JOIN t ON r.to_id = t.id
|
|
36
|
+
WHERE t.depth < ${maxDepth}
|
|
37
|
+
)
|
|
38
|
+
SELECT id FROM t
|
|
39
|
+
LIMIT ${limit}
|
|
40
|
+
`;
|
|
41
|
+
const result = (await db.execute(query));
|
|
42
|
+
return result.rows.map((row) => row.id);
|
|
43
|
+
};
|
|
44
|
+
/** Load and hydrate posts in a reply closure, then ACL-filter + transform. */
|
|
45
|
+
export const loadReplyContextPosts = async (authData, startId, direction, mapping, { maxDepth = 9999, limit = CONTEXT_NODE_CAP, } = {}) => {
|
|
46
|
+
const { db } = await allpeepDb();
|
|
47
|
+
const mapData = mapping.data();
|
|
48
|
+
const ids = await collectReplyClosureIds(db, startId, direction, {
|
|
49
|
+
maxDepth,
|
|
50
|
+
limit,
|
|
51
|
+
});
|
|
52
|
+
if (!ids.length)
|
|
53
|
+
return [];
|
|
54
|
+
const rows = await fetchRowsByIds(db, mapData.collection, ids, mapData.softDelete);
|
|
55
|
+
const hydrated = (await hydrateMapData(db, mapData, rows));
|
|
56
|
+
const sorted = applySort(hydrated, mapData.sort);
|
|
57
|
+
const config = await capabilitiesConfig();
|
|
58
|
+
const readable = canReadPost(config, authData);
|
|
59
|
+
const posts = [];
|
|
60
|
+
for (const post of sorted) {
|
|
61
|
+
const transformed = await transformPost(post, authData.profile);
|
|
62
|
+
if (readable(transformed))
|
|
63
|
+
posts.push(transformed);
|
|
64
|
+
}
|
|
65
|
+
return posts;
|
|
66
|
+
};
|