@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,39 @@
|
|
|
1
|
+
export declare const DEFAULT_EXPORT_DIR = "./arango-export";
|
|
2
|
+
export declare const exportDirFromEnv: () => string;
|
|
3
|
+
export declare const collectionsDir: (exportDir: string) => string;
|
|
4
|
+
export declare const manifestPath: (exportDir: string) => string;
|
|
5
|
+
/** Counts actually inserted into Postgres (after skips / remaps / dedupe). */
|
|
6
|
+
export declare const importStatsPath: (exportDir: string) => string;
|
|
7
|
+
export type ImportStats = {
|
|
8
|
+
importedAt: string;
|
|
9
|
+
collections: CollectionCounts;
|
|
10
|
+
};
|
|
11
|
+
export declare const collectionFilePath: (exportDir: string, collection: string) => string;
|
|
12
|
+
export declare const DOCUMENT_IMPORT_ORDER: readonly ["configs", "i18n", "dataMigrations", "accounts", "roles", "profiles", "groups", "hashtags", "posts", "notifications", "reports", "accessTokens", "pushSubscriptions", "inviteLinks", "jamEvents", "mediaAttachments", "processingStats", "profileSettings"];
|
|
13
|
+
export declare const EDGE_IMPORT_ORDER: readonly ["controls", "follows", "requestsFollow", "mentions", "audience", "postHashtags", "entries", "reactions", "replyTo", "repost", "bookmarks", "postSeen", "hasSeen", "hasRead", "userGroups", "postGroups", "hasRole", "profileAccessTokens", "accountToPushSubscription", "createdReport", "isReportedProfile", "isReportedObject", "inviteLinkCreators", "inviteLinkRedeemers", "jamRecordings"];
|
|
14
|
+
export type CollectionCounts = Record<string, number>;
|
|
15
|
+
export type MigrationManifest = {
|
|
16
|
+
exportedAt: string;
|
|
17
|
+
dbUrl: string;
|
|
18
|
+
dbName?: string;
|
|
19
|
+
collections: CollectionCounts;
|
|
20
|
+
checksums: {
|
|
21
|
+
accountEmails: string;
|
|
22
|
+
postIds: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const arangoConfig: () => {
|
|
26
|
+
url: string;
|
|
27
|
+
databaseName: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
export declare const sha256: (value: string) => string;
|
|
30
|
+
export declare const sortedChecksum: (values: string[]) => string;
|
|
31
|
+
export declare const readJsonl: (filePath: string) => Promise<Record<string, unknown>[]>;
|
|
32
|
+
export declare const readManifest: (exportDir: string) => Promise<MigrationManifest>;
|
|
33
|
+
export declare const writeManifest: (exportDir: string, manifest: MigrationManifest) => Promise<void>;
|
|
34
|
+
export declare const writeImportStats: (exportDir: string, collections: CollectionCounts) => Promise<void>;
|
|
35
|
+
export declare const readImportStats: (exportDir: string) => Promise<ImportStats | null>;
|
|
36
|
+
/** Prefer post-import counts when present (skips / remaps / dedupe). */
|
|
37
|
+
export declare const expectedCollectionCount: (collection: string, manifestCounts: CollectionCounts, importedCounts: CollectionCounts | null) => number;
|
|
38
|
+
export declare const assertExportDir: (exportDir: string) => Promise<void>;
|
|
39
|
+
export declare const BATCH_SIZE = 500;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
2
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3
|
+
var m = o[Symbol.asyncIterator], i;
|
|
4
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
5
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
6
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
7
|
+
};
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { createReadStream } from 'node:fs';
|
|
10
|
+
import { access, readFile, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { constants } from 'node:fs';
|
|
12
|
+
import { createInterface } from 'node:readline';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import dotenv from 'dotenv';
|
|
15
|
+
dotenv.config();
|
|
16
|
+
export const DEFAULT_EXPORT_DIR = './arango-export';
|
|
17
|
+
export const exportDirFromEnv = () => { var _a; return (_a = process.env.MIGRATION_EXPORT_DIR) !== null && _a !== void 0 ? _a : DEFAULT_EXPORT_DIR; };
|
|
18
|
+
export const collectionsDir = (exportDir) => join(exportDir, 'collections');
|
|
19
|
+
export const manifestPath = (exportDir) => join(exportDir, 'manifest.json');
|
|
20
|
+
/** Counts actually inserted into Postgres (after skips / remaps / dedupe). */
|
|
21
|
+
export const importStatsPath = (exportDir) => join(exportDir, 'import-stats.json');
|
|
22
|
+
export const collectionFilePath = (exportDir, collection) => join(collectionsDir(exportDir), `${collection}.jsonl`);
|
|
23
|
+
export const DOCUMENT_IMPORT_ORDER = [
|
|
24
|
+
'configs',
|
|
25
|
+
'i18n',
|
|
26
|
+
'dataMigrations',
|
|
27
|
+
'accounts',
|
|
28
|
+
'roles',
|
|
29
|
+
'profiles',
|
|
30
|
+
'groups',
|
|
31
|
+
'hashtags',
|
|
32
|
+
'posts',
|
|
33
|
+
'notifications',
|
|
34
|
+
'reports',
|
|
35
|
+
'accessTokens',
|
|
36
|
+
'pushSubscriptions',
|
|
37
|
+
'inviteLinks',
|
|
38
|
+
'jamEvents',
|
|
39
|
+
'mediaAttachments',
|
|
40
|
+
'processingStats',
|
|
41
|
+
'profileSettings',
|
|
42
|
+
];
|
|
43
|
+
export const EDGE_IMPORT_ORDER = [
|
|
44
|
+
'controls',
|
|
45
|
+
'follows',
|
|
46
|
+
'requestsFollow',
|
|
47
|
+
'mentions',
|
|
48
|
+
'audience',
|
|
49
|
+
'postHashtags',
|
|
50
|
+
'entries',
|
|
51
|
+
'reactions',
|
|
52
|
+
'replyTo',
|
|
53
|
+
'repost',
|
|
54
|
+
'bookmarks',
|
|
55
|
+
'postSeen',
|
|
56
|
+
'hasSeen',
|
|
57
|
+
'hasRead',
|
|
58
|
+
'userGroups',
|
|
59
|
+
'postGroups',
|
|
60
|
+
'hasRole',
|
|
61
|
+
'profileAccessTokens',
|
|
62
|
+
'accountToPushSubscription',
|
|
63
|
+
'createdReport',
|
|
64
|
+
'isReportedProfile',
|
|
65
|
+
'isReportedObject',
|
|
66
|
+
'inviteLinkCreators',
|
|
67
|
+
'inviteLinkRedeemers',
|
|
68
|
+
'jamRecordings',
|
|
69
|
+
];
|
|
70
|
+
export const arangoConfig = () => {
|
|
71
|
+
var _a;
|
|
72
|
+
return ({
|
|
73
|
+
url: (_a = process.env.DB_URL) !== null && _a !== void 0 ? _a : 'http://localhost:8529',
|
|
74
|
+
databaseName: process.env.DB_NAME,
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export const sha256 = (value) => createHash('sha256').update(value).digest('hex');
|
|
78
|
+
export const sortedChecksum = (values) => sha256(values.filter(Boolean).sort().join('\n'));
|
|
79
|
+
export const readJsonl = async (filePath) => {
|
|
80
|
+
var _a, e_1, _b, _c;
|
|
81
|
+
const docs = [];
|
|
82
|
+
let buffer = '';
|
|
83
|
+
const lineReader = createInterface({
|
|
84
|
+
input: createReadStream(filePath),
|
|
85
|
+
crlfDelay: Infinity,
|
|
86
|
+
});
|
|
87
|
+
try {
|
|
88
|
+
for (var _d = true, lineReader_1 = __asyncValues(lineReader), lineReader_1_1; lineReader_1_1 = await lineReader_1.next(), _a = lineReader_1_1.done, !_a; _d = true) {
|
|
89
|
+
_c = lineReader_1_1.value;
|
|
90
|
+
_d = false;
|
|
91
|
+
const line = _c;
|
|
92
|
+
if (!line.trim()) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
buffer += line;
|
|
96
|
+
try {
|
|
97
|
+
docs.push(JSON.parse(buffer));
|
|
98
|
+
buffer = '';
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
102
|
+
const partialJson = message.includes('Unexpected end of JSON input') ||
|
|
103
|
+
message.includes('Unterminated string') ||
|
|
104
|
+
message.includes('Unexpected token');
|
|
105
|
+
if (!partialJson) {
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
112
|
+
finally {
|
|
113
|
+
try {
|
|
114
|
+
if (!_d && !_a && (_b = lineReader_1.return)) await _b.call(lineReader_1);
|
|
115
|
+
}
|
|
116
|
+
finally { if (e_1) throw e_1.error; }
|
|
117
|
+
}
|
|
118
|
+
if (buffer.trim().length > 0) {
|
|
119
|
+
throw new Error(`Unparsed JSON remaining in ${filePath}`);
|
|
120
|
+
}
|
|
121
|
+
return docs;
|
|
122
|
+
};
|
|
123
|
+
export const readManifest = async (exportDir) => {
|
|
124
|
+
const raw = await readFile(manifestPath(exportDir), 'utf-8');
|
|
125
|
+
return JSON.parse(raw);
|
|
126
|
+
};
|
|
127
|
+
export const writeManifest = async (exportDir, manifest) => {
|
|
128
|
+
await writeFile(manifestPath(exportDir), JSON.stringify(manifest, null, 2));
|
|
129
|
+
};
|
|
130
|
+
export const writeImportStats = async (exportDir, collections) => {
|
|
131
|
+
const stats = {
|
|
132
|
+
importedAt: new Date().toISOString(),
|
|
133
|
+
collections,
|
|
134
|
+
};
|
|
135
|
+
await writeFile(importStatsPath(exportDir), JSON.stringify(stats, null, 2));
|
|
136
|
+
};
|
|
137
|
+
export const readImportStats = async (exportDir) => {
|
|
138
|
+
try {
|
|
139
|
+
await access(importStatsPath(exportDir), constants.F_OK);
|
|
140
|
+
}
|
|
141
|
+
catch (_a) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const raw = await readFile(importStatsPath(exportDir), 'utf-8');
|
|
145
|
+
return JSON.parse(raw);
|
|
146
|
+
};
|
|
147
|
+
/** Prefer post-import counts when present (skips / remaps / dedupe). */
|
|
148
|
+
export const expectedCollectionCount = (collection, manifestCounts, importedCounts) => {
|
|
149
|
+
var _a, _b;
|
|
150
|
+
return importedCounts
|
|
151
|
+
? ((_a = importedCounts[collection]) !== null && _a !== void 0 ? _a : 0)
|
|
152
|
+
: ((_b = manifestCounts[collection]) !== null && _b !== void 0 ? _b : 0);
|
|
153
|
+
};
|
|
154
|
+
export const assertExportDir = async (exportDir) => {
|
|
155
|
+
await access(manifestPath(exportDir), constants.F_OK);
|
|
156
|
+
await access(collectionsDir(exportDir), constants.F_OK);
|
|
157
|
+
};
|
|
158
|
+
export const BATCH_SIZE = 500;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Postgres uuid compares case-insensitively; normalize so dedupe matches. */
|
|
2
|
+
export declare const normalizeImportId: (value: unknown) => string | undefined;
|
|
3
|
+
export declare const arangoDocToModel: (doc: Record<string, unknown>) => Record<string, unknown>;
|
|
4
|
+
export type ImportContext = {
|
|
5
|
+
postCreatorIdByPostId?: Map<string, string>;
|
|
6
|
+
/** Empty-name / duplicate-name hashtags: old id → kept id, or '' if dropped. */
|
|
7
|
+
hashtagIdRemap?: Map<string, string>;
|
|
8
|
+
};
|
|
9
|
+
/** Pre-scan entries edges so legacy posts without creatorId can be imported. */
|
|
10
|
+
export declare const buildPostCreatorIdByPostId: (collectionsDir: string) => Promise<Map<string, string>>;
|
|
11
|
+
/**
|
|
12
|
+
* Legacy Arango groups used discoverable/locked flags; capabilities were added
|
|
13
|
+
* later via an Arango-only data migration that never runs on Postgres restores.
|
|
14
|
+
*/
|
|
15
|
+
export declare const capabilitiesFromLegacyGroupFlags: (data: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
16
|
+
export declare const arangoDocToDocumentRow: (collection: string, doc: Record<string, unknown>, context?: ImportContext) => Record<string, unknown>;
|
|
17
|
+
export declare const arangoDocToEdgeRow: (collection: string, doc: Record<string, unknown>) => Record<string, unknown>;
|
|
18
|
+
export declare const isEdgeCollection: (collection: string) => boolean;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { access } from 'node:fs/promises';
|
|
13
|
+
import { constants } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { groupCapabilityTemplates } from '@openpeepshq/common/lib';
|
|
16
|
+
import { documentRegistry, edgeRegistry, parseDocRef, } from '../pg/map/registry.js';
|
|
17
|
+
import { nowIso } from '../pg/mappers.js';
|
|
18
|
+
import { uuidv7 } from 'uuidv7';
|
|
19
|
+
import { readJsonl } from './shared.js';
|
|
20
|
+
const ARANGO_META = ['_id', '_key', '_rev', '_from', '_to'];
|
|
21
|
+
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
22
|
+
/** Postgres uuid compares case-insensitively; normalize so dedupe matches. */
|
|
23
|
+
export const normalizeImportId = (value) => {
|
|
24
|
+
if (typeof value !== 'string') {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const trimmed = value.trim();
|
|
28
|
+
if (!trimmed) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return UUID_REGEX.test(trimmed) ? trimmed.toLowerCase() : trimmed;
|
|
32
|
+
};
|
|
33
|
+
export const arangoDocToModel = (doc) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const id = ((_a = doc._key) !== null && _a !== void 0 ? _a : doc.id);
|
|
36
|
+
const model = Object.assign(Object.assign({}, doc), { id });
|
|
37
|
+
for (const key of ARANGO_META) {
|
|
38
|
+
delete model[key];
|
|
39
|
+
}
|
|
40
|
+
return model;
|
|
41
|
+
};
|
|
42
|
+
const isNonEmptyTimestamp = (value) => typeof value === 'string' && value.trim() !== '';
|
|
43
|
+
const resolveDocumentId = (doc) => {
|
|
44
|
+
const candidates = [doc.id, doc._key]
|
|
45
|
+
.map((value) => normalizeImportId(value))
|
|
46
|
+
.filter((value) => Boolean(value));
|
|
47
|
+
const uuid = candidates.find((value) => UUID_REGEX.test(value));
|
|
48
|
+
return uuid !== null && uuid !== void 0 ? uuid : uuidv7();
|
|
49
|
+
};
|
|
50
|
+
const timestampsFromModel = (model) => {
|
|
51
|
+
const ts = nowIso();
|
|
52
|
+
return {
|
|
53
|
+
createdAt: isNonEmptyTimestamp(model.createdAt) ? model.createdAt : ts,
|
|
54
|
+
updatedAt: isNonEmptyTimestamp(model.updatedAt) ? model.updatedAt : ts,
|
|
55
|
+
deletedAt: isNonEmptyTimestamp(model.deletedAt) ? model.deletedAt : null,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const entryTypeFromDoc = (doc) => {
|
|
59
|
+
if (typeof doc.type === 'string') {
|
|
60
|
+
return doc.type;
|
|
61
|
+
}
|
|
62
|
+
const body = doc.body;
|
|
63
|
+
if (body && typeof body === 'object' && 'type' in body) {
|
|
64
|
+
return body.type;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
};
|
|
68
|
+
/** Pre-scan entries edges so legacy posts without creatorId can be imported. */
|
|
69
|
+
export const buildPostCreatorIdByPostId = async (collectionsDir) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
const map = new Map();
|
|
72
|
+
const filePath = join(collectionsDir, 'entries.jsonl');
|
|
73
|
+
try {
|
|
74
|
+
await access(filePath, constants.F_OK);
|
|
75
|
+
}
|
|
76
|
+
catch (_e) {
|
|
77
|
+
return map;
|
|
78
|
+
}
|
|
79
|
+
const docs = await readJsonl(filePath);
|
|
80
|
+
for (const doc of docs) {
|
|
81
|
+
const fromRef = parseDocRef(doc._from);
|
|
82
|
+
const toRef = parseDocRef(doc._to);
|
|
83
|
+
if (!fromRef || !toRef || toRef.collection !== 'posts') {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const entryType = entryTypeFromDoc(doc);
|
|
87
|
+
const postId = (_a = normalizeImportId(toRef.id)) !== null && _a !== void 0 ? _a : toRef.id;
|
|
88
|
+
const creatorId = (_b = normalizeImportId(fromRef.id)) !== null && _b !== void 0 ? _b : fromRef.id;
|
|
89
|
+
if (entryType === 'create' || !map.has(postId)) {
|
|
90
|
+
map.set(postId, creatorId);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return map;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Legacy Arango groups used discoverable/locked flags; capabilities were added
|
|
97
|
+
* later via an Arango-only data migration that never runs on Postgres restores.
|
|
98
|
+
*/
|
|
99
|
+
export const capabilitiesFromLegacyGroupFlags = (data) => {
|
|
100
|
+
if (data.capabilities && typeof data.capabilities === 'object') {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
const discoverable = Boolean(data.discoverable);
|
|
104
|
+
const locked = Boolean(data.locked);
|
|
105
|
+
const { publicGroup, privateGroup, lockedGroup } = groupCapabilityTemplates;
|
|
106
|
+
const template = discoverable
|
|
107
|
+
? locked
|
|
108
|
+
? lockedGroup
|
|
109
|
+
: publicGroup
|
|
110
|
+
: privateGroup;
|
|
111
|
+
return template.capabilities;
|
|
112
|
+
};
|
|
113
|
+
export const arangoDocToDocumentRow = (collection, doc, context) => {
|
|
114
|
+
var _a, _b, _e, _f, _g, _h, _j, _k, _m, _o, _p, _q, _r, _s;
|
|
115
|
+
const model = arangoDocToModel(doc);
|
|
116
|
+
const { createdAt, updatedAt, deletedAt } = timestampsFromModel(model);
|
|
117
|
+
if (collection === 'configs') {
|
|
118
|
+
const { createdAt: _c, updatedAt: _u, deletedAt: _d, id: _id } = model, body = __rest(model, ["createdAt", "updatedAt", "deletedAt", "id"]);
|
|
119
|
+
const rawKey = String((_b = (_a = doc._key) !== null && _a !== void 0 ? _a : doc.id) !== null && _b !== void 0 ? _b : '');
|
|
120
|
+
// Legacy Arango backups used allpeep-* keys; runtime loaders use openpeeps-*.
|
|
121
|
+
const key = rawKey.startsWith('allpeep-')
|
|
122
|
+
? `openpeeps-${rawKey.slice('allpeep-'.length)}`
|
|
123
|
+
: rawKey;
|
|
124
|
+
return { key, body, createdAt, updatedAt, deletedAt };
|
|
125
|
+
}
|
|
126
|
+
if (collection === 'dataMigrations') {
|
|
127
|
+
const appliedAtRaw = (_e = doc.appliedAt) !== null && _e !== void 0 ? _e : model.createdAt;
|
|
128
|
+
return {
|
|
129
|
+
id: (_f = doc._key) !== null && _f !== void 0 ? _f : doc.id,
|
|
130
|
+
appliedAt: isNonEmptyTimestamp(appliedAtRaw) ? appliedAtRaw : nowIso(),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
if (collection === 'i18n') {
|
|
134
|
+
const id = resolveDocumentId(doc);
|
|
135
|
+
const locale = ((_h = (_g = doc.locale) !== null && _g !== void 0 ? _g : doc._key) !== null && _h !== void 0 ? _h : id);
|
|
136
|
+
const namespace = ((_j = doc.namespace) !== null && _j !== void 0 ? _j : 'translation');
|
|
137
|
+
const body = (_m = (_k = doc.body) !== null && _k !== void 0 ? _k : doc.translations) !== null && _m !== void 0 ? _m : (() => {
|
|
138
|
+
const { createdAt: _c, updatedAt: _u, deletedAt: _d, id: _id, locale: _l, namespace: _n, translations: _t } = model, rest = __rest(model, ["createdAt", "updatedAt", "deletedAt", "id", "locale", "namespace", "translations"]);
|
|
139
|
+
return rest;
|
|
140
|
+
})();
|
|
141
|
+
return {
|
|
142
|
+
id,
|
|
143
|
+
locale,
|
|
144
|
+
namespace,
|
|
145
|
+
body,
|
|
146
|
+
createdAt,
|
|
147
|
+
updatedAt,
|
|
148
|
+
deletedAt,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const config = documentRegistry[collection];
|
|
152
|
+
if (!config) {
|
|
153
|
+
throw new Error(`Unknown document collection: ${collection}`);
|
|
154
|
+
}
|
|
155
|
+
const id = (_p = normalizeImportId((_o = doc._key) !== null && _o !== void 0 ? _o : doc.id)) !== null && _p !== void 0 ? _p : String((_r = (_q = doc._key) !== null && _q !== void 0 ? _q : doc.id) !== null && _r !== void 0 ? _r : '');
|
|
156
|
+
const { createdAt: _c, updatedAt: _u, deletedAt: _d, id: _id } = model, data = __rest(model, ["createdAt", "updatedAt", "deletedAt", "id"]);
|
|
157
|
+
const { scalars, body } = config.splitPatch(data);
|
|
158
|
+
if (collection === 'posts' &&
|
|
159
|
+
scalars.creatorId === undefined &&
|
|
160
|
+
(context === null || context === void 0 ? void 0 : context.postCreatorIdByPostId)) {
|
|
161
|
+
const creatorId = context.postCreatorIdByPostId.get(id);
|
|
162
|
+
if (creatorId) {
|
|
163
|
+
scalars.creatorId = creatorId;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (collection === 'profileSettings' && scalars.profileId === undefined) {
|
|
167
|
+
scalars.profileId = id;
|
|
168
|
+
}
|
|
169
|
+
if (collection === 'notifications' && scalars.profileId === undefined) {
|
|
170
|
+
const actorId = (_s = model.actorId) !== null && _s !== void 0 ? _s : model.profileId;
|
|
171
|
+
if (typeof actorId === 'string') {
|
|
172
|
+
scalars.profileId = actorId;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (collection === 'groups') {
|
|
176
|
+
const capabilities = capabilitiesFromLegacyGroupFlags(data);
|
|
177
|
+
if (capabilities) {
|
|
178
|
+
body.capabilities = capabilities;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return Object.assign(Object.assign({ id }, scalars), { body,
|
|
182
|
+
createdAt,
|
|
183
|
+
updatedAt,
|
|
184
|
+
deletedAt });
|
|
185
|
+
};
|
|
186
|
+
export const arangoDocToEdgeRow = (collection, doc) => {
|
|
187
|
+
var _a, _b, _e, _f, _g;
|
|
188
|
+
const config = edgeRegistry[collection];
|
|
189
|
+
if (!config) {
|
|
190
|
+
throw new Error(`Unknown edge collection: ${collection}`);
|
|
191
|
+
}
|
|
192
|
+
const fromRef = parseDocRef(doc._from);
|
|
193
|
+
const toRef = parseDocRef(doc._to);
|
|
194
|
+
if (!fromRef || !toRef) {
|
|
195
|
+
throw new Error(`Invalid edge refs in ${collection}/${String(doc._key)}: ${String(doc._from)} -> ${String(doc._to)}`);
|
|
196
|
+
}
|
|
197
|
+
const model = arangoDocToModel(doc);
|
|
198
|
+
const { createdAt, updatedAt } = timestampsFromModel(model);
|
|
199
|
+
const { createdAt: _c, updatedAt: _u, id: _id } = model, body = __rest(model, ["createdAt", "updatedAt", "id"]);
|
|
200
|
+
return {
|
|
201
|
+
id: (_b = normalizeImportId((_a = doc._key) !== null && _a !== void 0 ? _a : doc.id)) !== null && _b !== void 0 ? _b : String((_e = doc._key) !== null && _e !== void 0 ? _e : doc.id),
|
|
202
|
+
fromId: (_f = normalizeImportId(fromRef.id)) !== null && _f !== void 0 ? _f : fromRef.id,
|
|
203
|
+
toId: (_g = normalizeImportId(toRef.id)) !== null && _g !== void 0 ? _g : toRef.id,
|
|
204
|
+
body,
|
|
205
|
+
createdAt,
|
|
206
|
+
updatedAt,
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
export const isEdgeCollection = (collection) => collection in edgeRegistry;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CollectionCounts } from './shared';
|
|
2
|
+
type ValidationIssue = {
|
|
3
|
+
collection: string;
|
|
4
|
+
kind: 'count' | 'checksum';
|
|
5
|
+
expected: string | number;
|
|
6
|
+
actual: string | number;
|
|
7
|
+
};
|
|
8
|
+
export declare const validateMigration: (exportDir?: string, options?: {
|
|
9
|
+
closeConnection?: boolean;
|
|
10
|
+
importedCounts?: CollectionCounts;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
ok: true;
|
|
13
|
+
issues: ValidationIssue[];
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
issues: ValidationIssue[];
|
|
17
|
+
}>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { logger } from '../../log/index.js';
|
|
3
|
+
import { closePostgres, pgDb } from '../pg/client.js';
|
|
4
|
+
import { documentRegistry, edgeRegistry } from '../pg/map/registry.js';
|
|
5
|
+
import { tableCount } from './detect.js';
|
|
6
|
+
import { assertExportDir, expectedCollectionCount, exportDirFromEnv, readImportStats, readManifest, sortedChecksum, } from './shared.js';
|
|
7
|
+
const log = logger('core:migration:validate');
|
|
8
|
+
const accountEmailChecksum = async () => {
|
|
9
|
+
const db = pgDb();
|
|
10
|
+
const rows = await db.execute(sql `SELECT email FROM accounts ORDER BY email`);
|
|
11
|
+
return sortedChecksum(rows.rows.map((row) => row.email));
|
|
12
|
+
};
|
|
13
|
+
const postIdChecksum = async () => {
|
|
14
|
+
const db = pgDb();
|
|
15
|
+
const rows = await db.execute(sql `SELECT id FROM posts ORDER BY id`);
|
|
16
|
+
return sortedChecksum(rows.rows.map((row) => row.id));
|
|
17
|
+
};
|
|
18
|
+
export const validateMigration = async (exportDir = exportDirFromEnv(), options = {}) => {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
const closeConnection = (_a = options.closeConnection) !== null && _a !== void 0 ? _a : true;
|
|
21
|
+
await assertExportDir(exportDir);
|
|
22
|
+
const manifest = await readManifest(exportDir);
|
|
23
|
+
const importStats = await readImportStats(exportDir);
|
|
24
|
+
const importedCounts = (_c = (_b = options.importedCounts) !== null && _b !== void 0 ? _b : importStats === null || importStats === void 0 ? void 0 : importStats.collections) !== null && _c !== void 0 ? _c : null;
|
|
25
|
+
if (importedCounts) {
|
|
26
|
+
log.info('Validating Postgres counts against import stats (intentional Arango skips/remaps allowed)');
|
|
27
|
+
}
|
|
28
|
+
const issues = [];
|
|
29
|
+
const collections = [
|
|
30
|
+
...Object.keys(documentRegistry),
|
|
31
|
+
...Object.keys(edgeRegistry),
|
|
32
|
+
];
|
|
33
|
+
for (const collection of collections) {
|
|
34
|
+
const expected = expectedCollectionCount(collection, manifest.collections, importedCounts);
|
|
35
|
+
const actual = await tableCount(collection);
|
|
36
|
+
if (expected !== actual) {
|
|
37
|
+
issues.push({ collection, kind: 'count', expected, actual });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const emailChecksum = await accountEmailChecksum();
|
|
41
|
+
if (emailChecksum !== manifest.checksums.accountEmails) {
|
|
42
|
+
issues.push({
|
|
43
|
+
collection: 'accounts',
|
|
44
|
+
kind: 'checksum',
|
|
45
|
+
expected: manifest.checksums.accountEmails,
|
|
46
|
+
actual: emailChecksum,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const postsChecksum = await postIdChecksum();
|
|
50
|
+
if (postsChecksum !== manifest.checksums.postIds) {
|
|
51
|
+
issues.push({
|
|
52
|
+
collection: 'posts',
|
|
53
|
+
kind: 'checksum',
|
|
54
|
+
expected: manifest.checksums.postIds,
|
|
55
|
+
actual: postsChecksum,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (closeConnection) {
|
|
59
|
+
await closePostgres();
|
|
60
|
+
}
|
|
61
|
+
if (issues.length === 0) {
|
|
62
|
+
log.info('Validation passed for export %s', exportDir);
|
|
63
|
+
return { ok: true, issues };
|
|
64
|
+
}
|
|
65
|
+
for (const issue of issues) {
|
|
66
|
+
log.error('Validation failed for %s (%s): expected %s, got %s', issue.collection, issue.kind, issue.expected, issue.actual);
|
|
67
|
+
}
|
|
68
|
+
return { ok: false, issues };
|
|
69
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
|
+
import pg from 'pg';
|
|
3
|
+
import { type Schema } from './schema';
|
|
4
|
+
/** Shared by initPostgres + auto-migrate so DDL cannot race an import. */
|
|
5
|
+
export declare const SCHEMA_MIGRATE_LOCK: {
|
|
6
|
+
readonly key1: 8742301;
|
|
7
|
+
readonly key2: 1;
|
|
8
|
+
};
|
|
9
|
+
export type PgDb = NodePgDatabase<Schema>;
|
|
10
|
+
export declare const pgConnectionString: () => string;
|
|
11
|
+
export declare const pgPool: () => pg.Pool;
|
|
12
|
+
export declare const pgDb: () => PgDb;
|
|
13
|
+
/**
|
|
14
|
+
* Hold a session-level advisory lock on a dedicated checked-out client for the
|
|
15
|
+
* duration of `fn`. Other pool clients may still run queries; only another
|
|
16
|
+
* lock acquisition on the same keys will block.
|
|
17
|
+
*/
|
|
18
|
+
export declare const withPostgresAdvisoryLock: <T>(key1: number, key2: number, fn: () => Promise<T>) => Promise<T>;
|
|
19
|
+
export declare const initPostgres: () => Promise<PgDb>;
|
|
20
|
+
export declare const closePostgres: () => Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Drop and recreate app schemas. Drizzle stores its migration journal in
|
|
23
|
+
* `drizzle` (not `public`); both must be cleared or the next migrate() is a
|
|
24
|
+
* no-op / conflicts with leftover types.
|
|
25
|
+
*
|
|
26
|
+
* Closes the pool by default so remigrate does not reuse connections whose
|
|
27
|
+
* search_path still points at the dropped public schema OID. Pass
|
|
28
|
+
* `{ closePool: false }` when a caller still holds a pooled client (e.g.
|
|
29
|
+
* advisory lock).
|
|
30
|
+
*/
|
|
31
|
+
export declare const resetPostgresSchemas: (options?: {
|
|
32
|
+
closePool?: boolean;
|
|
33
|
+
}) => Promise<void>;
|
|
34
|
+
/** Wipe all app tables after a failed auto-migration (keeps the database). */
|
|
35
|
+
export declare const wipePostgresDatabase: () => Promise<void>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
3
|
+
import pg from 'pg';
|
|
4
|
+
import { logger } from '../../log/index.js';
|
|
5
|
+
import { dbTimingEnabled, maybeLogSlowQuery } from '../../performance/index.js';
|
|
6
|
+
import { schema } from './schema/index.js';
|
|
7
|
+
import { assertSchemaReady, runMigrations } from './migrate.js';
|
|
8
|
+
const log = logger('openpeeps:pg');
|
|
9
|
+
/** Shared by initPostgres + auto-migrate so DDL cannot race an import. */
|
|
10
|
+
export const SCHEMA_MIGRATE_LOCK = { key1: 8742301, key2: 1 };
|
|
11
|
+
let pool;
|
|
12
|
+
let dbInstance;
|
|
13
|
+
export const pgConnectionString = () => {
|
|
14
|
+
var _a;
|
|
15
|
+
return (_a = process.env.DATABASE_URL) !== null && _a !== void 0 ? _a : 'postgresql://openpeeps:openpeeps@localhost:5432/openpeeps';
|
|
16
|
+
};
|
|
17
|
+
const instrumentPoolQuery = (target) => {
|
|
18
|
+
if (!dbTimingEnabled())
|
|
19
|
+
return;
|
|
20
|
+
const originalQuery = target.query.bind(target);
|
|
21
|
+
// Pool.query has many overloads; wrap for timing without changing call sites.
|
|
22
|
+
target.query = (...args) => {
|
|
23
|
+
const start = performance.now();
|
|
24
|
+
const result = originalQuery(...args);
|
|
25
|
+
if (result && typeof result.then === 'function') {
|
|
26
|
+
return result.then((value) => {
|
|
27
|
+
maybeLogSlowQuery(args[0], performance.now() - start);
|
|
28
|
+
return value;
|
|
29
|
+
}, (err) => {
|
|
30
|
+
maybeLogSlowQuery(args[0], performance.now() - start);
|
|
31
|
+
throw err;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
maybeLogSlowQuery(args[0], performance.now() - start);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export const pgPool = () => {
|
|
39
|
+
if (!pool) {
|
|
40
|
+
pool = new pg.Pool({ connectionString: pgConnectionString() });
|
|
41
|
+
pool.on('error', (err) => log.error(err, 'Postgres pool error'));
|
|
42
|
+
instrumentPoolQuery(pool);
|
|
43
|
+
}
|
|
44
|
+
return pool;
|
|
45
|
+
};
|
|
46
|
+
export const pgDb = () => {
|
|
47
|
+
if (!dbInstance) {
|
|
48
|
+
dbInstance = drizzle(pgPool(), { schema });
|
|
49
|
+
}
|
|
50
|
+
return dbInstance;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Hold a session-level advisory lock on a dedicated checked-out client for the
|
|
54
|
+
* duration of `fn`. Other pool clients may still run queries; only another
|
|
55
|
+
* lock acquisition on the same keys will block.
|
|
56
|
+
*/
|
|
57
|
+
export const withPostgresAdvisoryLock = async (key1, key2, fn) => {
|
|
58
|
+
const client = await pgPool().connect();
|
|
59
|
+
try {
|
|
60
|
+
await client.query('SELECT pg_advisory_lock($1::int, $2::int)', [
|
|
61
|
+
key1,
|
|
62
|
+
key2,
|
|
63
|
+
]);
|
|
64
|
+
await client.query('SET search_path TO public');
|
|
65
|
+
try {
|
|
66
|
+
return await fn();
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
await client
|
|
70
|
+
.query('SELECT pg_advisory_unlock($1::int, $2::int)', [key1, key2])
|
|
71
|
+
.catch((err) => {
|
|
72
|
+
log.error(err, 'Failed to release Postgres advisory lock');
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
client.release();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export const initPostgres = async () => {
|
|
81
|
+
const client = pgPool();
|
|
82
|
+
await client.query('SELECT 1');
|
|
83
|
+
await client.query('SET search_path TO public');
|
|
84
|
+
log.info('Postgres connection established');
|
|
85
|
+
// Hosted web/worker set RUN_DB_MIGRATE_ON_BOOT=false; migrate runs as one-shot.
|
|
86
|
+
if (process.env.RUN_DB_MIGRATE_ON_BOOT !== 'false') {
|
|
87
|
+
await withPostgresAdvisoryLock(SCHEMA_MIGRATE_LOCK.key1, SCHEMA_MIGRATE_LOCK.key2, () => runMigrations());
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
await assertSchemaReady();
|
|
91
|
+
}
|
|
92
|
+
return pgDb();
|
|
93
|
+
};
|
|
94
|
+
export const closePostgres = async () => {
|
|
95
|
+
await (pool === null || pool === void 0 ? void 0 : pool.end());
|
|
96
|
+
pool = undefined;
|
|
97
|
+
dbInstance = undefined;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Drop and recreate app schemas. Drizzle stores its migration journal in
|
|
101
|
+
* `drizzle` (not `public`); both must be cleared or the next migrate() is a
|
|
102
|
+
* no-op / conflicts with leftover types.
|
|
103
|
+
*
|
|
104
|
+
* Closes the pool by default so remigrate does not reuse connections whose
|
|
105
|
+
* search_path still points at the dropped public schema OID. Pass
|
|
106
|
+
* `{ closePool: false }` when a caller still holds a pooled client (e.g.
|
|
107
|
+
* advisory lock).
|
|
108
|
+
*/
|
|
109
|
+
export const resetPostgresSchemas = async (options = {}) => {
|
|
110
|
+
var _a;
|
|
111
|
+
const closePool = (_a = options.closePool) !== null && _a !== void 0 ? _a : true;
|
|
112
|
+
const db = pgDb();
|
|
113
|
+
await db.execute(sql.raw('DROP SCHEMA IF EXISTS public CASCADE'));
|
|
114
|
+
await db.execute(sql.raw('DROP SCHEMA IF EXISTS drizzle CASCADE'));
|
|
115
|
+
await db.execute(sql.raw('CREATE SCHEMA IF NOT EXISTS public'));
|
|
116
|
+
await db.execute(sql.raw('GRANT ALL ON SCHEMA public TO CURRENT_USER'));
|
|
117
|
+
await db.execute(sql.raw('GRANT ALL ON SCHEMA public TO public'));
|
|
118
|
+
if (closePool) {
|
|
119
|
+
await closePostgres();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/** Wipe all app tables after a failed auto-migration (keeps the database). */
|
|
123
|
+
export const wipePostgresDatabase = async () => {
|
|
124
|
+
await resetPostgresSchemas();
|
|
125
|
+
log.warn('Wiped Postgres public + drizzle schemas after failed migration');
|
|
126
|
+
};
|