@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,111 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile, access, readFile } from 'node:fs/promises';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { logger } from '../../log/index.js';
|
|
6
|
+
import { SCHEMA_MIGRATE_LOCK, closePostgres, resetPostgresSchemas, withPostgresAdvisoryLock, } from '../pg/client.js';
|
|
7
|
+
import { arangoHasSourceData, isPostgresEmpty } from './detect.js';
|
|
8
|
+
import { exportArango } from './exportArango.js';
|
|
9
|
+
import { importPostgres } from './importPostgres.js';
|
|
10
|
+
import { validateMigration } from './validate.js';
|
|
11
|
+
const log = logger('core:migration:auto');
|
|
12
|
+
const autoMigrateEnabled = () => process.env.AUTO_MIGRATE_FROM_ARANGO !== 'false';
|
|
13
|
+
export const autoMigrateFailureMarkerPath = () => process.env.AUTO_MIGRATE_FAILURE_MARKER ||
|
|
14
|
+
// Ephemeral container path (not on apatlogs/apatfiles volumes) so a
|
|
15
|
+
// replaced/updated container retries migration automatically.
|
|
16
|
+
join(tmpdir(), 'openpeeps-auto-migrate-from-arango.failed');
|
|
17
|
+
const markerExists = async (path) => {
|
|
18
|
+
try {
|
|
19
|
+
await access(path, constants.F_OK);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (_a) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/** Stay alive so Docker `restart: always` does not retry a failed migration. */
|
|
27
|
+
const idleForever = async (message) => {
|
|
28
|
+
log.error(message);
|
|
29
|
+
// A bare pending Promise does not keep Node's event loop alive — schedule a
|
|
30
|
+
// timer so the process does not exit(0) and get restarted by Docker.
|
|
31
|
+
await new Promise(() => {
|
|
32
|
+
setInterval(() => undefined, 60000);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const writeFailureMarker = async (detail) => {
|
|
36
|
+
const marker = autoMigrateFailureMarkerPath();
|
|
37
|
+
try {
|
|
38
|
+
await writeFile(marker, `Automatic Arango → Postgres migration failed at ${new Date().toISOString()}\n\n${detail}\n`, 'utf8');
|
|
39
|
+
log.error('Wrote auto-migration failure marker to %s (remove it to retry after fixing data)', marker);
|
|
40
|
+
}
|
|
41
|
+
catch (markerErr) {
|
|
42
|
+
log.error('Failed to write auto-migration failure marker to %s', marker, markerErr);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export const maybeAutoMigrateFromArango = async () => {
|
|
46
|
+
if (!autoMigrateEnabled()) {
|
|
47
|
+
log.info('Automatic Arango → Postgres migration is disabled');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const marker = autoMigrateFailureMarkerPath();
|
|
51
|
+
if (await markerExists(marker)) {
|
|
52
|
+
const previous = await readFile(marker, 'utf8').catch(() => '');
|
|
53
|
+
await idleForever(`Previous automatic Arango → Postgres migration failed. Marker: ${marker}\n${previous}`);
|
|
54
|
+
}
|
|
55
|
+
if (!(await isPostgresEmpty())) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!(await arangoHasSourceData())) {
|
|
59
|
+
log.info('Postgres is empty and no Arango source data was found; skipping auto migration');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let failureDetail;
|
|
63
|
+
// Serialize against concurrent apat processes (compose scale, rolling
|
|
64
|
+
// restart). A peer that hits a migrate conflict used to DROP SCHEMA under
|
|
65
|
+
// an in-flight import — holding this lock for the whole import prevents that.
|
|
66
|
+
await withPostgresAdvisoryLock(SCHEMA_MIGRATE_LOCK.key1, SCHEMA_MIGRATE_LOCK.key2, async () => {
|
|
67
|
+
var _a;
|
|
68
|
+
if (!(await isPostgresEmpty())) {
|
|
69
|
+
log.info('Postgres is no longer empty after acquiring migrate lock; skipping auto migration');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const exportDir = await mkdtemp(join(tmpdir(), 'openpeeps-arango-export-'));
|
|
73
|
+
log.info('Postgres is empty and Arango has data; starting automatic migration (export dir: %s)', exportDir);
|
|
74
|
+
try {
|
|
75
|
+
await exportArango(exportDir);
|
|
76
|
+
await importPostgres(exportDir, { closeConnection: false });
|
|
77
|
+
const result = await validateMigration(exportDir, {
|
|
78
|
+
closeConnection: false,
|
|
79
|
+
});
|
|
80
|
+
if (!result.ok) {
|
|
81
|
+
throw new Error(`Automatic Arango → Postgres migration failed validation (${result.issues.length} issue(s))`);
|
|
82
|
+
}
|
|
83
|
+
log.info('Automatic Arango → Postgres migration completed successfully');
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
failureDetail =
|
|
87
|
+
err instanceof Error
|
|
88
|
+
? `${err.message}\n${(_a = err.stack) !== null && _a !== void 0 ? _a : ''}`
|
|
89
|
+
: String(err);
|
|
90
|
+
log.error('Automatic Arango → Postgres migration failed:\n%s', failureDetail);
|
|
91
|
+
try {
|
|
92
|
+
// Keep the pool open until the advisory lock client is released.
|
|
93
|
+
await resetPostgresSchemas({ closePool: false });
|
|
94
|
+
log.warn('Wiped Postgres public + drizzle schemas after failed migration');
|
|
95
|
+
}
|
|
96
|
+
catch (wipeErr) {
|
|
97
|
+
log.error('Failed to wipe Postgres after auto-migration failure', wipeErr);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
await rm(exportDir, { recursive: true, force: true }).catch((err) => {
|
|
102
|
+
log.warn('Failed to remove temporary export directory %s', exportDir, err);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
if (failureDetail) {
|
|
107
|
+
await closePostgres();
|
|
108
|
+
await writeFailureMarker(failureDetail);
|
|
109
|
+
await idleForever('Automatic Arango → Postgres migration failed; Postgres was wiped and this process will idle. Redeploy/replace the container (or remove the ephemeral failure marker) to retry.');
|
|
110
|
+
}
|
|
111
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runCli: (argv?: string[]) => Promise<0 | 1>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { logger } from '../../log/index.js';
|
|
2
|
+
import { exportArango } from './exportArango.js';
|
|
3
|
+
import { importPostgres } from './importPostgres.js';
|
|
4
|
+
import { exportDirFromEnv } from './shared.js';
|
|
5
|
+
import { validateMigration } from './validate.js';
|
|
6
|
+
const log = logger('core:migration:cli');
|
|
7
|
+
const usage = () => {
|
|
8
|
+
console.log(`Usage: node dist/db/migration/cli.js <command>
|
|
9
|
+
|
|
10
|
+
Commands:
|
|
11
|
+
export Export ArangoDB collections to JSONL (DB_URL, DB_NAME)
|
|
12
|
+
import Import export into Postgres (DATABASE_URL)
|
|
13
|
+
validate Compare Postgres to import-stats.json (or export manifest) + checksums
|
|
14
|
+
|
|
15
|
+
Environment:
|
|
16
|
+
MIGRATION_EXPORT_DIR Export directory (default: ./arango-export)
|
|
17
|
+
DB_URL Arango server URL (default: http://localhost:8529)
|
|
18
|
+
DB_NAME Arango database name
|
|
19
|
+
DATABASE_URL Postgres connection string
|
|
20
|
+
`);
|
|
21
|
+
};
|
|
22
|
+
export const runCli = async (argv = process.argv.slice(2)) => {
|
|
23
|
+
const [command] = argv;
|
|
24
|
+
const exportDir = exportDirFromEnv();
|
|
25
|
+
switch (command) {
|
|
26
|
+
case 'export': {
|
|
27
|
+
await exportArango(exportDir);
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
case 'import': {
|
|
31
|
+
await importPostgres(exportDir);
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
case 'validate': {
|
|
35
|
+
const result = await validateMigration(exportDir);
|
|
36
|
+
return result.ok ? 0 : 1;
|
|
37
|
+
}
|
|
38
|
+
default:
|
|
39
|
+
usage();
|
|
40
|
+
if (command) {
|
|
41
|
+
log.error('Unknown command: %s', command);
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
runCli()
|
|
48
|
+
.then((code) => {
|
|
49
|
+
if (code !== 0) {
|
|
50
|
+
process.exitCode = code;
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
.catch((err) => {
|
|
54
|
+
log.error('Migration CLI failed', err);
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const isUndefinedTableError: (err: unknown) => boolean;
|
|
2
|
+
export declare const tableCount: (collection: string) => Promise<number>;
|
|
3
|
+
export declare const isPostgresEmpty: () => Promise<boolean>;
|
|
4
|
+
export { isUndefinedTableError };
|
|
5
|
+
export declare const isArangoAvailable: () => Promise<boolean>;
|
|
6
|
+
export declare const arangoHasSourceData: () => Promise<boolean>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { aql, Database } from 'arangojs';
|
|
2
|
+
import { getTableName, sql } from 'drizzle-orm';
|
|
3
|
+
import { logger } from '../../log/index.js';
|
|
4
|
+
import { pgDb } from '../pg/client.js';
|
|
5
|
+
import { getTableForCollection } from '../pg/map/registry.js';
|
|
6
|
+
import { connectArango } from './exportArango.js';
|
|
7
|
+
import { arangoConfig, DOCUMENT_IMPORT_ORDER, EDGE_IMPORT_ORDER, } from './shared.js';
|
|
8
|
+
const log = logger('core:migration:detect');
|
|
9
|
+
const ARANGO_SOURCE_COLLECTIONS = ['accounts', 'profiles', 'posts'];
|
|
10
|
+
const isUndefinedTableError = (err) => {
|
|
11
|
+
const candidates = [
|
|
12
|
+
err,
|
|
13
|
+
err && typeof err === 'object' && 'cause' in err
|
|
14
|
+
? err.cause
|
|
15
|
+
: undefined,
|
|
16
|
+
];
|
|
17
|
+
return candidates.some((candidate) => candidate &&
|
|
18
|
+
typeof candidate === 'object' &&
|
|
19
|
+
'code' in candidate &&
|
|
20
|
+
candidate.code === '42P01');
|
|
21
|
+
};
|
|
22
|
+
export const tableCount = async (collection) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const table = getTableForCollection(collection);
|
|
25
|
+
const tableName = getTableName(table);
|
|
26
|
+
const db = pgDb();
|
|
27
|
+
try {
|
|
28
|
+
const result = await db.execute(sql.raw(`SELECT COUNT(*)::text AS count FROM "${tableName}"`));
|
|
29
|
+
return Number((_b = (_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
// Missing table ⇒ treat as empty so callers can remigrate / auto-import.
|
|
33
|
+
if (isUndefinedTableError(err)) {
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const isPostgresEmpty = async () => {
|
|
40
|
+
for (const collection of [
|
|
41
|
+
...DOCUMENT_IMPORT_ORDER,
|
|
42
|
+
...EDGE_IMPORT_ORDER,
|
|
43
|
+
]) {
|
|
44
|
+
if ((await tableCount(collection)) > 0) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
50
|
+
export { isUndefinedTableError };
|
|
51
|
+
export const isArangoAvailable = async () => {
|
|
52
|
+
const config = arangoConfig();
|
|
53
|
+
const systemDb = new Database({ url: config.url, databaseName: '_system' });
|
|
54
|
+
try {
|
|
55
|
+
return Boolean(await systemDb.availability());
|
|
56
|
+
}
|
|
57
|
+
catch (_a) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export const arangoHasSourceData = async () => {
|
|
62
|
+
if (!(await isArangoAvailable())) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const config = arangoConfig();
|
|
66
|
+
if (config.databaseName) {
|
|
67
|
+
const systemDb = new Database(Object.assign(Object.assign({}, config), { databaseName: '_system' }));
|
|
68
|
+
if (!(await systemDb.database(config.databaseName).exists())) {
|
|
69
|
+
log.info('Arango database %s does not exist; skipping auto migration', config.databaseName);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const db = connectArango();
|
|
74
|
+
for (const collectionName of ARANGO_SOURCE_COLLECTIONS) {
|
|
75
|
+
if (!(await db.collection(collectionName).exists())) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const cursor = await db.query(aql `
|
|
79
|
+
RETURN LENGTH(FOR doc IN ${db.collection(collectionName)} LIMIT 1 RETURN 1)
|
|
80
|
+
`);
|
|
81
|
+
const hasDocuments = (await cursor.next()) === 1;
|
|
82
|
+
if (hasDocuments) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
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 { appendFile, mkdir, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { aql, Database } from 'arangojs';
|
|
11
|
+
import { collectionInfos } from '../pg/collections.js';
|
|
12
|
+
import { logger } from '../../log/index.js';
|
|
13
|
+
import { arangoConfig, collectionFilePath, collectionsDir, exportDirFromEnv, sortedChecksum, writeManifest, } from './shared.js';
|
|
14
|
+
const log = logger('core:migration:export');
|
|
15
|
+
export const connectArango = () => new Database(arangoConfig());
|
|
16
|
+
export const exportArango = async (exportDir = exportDirFromEnv()) => {
|
|
17
|
+
var _a, e_1, _b, _c;
|
|
18
|
+
var _d;
|
|
19
|
+
const config = arangoConfig();
|
|
20
|
+
const db = connectArango();
|
|
21
|
+
log.info('Exporting ArangoDB from %s (database: %s)', config.url, (_d = config.databaseName) !== null && _d !== void 0 ? _d : 'default');
|
|
22
|
+
await mkdir(collectionsDir(exportDir), { recursive: true });
|
|
23
|
+
await writeFile(join(exportDir, 'collectionInfos.json'), JSON.stringify(collectionInfos, null, 2));
|
|
24
|
+
const collections = {};
|
|
25
|
+
const accountEmails = [];
|
|
26
|
+
const postIds = [];
|
|
27
|
+
for (const collectionInfo of Object.values(collectionInfos)) {
|
|
28
|
+
const collectionName = collectionInfo.name;
|
|
29
|
+
const filePath = collectionFilePath(exportDir, collectionName);
|
|
30
|
+
if (!(await db.collection(collectionName).exists())) {
|
|
31
|
+
log.info('Skipping missing collection %s', collectionName);
|
|
32
|
+
collections[collectionName] = 0;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
log.info('Exporting collection %s', collectionName);
|
|
36
|
+
let count = 0;
|
|
37
|
+
const cursor = await db.query(aql `
|
|
38
|
+
FOR doc IN ${db.collection(collectionName)}
|
|
39
|
+
RETURN doc
|
|
40
|
+
`);
|
|
41
|
+
try {
|
|
42
|
+
for (var _e = true, cursor_1 = (e_1 = void 0, __asyncValues(cursor)), cursor_1_1; cursor_1_1 = await cursor_1.next(), _a = cursor_1_1.done, !_a; _e = true) {
|
|
43
|
+
_c = cursor_1_1.value;
|
|
44
|
+
_e = false;
|
|
45
|
+
const doc = _c;
|
|
46
|
+
const record = doc;
|
|
47
|
+
await appendFile(filePath, `${JSON.stringify(record)}\n`);
|
|
48
|
+
count++;
|
|
49
|
+
if (collectionName === 'accounts' && typeof record.email === 'string') {
|
|
50
|
+
accountEmails.push(record.email);
|
|
51
|
+
}
|
|
52
|
+
if (collectionName === 'posts' && typeof record._key === 'string') {
|
|
53
|
+
postIds.push(record._key);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
58
|
+
finally {
|
|
59
|
+
try {
|
|
60
|
+
if (!_e && !_a && (_b = cursor_1.return)) await _b.call(cursor_1);
|
|
61
|
+
}
|
|
62
|
+
finally { if (e_1) throw e_1.error; }
|
|
63
|
+
}
|
|
64
|
+
collections[collectionName] = count;
|
|
65
|
+
log.info('Exported %d documents from %s', count, collectionName);
|
|
66
|
+
}
|
|
67
|
+
const manifest = {
|
|
68
|
+
exportedAt: new Date().toISOString(),
|
|
69
|
+
dbUrl: config.url,
|
|
70
|
+
dbName: config.databaseName,
|
|
71
|
+
collections,
|
|
72
|
+
checksums: {
|
|
73
|
+
accountEmails: sortedChecksum(accountEmails),
|
|
74
|
+
postIds: sortedChecksum(postIds),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
await writeManifest(exportDir, manifest);
|
|
78
|
+
log.info('Export complete: %s', exportDir);
|
|
79
|
+
return manifest;
|
|
80
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ImportContext } from './transform';
|
|
2
|
+
/** Arango exports can contain duplicate _key lines; keep the last row per id. */
|
|
3
|
+
export declare const dedupeRowsById: <T extends Record<string, unknown>>(rows: T[]) => T[];
|
|
4
|
+
export declare const collectionJsonlPath: (collectionsDir: string, collection: string) => string;
|
|
5
|
+
export declare const truncateAllTables: () => Promise<void>;
|
|
6
|
+
export declare const isUuid: (value: unknown) => value is string;
|
|
7
|
+
/** Collapse empty / duplicate hashtag names onto one row (unique on name). */
|
|
8
|
+
export declare const prepareHashtagRows: (rows: Record<string, unknown>[], context: ImportContext) => Record<string, unknown>[];
|
|
9
|
+
export declare const importArangoCollection: (collection: string, collectionsDir: string, context?: ImportContext) => Promise<number>;
|
|
10
|
+
export declare const importPostgresRowCollection: (collection: string, collectionsDir: string) => Promise<number>;
|
|
11
|
+
export declare const importAllArangoCollections: (collectionsDir: string) => Promise<{
|
|
12
|
+
imported: Record<string, number>;
|
|
13
|
+
total: number;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const importAllPostgresCollections: (collectionsDir: string) => Promise<{
|
|
16
|
+
imported: Record<string, number>;
|
|
17
|
+
total: number;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const exportAllPostgresCollections: (collectionsDir: string) => Promise<void>;
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { appendFile, access } from 'node:fs/promises';
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { getTableName, sql } from 'drizzle-orm';
|
|
6
|
+
import { logger } from '../../log/index.js';
|
|
7
|
+
import { pgDb } from '../pg/client.js';
|
|
8
|
+
import { runMigrations } from '../pg/migrate.js';
|
|
9
|
+
import { documentRegistry, edgeRegistry, getTableForCollection, } from '../pg/map/registry.js';
|
|
10
|
+
import { arangoDocToDocumentRow, arangoDocToEdgeRow, buildPostCreatorIdByPostId, isEdgeCollection, normalizeImportId, } from './transform.js';
|
|
11
|
+
import { BATCH_SIZE, DOCUMENT_IMPORT_ORDER, EDGE_IMPORT_ORDER, readJsonl, } from './shared.js';
|
|
12
|
+
const log = logger('core:db:import');
|
|
13
|
+
const rowDedupeKey = (row) => { var _a; return normalizeImportId((_a = row.id) !== null && _a !== void 0 ? _a : row.key); };
|
|
14
|
+
/** Arango exports can contain duplicate _key lines; keep the last row per id. */
|
|
15
|
+
export const dedupeRowsById = (rows) => {
|
|
16
|
+
const byKey = new Map();
|
|
17
|
+
const withoutKey = [];
|
|
18
|
+
for (const row of rows) {
|
|
19
|
+
const key = rowDedupeKey(row);
|
|
20
|
+
if (key) {
|
|
21
|
+
byKey.set(key, typeof row.id === 'string' ? Object.assign(Object.assign({}, row), { id: key }) : row);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
withoutKey.push(row);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return [...byKey.values(), ...withoutKey];
|
|
28
|
+
};
|
|
29
|
+
export const collectionJsonlPath = (collectionsDir, collection) => join(collectionsDir, `${collection}.jsonl`);
|
|
30
|
+
const isKnownCollection = (collection) => collection in documentRegistry || collection in edgeRegistry;
|
|
31
|
+
export const truncateAllTables = async () => {
|
|
32
|
+
var _a;
|
|
33
|
+
const db = pgDb();
|
|
34
|
+
const tableNames = [
|
|
35
|
+
...EDGE_IMPORT_ORDER.map((collection) => getTableName(edgeRegistry[collection].table)),
|
|
36
|
+
...[...DOCUMENT_IMPORT_ORDER]
|
|
37
|
+
.reverse()
|
|
38
|
+
.map((collection) => getTableName(documentRegistry[collection].table)),
|
|
39
|
+
];
|
|
40
|
+
const existing = [];
|
|
41
|
+
for (const name of tableNames) {
|
|
42
|
+
const result = await db.execute(sql.raw(`SELECT to_regclass('public.${name}')::text AS regclass`));
|
|
43
|
+
if (((_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.regclass) != null) {
|
|
44
|
+
existing.push(name);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (existing.length === 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await db.execute(sql.raw(`TRUNCATE TABLE ${existing.map((name) => `"${name}"`).join(', ')} RESTART IDENTITY CASCADE`));
|
|
51
|
+
};
|
|
52
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
53
|
+
export const isUuid = (value) => typeof value === 'string' && UUID_RE.test(value);
|
|
54
|
+
/**
|
|
55
|
+
* Edge `id` columns are uuid. Legacy Arango edge `_key`s are sometimes numeric
|
|
56
|
+
* (or otherwise non-UUID); replace those so the insert does not fail. Document
|
|
57
|
+
* collections are left alone (`data_migrations.id` is text, not uuid).
|
|
58
|
+
*/
|
|
59
|
+
const ensureEdgeUuidId = (collection, row) => {
|
|
60
|
+
var _a;
|
|
61
|
+
if (!isEdgeCollection(collection)) {
|
|
62
|
+
return row;
|
|
63
|
+
}
|
|
64
|
+
if (isUuid(row.id)) {
|
|
65
|
+
const normalized = (_a = normalizeImportId(row.id)) !== null && _a !== void 0 ? _a : String(row.id);
|
|
66
|
+
return normalized === row.id ? row : Object.assign(Object.assign({}, row), { id: normalized });
|
|
67
|
+
}
|
|
68
|
+
const next = Object.assign(Object.assign({}, row), { id: randomUUID() });
|
|
69
|
+
log.warn('Replaced non-UUID %s edge id %s with %s', collection, String(row.id), next.id);
|
|
70
|
+
return next;
|
|
71
|
+
};
|
|
72
|
+
const documentRowIsImportable = (collection, row) => {
|
|
73
|
+
if (collection === 'posts' && !row.creatorId) {
|
|
74
|
+
log.warn('Skipping post %s: missing creatorId', row.id);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (collection === 'jamEvents' && !row.postId) {
|
|
78
|
+
log.warn('Skipping jam event %s: missing postId', row.id);
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (collection === 'profileSettings' && !row.profileId) {
|
|
82
|
+
log.warn('Skipping profile settings %s: missing profileId', row.id);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
};
|
|
87
|
+
/** Collapse empty / duplicate hashtag names onto one row (unique on name). */
|
|
88
|
+
export const prepareHashtagRows = (rows, context) => {
|
|
89
|
+
var _a;
|
|
90
|
+
const remap = (_a = context.hashtagIdRemap) !== null && _a !== void 0 ? _a : new Map();
|
|
91
|
+
context.hashtagIdRemap = remap;
|
|
92
|
+
const byName = new Map();
|
|
93
|
+
const prepared = [];
|
|
94
|
+
for (const row of rows) {
|
|
95
|
+
const id = typeof row.id === 'string' ? row.id : undefined;
|
|
96
|
+
const name = typeof row.name === 'string' ? row.name.trim().toLowerCase() : '';
|
|
97
|
+
if (!name) {
|
|
98
|
+
if (id)
|
|
99
|
+
remap.set(id, '');
|
|
100
|
+
log.warn('Skipping hashtag %s: empty name', id !== null && id !== void 0 ? id : '(no id)');
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
row.name = name;
|
|
104
|
+
const existing = byName.get(name);
|
|
105
|
+
if (existing) {
|
|
106
|
+
const keptId = typeof existing.id === 'string' ? existing.id : '';
|
|
107
|
+
if (id)
|
|
108
|
+
remap.set(id, keptId);
|
|
109
|
+
log.warn('Skipping duplicate hashtag name "%s" (id %s → %s)', name, id, keptId || '(unknown)');
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
byName.set(name, row);
|
|
113
|
+
prepared.push(row);
|
|
114
|
+
}
|
|
115
|
+
return prepared;
|
|
116
|
+
};
|
|
117
|
+
const applyHashtagEdgeRemap = (collection, rows, context) => {
|
|
118
|
+
var _a;
|
|
119
|
+
if (collection !== 'postHashtags' || !((_a = context.hashtagIdRemap) === null || _a === void 0 ? void 0 : _a.size)) {
|
|
120
|
+
return rows;
|
|
121
|
+
}
|
|
122
|
+
const remap = context.hashtagIdRemap;
|
|
123
|
+
const out = [];
|
|
124
|
+
let dropped = 0;
|
|
125
|
+
for (const row of rows) {
|
|
126
|
+
const toId = typeof row.toId === 'string' ? row.toId : undefined;
|
|
127
|
+
if (!toId || !remap.has(toId)) {
|
|
128
|
+
out.push(row);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const mapped = remap.get(toId);
|
|
132
|
+
if (!mapped) {
|
|
133
|
+
dropped += 1;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
out.push(Object.assign(Object.assign({}, row), { toId: mapped }));
|
|
137
|
+
}
|
|
138
|
+
if (dropped > 0) {
|
|
139
|
+
log.warn('Dropped %d postHashtags edge(s) pointing at skipped hashtags', dropped);
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
};
|
|
143
|
+
export const importArangoCollection = async (collection, collectionsDir, context = {}) => {
|
|
144
|
+
if (!isKnownCollection(collection)) {
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
const filePath = collectionJsonlPath(collectionsDir, collection);
|
|
148
|
+
try {
|
|
149
|
+
await access(filePath, constants.F_OK);
|
|
150
|
+
}
|
|
151
|
+
catch (_a) {
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
const docs = await readJsonl(filePath);
|
|
155
|
+
if (docs.length === 0) {
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
const table = getTableForCollection(collection);
|
|
159
|
+
const db = pgDb();
|
|
160
|
+
let mapped = docs.map((doc) => isEdgeCollection(collection)
|
|
161
|
+
? arangoDocToEdgeRow(collection, doc)
|
|
162
|
+
: arangoDocToDocumentRow(collection, doc, context));
|
|
163
|
+
if (collection === 'hashtags') {
|
|
164
|
+
mapped = prepareHashtagRows(mapped, context);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
mapped = mapped.filter((row) => documentRowIsImportable(collection, row));
|
|
168
|
+
}
|
|
169
|
+
mapped = applyHashtagEdgeRemap(collection, mapped, context);
|
|
170
|
+
mapped = mapped.map((row) => ensureEdgeUuidId(collection, row));
|
|
171
|
+
const beforeDedupe = mapped.length;
|
|
172
|
+
const rows = dedupeRowsById(mapped);
|
|
173
|
+
if (rows.length < beforeDedupe) {
|
|
174
|
+
log.warn('Dropped %d duplicate row(s) while importing %s (e.g. remapped config keys or duplicate _key)', beforeDedupe - rows.length, collection);
|
|
175
|
+
}
|
|
176
|
+
if (rows.length === 0) {
|
|
177
|
+
return 0;
|
|
178
|
+
}
|
|
179
|
+
let imported = 0;
|
|
180
|
+
for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) {
|
|
181
|
+
const batch = rows.slice(offset, offset + BATCH_SIZE);
|
|
182
|
+
try {
|
|
183
|
+
await db.insert(table).values(batch);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
const cause = err && typeof err === 'object' && 'cause' in err
|
|
187
|
+
? err.cause
|
|
188
|
+
: undefined;
|
|
189
|
+
const detail = cause instanceof Error
|
|
190
|
+
? cause.message
|
|
191
|
+
: err instanceof Error
|
|
192
|
+
? err.message
|
|
193
|
+
: String(err);
|
|
194
|
+
throw new Error(`Failed importing ${collection} batch at offset ${offset} (${batch.length} rows): ${detail}`);
|
|
195
|
+
}
|
|
196
|
+
imported += batch.length;
|
|
197
|
+
}
|
|
198
|
+
log.info('Imported %d rows into %s from Arango JSONL', imported, collection);
|
|
199
|
+
return imported;
|
|
200
|
+
};
|
|
201
|
+
export const importPostgresRowCollection = async (collection, collectionsDir) => {
|
|
202
|
+
if (!isKnownCollection(collection)) {
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
const filePath = collectionJsonlPath(collectionsDir, collection);
|
|
206
|
+
try {
|
|
207
|
+
await access(filePath, constants.F_OK);
|
|
208
|
+
}
|
|
209
|
+
catch (_a) {
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
const mapped = await readJsonl(filePath);
|
|
213
|
+
if (mapped.length === 0) {
|
|
214
|
+
return 0;
|
|
215
|
+
}
|
|
216
|
+
const withValidIds = mapped.map((row) => ensureEdgeUuidId(collection, row));
|
|
217
|
+
const rows = dedupeRowsById(withValidIds);
|
|
218
|
+
if (rows.length < mapped.length) {
|
|
219
|
+
log.warn('Dropped %d duplicate row(s) while importing %s', mapped.length - rows.length, collection);
|
|
220
|
+
}
|
|
221
|
+
const table = getTableForCollection(collection);
|
|
222
|
+
const db = pgDb();
|
|
223
|
+
let imported = 0;
|
|
224
|
+
for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) {
|
|
225
|
+
const batch = rows.slice(offset, offset + BATCH_SIZE);
|
|
226
|
+
await db.insert(table).values(batch);
|
|
227
|
+
imported += batch.length;
|
|
228
|
+
}
|
|
229
|
+
log.info('Imported %d rows into %s from Postgres JSONL', imported, collection);
|
|
230
|
+
return imported;
|
|
231
|
+
};
|
|
232
|
+
const sumImported = (imported) => Object.values(imported).reduce((sum, count) => sum + count, 0);
|
|
233
|
+
export const importAllArangoCollections = async (collectionsDir) => {
|
|
234
|
+
await runMigrations();
|
|
235
|
+
await truncateAllTables();
|
|
236
|
+
const imported = {};
|
|
237
|
+
const context = {
|
|
238
|
+
postCreatorIdByPostId: await buildPostCreatorIdByPostId(collectionsDir),
|
|
239
|
+
hashtagIdRemap: new Map(),
|
|
240
|
+
};
|
|
241
|
+
for (const collection of DOCUMENT_IMPORT_ORDER) {
|
|
242
|
+
imported[collection] = await importArangoCollection(collection, collectionsDir, context);
|
|
243
|
+
}
|
|
244
|
+
for (const collection of EDGE_IMPORT_ORDER) {
|
|
245
|
+
imported[collection] = await importArangoCollection(collection, collectionsDir, context);
|
|
246
|
+
}
|
|
247
|
+
const total = sumImported(imported);
|
|
248
|
+
log.info('Arango JSONL import complete: %d rows across %d collections', total, Object.keys(imported).filter((key) => imported[key] > 0).length);
|
|
249
|
+
return { imported, total };
|
|
250
|
+
};
|
|
251
|
+
export const importAllPostgresCollections = async (collectionsDir) => {
|
|
252
|
+
await runMigrations();
|
|
253
|
+
await truncateAllTables();
|
|
254
|
+
const imported = {};
|
|
255
|
+
for (const collection of DOCUMENT_IMPORT_ORDER) {
|
|
256
|
+
imported[collection] = await importPostgresRowCollection(collection, collectionsDir);
|
|
257
|
+
}
|
|
258
|
+
for (const collection of EDGE_IMPORT_ORDER) {
|
|
259
|
+
imported[collection] = await importPostgresRowCollection(collection, collectionsDir);
|
|
260
|
+
}
|
|
261
|
+
const total = sumImported(imported);
|
|
262
|
+
log.info('Postgres JSONL import complete: %d rows across %d collections', total, Object.keys(imported).filter((key) => imported[key] > 0).length);
|
|
263
|
+
return { imported, total };
|
|
264
|
+
};
|
|
265
|
+
export const exportAllPostgresCollections = async (collectionsDir) => {
|
|
266
|
+
const db = pgDb();
|
|
267
|
+
const collections = [...DOCUMENT_IMPORT_ORDER, ...EDGE_IMPORT_ORDER];
|
|
268
|
+
for (const collection of collections) {
|
|
269
|
+
const table = getTableForCollection(collection);
|
|
270
|
+
const rows = await db.select().from(table);
|
|
271
|
+
if (rows.length === 0) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const filePath = collectionJsonlPath(collectionsDir, collection);
|
|
275
|
+
for (const row of rows) {
|
|
276
|
+
await appendFile(filePath, `${JSON.stringify(row)}\n`);
|
|
277
|
+
}
|
|
278
|
+
log.info('Exported %d rows from %s', rows.length, collection);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { logger } from '../../log/index.js';
|
|
2
|
+
import { closePostgres } from '../pg/client.js';
|
|
3
|
+
import { assertExportDir, collectionsDir, exportDirFromEnv, readManifest, writeImportStats, } from './shared.js';
|
|
4
|
+
import { importAllArangoCollections } from './importCollections.js';
|
|
5
|
+
const log = logger('core:migration:import');
|
|
6
|
+
export const importPostgres = async (exportDir = exportDirFromEnv(), options = {}) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const closeConnection = (_a = options.closeConnection) !== null && _a !== void 0 ? _a : true;
|
|
9
|
+
await assertExportDir(exportDir);
|
|
10
|
+
const manifest = await readManifest(exportDir);
|
|
11
|
+
log.info('Importing export from %s (exported %s)', exportDir, manifest.exportedAt);
|
|
12
|
+
const { imported } = await importAllArangoCollections(collectionsDir(exportDir));
|
|
13
|
+
await writeImportStats(exportDir, imported);
|
|
14
|
+
if (closeConnection) {
|
|
15
|
+
await closePostgres();
|
|
16
|
+
}
|
|
17
|
+
return imported;
|
|
18
|
+
};
|