@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,566 @@
|
|
|
1
|
+
import { and, asc, desc, eq, gt, gte, isNull, lt, lte, ne, or, sql, } from 'drizzle-orm';
|
|
2
|
+
import { checkCapabilities, mergeCapabilities } from '@openpeepshq/common/lib';
|
|
3
|
+
import { isSqlFilter } from '../filters/index.js';
|
|
4
|
+
import { groupLastPostAtExpr, postActivityScoreExpr, postReplyCountExpr, postReplyToCountExpr, profileActivityScoreExpr, } from '../queries/activity.js';
|
|
5
|
+
import { asTable, edgeRegistry, getCollectionConfig, parseDocRef, } from './registry.js';
|
|
6
|
+
const SCALAR_COLUMNS = {
|
|
7
|
+
accounts: ['email', 'passwordHash', 'emailValidated', 'guest'],
|
|
8
|
+
profiles: ['handle', 'type', 'activityPubDomain'],
|
|
9
|
+
posts: ['type', 'visibility', 'creatorId'],
|
|
10
|
+
groups: ['handle'],
|
|
11
|
+
hashtags: ['name'],
|
|
12
|
+
roles: ['key', 'isDefault'],
|
|
13
|
+
notifications: ['profileId'],
|
|
14
|
+
jamEvents: ['postId'],
|
|
15
|
+
processingStats: ['filetype', 'filesize'],
|
|
16
|
+
profileSettings: ['profileId'],
|
|
17
|
+
inviteLinks: ['slug'],
|
|
18
|
+
};
|
|
19
|
+
const getPath = (obj, path) => {
|
|
20
|
+
const parts = path.replace(/\[['"]?(\w+)['"]?\]/g, '.$1').split('.');
|
|
21
|
+
let current = obj;
|
|
22
|
+
for (const part of parts) {
|
|
23
|
+
if (current == null || typeof current !== 'object')
|
|
24
|
+
return undefined;
|
|
25
|
+
current = current[part];
|
|
26
|
+
}
|
|
27
|
+
return current;
|
|
28
|
+
};
|
|
29
|
+
const normalizeAqlExpression = (expression) => expression
|
|
30
|
+
.replace(/DOC\./g, 'doc.')
|
|
31
|
+
.replace(/\band\b/gi, '&&')
|
|
32
|
+
.replace(/\bor\b/gi, '||')
|
|
33
|
+
.replace(/==/g, '===')
|
|
34
|
+
.replace(/!=/g, '!==')
|
|
35
|
+
.replace(/DATE_TIMESTAMP\(([^)]+)\)/g, 'new Date($1).getTime()')
|
|
36
|
+
.replace(/LENGTH\(([^)]+)\)/g, '(Array.isArray($1) ? $1.length : 0)');
|
|
37
|
+
export const evaluateStringFilter = (doc, expression) => {
|
|
38
|
+
if (!expression)
|
|
39
|
+
return true;
|
|
40
|
+
try {
|
|
41
|
+
const fn = new Function('doc', 'CHECK_CAPABILITIES', 'MERGE_CAPABILITIES', `return ${normalizeAqlExpression(expression)};`);
|
|
42
|
+
return Boolean(fn(doc, checkCapabilities, mergeCapabilities));
|
|
43
|
+
}
|
|
44
|
+
catch (_a) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
export const evaluateFilter = (doc, filter) => {
|
|
49
|
+
if (!filter)
|
|
50
|
+
return true;
|
|
51
|
+
if (isSqlFilter(filter))
|
|
52
|
+
return true;
|
|
53
|
+
if (typeof filter === 'string') {
|
|
54
|
+
return evaluateStringFilter(doc, filter);
|
|
55
|
+
}
|
|
56
|
+
if ('operator' in filter) {
|
|
57
|
+
const preds = filter.predicates.map((p) => {
|
|
58
|
+
if (isSqlFilter(p))
|
|
59
|
+
return true;
|
|
60
|
+
return evaluateFilter(doc, p);
|
|
61
|
+
});
|
|
62
|
+
return filter.operator === '&&'
|
|
63
|
+
? preds.every(Boolean)
|
|
64
|
+
: preds.some(Boolean);
|
|
65
|
+
}
|
|
66
|
+
if ('matches' in filter) {
|
|
67
|
+
const matches = Array.isArray(filter.matches)
|
|
68
|
+
? filter.matches
|
|
69
|
+
: [filter.matches];
|
|
70
|
+
return matches.some((match) => Object.entries(match).every(([key, value]) => {
|
|
71
|
+
const field = key === '_key' ? 'id' : key;
|
|
72
|
+
if (field === '_from' || field === '_to') {
|
|
73
|
+
const parsed = typeof value === 'string' ? parseDocRef(value) : undefined;
|
|
74
|
+
if (parsed) {
|
|
75
|
+
const docRef = getPath(doc, field);
|
|
76
|
+
const docParsed = docRef ? parseDocRef(docRef) : undefined;
|
|
77
|
+
return (docParsed === null || docParsed === void 0 ? void 0 : docParsed.id) === parsed.id;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return getPath(doc, field) === value;
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
const bodyColumn = (table) => table.body;
|
|
86
|
+
const postsReplyCountSql = (table) => postReplyCountExpr(table);
|
|
87
|
+
const docFieldSql = (collection, table, fieldPath) => {
|
|
88
|
+
const t = asTable(table);
|
|
89
|
+
if (fieldPath === '_key' || fieldPath === 'id')
|
|
90
|
+
return sql `${t.id}`;
|
|
91
|
+
if (fieldPath === 'createdAt' && t.createdAt)
|
|
92
|
+
return sql `${t.createdAt}`;
|
|
93
|
+
if (fieldPath === 'updatedAt' && t.updatedAt)
|
|
94
|
+
return sql `${t.updatedAt}`;
|
|
95
|
+
if (fieldPath === '_from' && t.fromId)
|
|
96
|
+
return sql `${t.fromId}`;
|
|
97
|
+
if (fieldPath === '_to' && t.toId)
|
|
98
|
+
return sql `${t.toId}`;
|
|
99
|
+
const scalars = SCALAR_COLUMNS[collection];
|
|
100
|
+
if (scalars === null || scalars === void 0 ? void 0 : scalars.includes(fieldPath))
|
|
101
|
+
return sql `${t[fieldPath]}`;
|
|
102
|
+
let jsonPath = fieldPath;
|
|
103
|
+
if (collection === 'posts' && jsonPath.startsWith('data.')) {
|
|
104
|
+
jsonPath = jsonPath.slice(5);
|
|
105
|
+
}
|
|
106
|
+
if (!t.body)
|
|
107
|
+
return undefined;
|
|
108
|
+
const parts = jsonPath.split('.');
|
|
109
|
+
if (parts.length === 1) {
|
|
110
|
+
return sql `${bodyColumn(t)}->>${parts[0]}`;
|
|
111
|
+
}
|
|
112
|
+
const head = parts
|
|
113
|
+
.slice(0, -1)
|
|
114
|
+
.map((part) => `'${part}'`)
|
|
115
|
+
.join('->');
|
|
116
|
+
return sql `${bodyColumn(t)}->${sql.raw(head)}->>${parts[parts.length - 1]}`;
|
|
117
|
+
};
|
|
118
|
+
const docFieldJsonSql = (collection, table, fieldPath) => {
|
|
119
|
+
const t = asTable(table);
|
|
120
|
+
let jsonPath = fieldPath;
|
|
121
|
+
if (collection === 'posts' && jsonPath.startsWith('data.')) {
|
|
122
|
+
jsonPath = jsonPath.slice(5);
|
|
123
|
+
}
|
|
124
|
+
if (!t.body)
|
|
125
|
+
return undefined;
|
|
126
|
+
const parts = jsonPath.split('.');
|
|
127
|
+
if (parts.length === 1) {
|
|
128
|
+
return sql `${bodyColumn(t)}->${parts[0]}`;
|
|
129
|
+
}
|
|
130
|
+
const path = parts.map((part) => `'${part}'`).join('->');
|
|
131
|
+
return sql `${bodyColumn(t)}->${sql.raw(path)}`;
|
|
132
|
+
};
|
|
133
|
+
const parseLiteral = (raw) => {
|
|
134
|
+
const trimmed = raw.trim();
|
|
135
|
+
if (trimmed === 'null')
|
|
136
|
+
return null;
|
|
137
|
+
if (trimmed === 'true')
|
|
138
|
+
return true;
|
|
139
|
+
if (trimmed === 'false')
|
|
140
|
+
return false;
|
|
141
|
+
if (/^-?\d+(\.\d+)?$/.test(trimmed))
|
|
142
|
+
return Number(trimmed);
|
|
143
|
+
const quoted = (trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
144
|
+
(trimmed.startsWith("'") && trimmed.endsWith("'"));
|
|
145
|
+
if (quoted)
|
|
146
|
+
return trimmed.slice(1, -1);
|
|
147
|
+
return trimmed;
|
|
148
|
+
};
|
|
149
|
+
const compareSql = (left, op, value) => {
|
|
150
|
+
switch (op) {
|
|
151
|
+
case '==':
|
|
152
|
+
return value === null ? sql `${left} IS NULL` : eq(left, value);
|
|
153
|
+
case '!=':
|
|
154
|
+
return value === null ? sql `${left} IS NOT NULL` : ne(left, value);
|
|
155
|
+
case '>':
|
|
156
|
+
return gt(left, value);
|
|
157
|
+
case '>=':
|
|
158
|
+
return gte(left, value);
|
|
159
|
+
case '<':
|
|
160
|
+
return lt(left, value);
|
|
161
|
+
case '<=':
|
|
162
|
+
return lte(left, value);
|
|
163
|
+
default:
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const unwrapParens = (expression) => {
|
|
168
|
+
let expr = expression.trim();
|
|
169
|
+
while (expr.startsWith('(') && expr.endsWith(')')) {
|
|
170
|
+
let depth = 0;
|
|
171
|
+
let closed = true;
|
|
172
|
+
for (let i = 0; i < expr.length; i++) {
|
|
173
|
+
if (expr[i] === '(')
|
|
174
|
+
depth++;
|
|
175
|
+
if (expr[i] === ')')
|
|
176
|
+
depth--;
|
|
177
|
+
if (depth === 0 && i < expr.length - 1) {
|
|
178
|
+
closed = false;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!closed)
|
|
183
|
+
break;
|
|
184
|
+
expr = expr.slice(1, -1).trim();
|
|
185
|
+
}
|
|
186
|
+
return expr;
|
|
187
|
+
};
|
|
188
|
+
const splitTopLevel = (expression, separator) => {
|
|
189
|
+
const parts = [];
|
|
190
|
+
let depth = 0;
|
|
191
|
+
let start = 0;
|
|
192
|
+
for (let i = 0; i < expression.length; i++) {
|
|
193
|
+
const ch = expression[i];
|
|
194
|
+
if (ch === '(')
|
|
195
|
+
depth++;
|
|
196
|
+
else if (ch === ')')
|
|
197
|
+
depth--;
|
|
198
|
+
else if (depth === 0 && expression.startsWith(separator, i)) {
|
|
199
|
+
parts.push(expression.slice(start, i).trim());
|
|
200
|
+
start = i + separator.length;
|
|
201
|
+
i += separator.length - 1;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
parts.push(expression.slice(start).trim());
|
|
205
|
+
return parts.filter(Boolean);
|
|
206
|
+
};
|
|
207
|
+
const createdAtRangeSql = (table, expression) => {
|
|
208
|
+
const t = asTable(table);
|
|
209
|
+
const range = expression.match(/DATE_TIMESTAMP\(DOC\.createdAt\)\s*>=\s*(\d+).*DATE_TIMESTAMP\(DOC\.createdAt\)\s*<\s*(\d+)/);
|
|
210
|
+
if (range) {
|
|
211
|
+
return and(gte(t.createdAt, new Date(Number(range[1])).toISOString()), lt(t.createdAt, new Date(Number(range[2])).toISOString()));
|
|
212
|
+
}
|
|
213
|
+
const startOnly = expression.match(/DATE_TIMESTAMP\(DOC\.createdAt\)\s*>=\s*(\d+)/);
|
|
214
|
+
if (startOnly) {
|
|
215
|
+
return gte(t.createdAt, new Date(Number(startOnly[1])).toISOString());
|
|
216
|
+
}
|
|
217
|
+
const endOnly = expression.match(/DATE_TIMESTAMP\(DOC\.createdAt\)\s*<\s*(\d+)/);
|
|
218
|
+
if (endOnly) {
|
|
219
|
+
return lt(t.createdAt, new Date(Number(endOnly[1])).toISOString());
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
};
|
|
223
|
+
const eventFilterSql = (collection, table, expression) => {
|
|
224
|
+
if (collection !== 'posts')
|
|
225
|
+
return undefined;
|
|
226
|
+
const t = asTable(table);
|
|
227
|
+
const body = bodyColumn(t);
|
|
228
|
+
const past = expression.match(/^\(DOC\.data\.end \|\| DOC\.data\.start\)\s*<\s*['"]([^'"]+)['"]$/);
|
|
229
|
+
if (past) {
|
|
230
|
+
return sql `COALESCE(${body}->>'end', ${body}->>'start') < ${past[1]}`;
|
|
231
|
+
}
|
|
232
|
+
const upcoming = expression.match(/^\(\(DOC\.data\.start\s*>\s*['"]([^'"]+)['"]\)\s*\|\|\s*\(DOC\.data\.end && DOC\.data\.end\s*>\s*['"]\1['"]\)\)$/);
|
|
233
|
+
if (upcoming) {
|
|
234
|
+
const now = upcoming[1];
|
|
235
|
+
return or(sql `${body}->>'start' > ${now}`, and(sql `${body}->'end' IS NOT NULL`, sql `${body}->>'end' > ${now}`));
|
|
236
|
+
}
|
|
237
|
+
const current = expression.match(/^DOC\.data\.start\s*<=\s*['"]([^'"]+)['"]\s*&&\s*\(!DOC\.data\.end \|\| DOC\.data\.end\s*>=\s*['"]\1['"]\)$/);
|
|
238
|
+
if (current) {
|
|
239
|
+
const now = current[1];
|
|
240
|
+
return and(sql `${body}->>'start' <= ${now}`, or(sql `${body}->'end' IS NULL`, sql `${body}->>'end' >= ${now}`));
|
|
241
|
+
}
|
|
242
|
+
return undefined;
|
|
243
|
+
};
|
|
244
|
+
const singleStringFilterToSql = (collection, table, expression) => {
|
|
245
|
+
const expr = unwrapParens(expression);
|
|
246
|
+
if (!expr || expr.includes(' FOR ')) {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
const dateRange = createdAtRangeSql(table, expr);
|
|
250
|
+
if (dateRange)
|
|
251
|
+
return dateRange;
|
|
252
|
+
const eventFilter = eventFilterSql(collection, table, expr);
|
|
253
|
+
if (eventFilter)
|
|
254
|
+
return eventFilter;
|
|
255
|
+
const negation = expr.match(/^!DOC\.([a-zA-Z0-9_.]+)$/);
|
|
256
|
+
if (negation) {
|
|
257
|
+
const fieldPath = negation[1];
|
|
258
|
+
if (fieldPath === 'seen' || fieldPath === 'read') {
|
|
259
|
+
const field = docFieldSql(collection, table, fieldPath);
|
|
260
|
+
return field ? sql `NOT COALESCE((${field})::boolean, false)` : undefined;
|
|
261
|
+
}
|
|
262
|
+
const jsonField = docFieldJsonSql(collection, table, fieldPath);
|
|
263
|
+
return jsonField ? sql `${jsonField} IS NULL` : undefined;
|
|
264
|
+
}
|
|
265
|
+
const replyCountMatch = expr.match(/^DOC\.replyCount\s*(==|!=|>=|<=|>|<)\s*(\d+)$/);
|
|
266
|
+
if (replyCountMatch && collection === 'posts') {
|
|
267
|
+
const countExpr = postsReplyCountSql(table);
|
|
268
|
+
return compareSql(countExpr, replyCountMatch[1], Number(replyCountMatch[2]));
|
|
269
|
+
}
|
|
270
|
+
const comparison = expr.match(/^DOC\.([a-zA-Z0-9_.]+)\s*(==|!=|>=|<=|>|<)\s*(.+)$/);
|
|
271
|
+
if (comparison) {
|
|
272
|
+
const [, fieldPath, op, rawValue] = comparison;
|
|
273
|
+
const value = parseLiteral(rawValue);
|
|
274
|
+
if (fieldPath === 'replyCount' && collection === 'posts') {
|
|
275
|
+
if (typeof value !== 'number')
|
|
276
|
+
return undefined;
|
|
277
|
+
return compareSql(postsReplyCountSql(table), op, value);
|
|
278
|
+
}
|
|
279
|
+
if (op === '!=' && rawValue.trim() === 'null') {
|
|
280
|
+
const jsonField = docFieldJsonSql(collection, table, fieldPath);
|
|
281
|
+
return jsonField ? sql `${jsonField} IS NOT NULL` : undefined;
|
|
282
|
+
}
|
|
283
|
+
if (op === '==' && rawValue.trim() === 'null') {
|
|
284
|
+
const jsonField = docFieldJsonSql(collection, table, fieldPath);
|
|
285
|
+
return jsonField ? sql `${jsonField} IS NULL` : undefined;
|
|
286
|
+
}
|
|
287
|
+
const field = docFieldSql(collection, table, fieldPath);
|
|
288
|
+
if (!field)
|
|
289
|
+
return undefined;
|
|
290
|
+
if (fieldPath === 'seen' || fieldPath === 'read') {
|
|
291
|
+
if (op === '!=' && value === null) {
|
|
292
|
+
return sql `COALESCE((${field})::boolean, false) = true`;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return compareSql(field, op, value);
|
|
296
|
+
}
|
|
297
|
+
const keyCompare = expr.match(/^DOC\._key\s*(<|>)\s*['"]([^'"]+)['"]$/);
|
|
298
|
+
if (keyCompare) {
|
|
299
|
+
const t = asTable(table);
|
|
300
|
+
return keyCompare[1] === '<'
|
|
301
|
+
? lt(t.id, keyCompare[2])
|
|
302
|
+
: gt(t.id, keyCompare[2]);
|
|
303
|
+
}
|
|
304
|
+
const truthyField = expr.match(/^DOC\.([a-zA-Z0-9_.]+)$/);
|
|
305
|
+
if (truthyField) {
|
|
306
|
+
const jsonField = docFieldJsonSql(collection, table, truthyField[1]);
|
|
307
|
+
return jsonField ? sql `${jsonField} IS NOT NULL` : undefined;
|
|
308
|
+
}
|
|
309
|
+
const coalesceCompare = expr.match(/^\(DOC\.([a-zA-Z0-9_.]+)\s*\|\|\s*DOC\.([a-zA-Z0-9_.]+)\)\s*(<|>|<=|>=)\s*['"]([^'"]+)['"]$/);
|
|
310
|
+
if (coalesceCompare) {
|
|
311
|
+
const left = docFieldSql(collection, table, coalesceCompare[1]);
|
|
312
|
+
const right = docFieldSql(collection, table, coalesceCompare[2]);
|
|
313
|
+
if (!left || !right)
|
|
314
|
+
return undefined;
|
|
315
|
+
return compareSql(sql `COALESCE(${left}, ${right})`, coalesceCompare[3], coalesceCompare[4]);
|
|
316
|
+
}
|
|
317
|
+
const fieldTruthyAndCompare = expr.match(/^DOC\.([a-zA-Z0-9_.]+)\s*&&\s*DOC\.([a-zA-Z0-9_.]+)\s*(>|>=|<|<=|==|!=)\s*(.+)$/);
|
|
318
|
+
if (fieldTruthyAndCompare &&
|
|
319
|
+
fieldTruthyAndCompare[1] === fieldTruthyAndCompare[2]) {
|
|
320
|
+
const [, fieldPath, , op, rawValue] = fieldTruthyAndCompare;
|
|
321
|
+
const jsonField = docFieldJsonSql(collection, table, fieldPath);
|
|
322
|
+
const field = docFieldSql(collection, table, fieldPath);
|
|
323
|
+
if (!jsonField || !field)
|
|
324
|
+
return undefined;
|
|
325
|
+
const value = parseLiteral(rawValue);
|
|
326
|
+
const compare = compareSql(field, op, value);
|
|
327
|
+
if (!compare)
|
|
328
|
+
return undefined;
|
|
329
|
+
return and(sql `${jsonField} IS NOT NULL`, compare);
|
|
330
|
+
}
|
|
331
|
+
return undefined;
|
|
332
|
+
};
|
|
333
|
+
export const stringFilterToSql = (collection, table, expression) => {
|
|
334
|
+
const expr = unwrapParens(expression);
|
|
335
|
+
if (!expr)
|
|
336
|
+
return undefined;
|
|
337
|
+
if (expr.includes('||')) {
|
|
338
|
+
const parts = splitTopLevel(expr, '||');
|
|
339
|
+
// Nested `||` yields a single part — fall through instead of recursing.
|
|
340
|
+
if (parts.length > 1) {
|
|
341
|
+
const sqlParts = parts.map((part) => stringFilterToSql(collection, table, part));
|
|
342
|
+
if (sqlParts.some((part) => !part))
|
|
343
|
+
return undefined;
|
|
344
|
+
return or(...sqlParts);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (expr.includes('&&')) {
|
|
348
|
+
const parts = splitTopLevel(expr, '&&');
|
|
349
|
+
if (parts.length > 1) {
|
|
350
|
+
const sqlParts = parts.map((part) => stringFilterToSql(collection, table, part));
|
|
351
|
+
if (sqlParts.some((part) => !part))
|
|
352
|
+
return undefined;
|
|
353
|
+
return and(...sqlParts);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return singleStringFilterToSql(collection, table, expr);
|
|
357
|
+
};
|
|
358
|
+
const matchToSql = (collection, table, match) => {
|
|
359
|
+
const t = asTable(table);
|
|
360
|
+
const conditions = [];
|
|
361
|
+
for (const [key, value] of Object.entries(match)) {
|
|
362
|
+
if (key === '_key') {
|
|
363
|
+
conditions.push(eq(t.id, value));
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (key === '_from' && typeof value === 'string') {
|
|
367
|
+
const parsed = parseDocRef(value);
|
|
368
|
+
if (parsed)
|
|
369
|
+
conditions.push(eq(t.fromId, parsed.id));
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (key === '_to' && typeof value === 'string') {
|
|
373
|
+
const parsed = parseDocRef(value);
|
|
374
|
+
if (parsed)
|
|
375
|
+
conditions.push(eq(t.toId, parsed.id));
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (key === 'replyCount' && collection === 'posts') {
|
|
379
|
+
if (typeof value !== 'number')
|
|
380
|
+
continue;
|
|
381
|
+
const countExpr = postsReplyCountSql(table);
|
|
382
|
+
conditions.push(eq(countExpr, value));
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (key === 'replyToCount' && collection === 'posts') {
|
|
386
|
+
if (typeof value !== 'number')
|
|
387
|
+
continue;
|
|
388
|
+
conditions.push(eq(postReplyToCountExpr(table), value));
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (collection === 'hashtags' && key === 'tag') {
|
|
392
|
+
conditions.push(eq(t.name, value));
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
if (collection === 'jamEvents' && key === 'jamId') {
|
|
396
|
+
conditions.push(eq(t.postId, value));
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
const config = getCollectionConfig(collection);
|
|
400
|
+
if (!config)
|
|
401
|
+
continue;
|
|
402
|
+
if (config.kind === 'document') {
|
|
403
|
+
const scalars = SCALAR_COLUMNS[collection];
|
|
404
|
+
if (scalars === null || scalars === void 0 ? void 0 : scalars.includes(key)) {
|
|
405
|
+
conditions.push(eq(t[key], value));
|
|
406
|
+
}
|
|
407
|
+
else if (t.body) {
|
|
408
|
+
conditions.push(sql `${bodyColumn(t)} @> ${JSON.stringify({ [key]: value })}::jsonb`);
|
|
409
|
+
}
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
// Edge collections store non-meta fields in jsonb body.
|
|
413
|
+
if (config.kind === 'edge' && t.body) {
|
|
414
|
+
conditions.push(sql `${bodyColumn(t)} @> ${JSON.stringify({ [key]: value })}::jsonb`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return conditions.length ? and(...conditions) : undefined;
|
|
418
|
+
};
|
|
419
|
+
export const filterToSql = (collection, table, filter) => {
|
|
420
|
+
if (isSqlFilter(filter))
|
|
421
|
+
return filter.where;
|
|
422
|
+
if (typeof filter === 'string') {
|
|
423
|
+
return stringFilterToSql(collection, table, filter);
|
|
424
|
+
}
|
|
425
|
+
if ('operator' in filter) {
|
|
426
|
+
const parts = filter.predicates.map((predicate) => {
|
|
427
|
+
if (isSqlFilter(predicate))
|
|
428
|
+
return predicate.where;
|
|
429
|
+
return filterToSql(collection, table, predicate);
|
|
430
|
+
});
|
|
431
|
+
if (parts.some((part) => !part))
|
|
432
|
+
return undefined;
|
|
433
|
+
return filter.operator === '&&'
|
|
434
|
+
? and(...parts)
|
|
435
|
+
: or(...parts);
|
|
436
|
+
}
|
|
437
|
+
if ('matches' in filter) {
|
|
438
|
+
const matches = Array.isArray(filter.matches)
|
|
439
|
+
? filter.matches
|
|
440
|
+
: [filter.matches];
|
|
441
|
+
const parts = matches
|
|
442
|
+
.map((match) => matchToSql(collection, table, match))
|
|
443
|
+
.filter(Boolean);
|
|
444
|
+
if (!parts.length)
|
|
445
|
+
return undefined;
|
|
446
|
+
return parts.length === 1 ? parts[0] : or(...parts);
|
|
447
|
+
}
|
|
448
|
+
return undefined;
|
|
449
|
+
};
|
|
450
|
+
export const partitionFilters = (collection, table, filters, defaultFilter, softDelete) => {
|
|
451
|
+
const t = asTable(table);
|
|
452
|
+
const sqlConditions = [];
|
|
453
|
+
const postFilters = [];
|
|
454
|
+
if (softDelete !== false && t.deletedAt) {
|
|
455
|
+
sqlConditions.push(isNull(t.deletedAt));
|
|
456
|
+
}
|
|
457
|
+
for (const filter of [
|
|
458
|
+
...(defaultFilter ? [defaultFilter] : []),
|
|
459
|
+
...(filters !== null && filters !== void 0 ? filters : []),
|
|
460
|
+
]) {
|
|
461
|
+
if (isSqlFilter(filter)) {
|
|
462
|
+
sqlConditions.push(filter.where);
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
const sqlFilter = filterToSql(collection, table, filter);
|
|
466
|
+
if (sqlFilter)
|
|
467
|
+
sqlConditions.push(sqlFilter);
|
|
468
|
+
else
|
|
469
|
+
postFilters.push(filter);
|
|
470
|
+
}
|
|
471
|
+
return {
|
|
472
|
+
sqlWhere: sqlConditions.length ? and(...sqlConditions) : undefined,
|
|
473
|
+
postFilters,
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
export const filtersToSql = (collection, table, filters, softDelete) => partitionFilters(collection, table, filters, undefined, softDelete).sqlWhere;
|
|
477
|
+
export const applyDateRangeToEdgeSql = (table, filter) => {
|
|
478
|
+
if (!filter)
|
|
479
|
+
return undefined;
|
|
480
|
+
if (isSqlFilter(filter))
|
|
481
|
+
return filter.where;
|
|
482
|
+
if (typeof filter !== 'string')
|
|
483
|
+
return undefined;
|
|
484
|
+
return createdAtRangeSql(table, filter);
|
|
485
|
+
};
|
|
486
|
+
export const sortToSqlOrderBy = (collection, table, sort, activityWindow) => {
|
|
487
|
+
if (!(sort === null || sort === void 0 ? void 0 : sort.length))
|
|
488
|
+
return undefined;
|
|
489
|
+
const orderBy = [];
|
|
490
|
+
for (const [expr, direction] of sort) {
|
|
491
|
+
const path = expr.replace(/^DOC\./, '');
|
|
492
|
+
const dir = direction === 'DESC' ? desc : asc;
|
|
493
|
+
if (path === 'activityScore') {
|
|
494
|
+
if (collection === 'profiles') {
|
|
495
|
+
orderBy.push(dir(profileActivityScoreExpr(table, activityWindow)));
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (collection === 'posts') {
|
|
499
|
+
orderBy.push(dir(postActivityScoreExpr(table)));
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (path === 'replyCount' && collection === 'posts') {
|
|
504
|
+
orderBy.push(dir(postReplyCountExpr(table)));
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (path === 'lastPostAt' && collection === 'groups') {
|
|
508
|
+
orderBy.push(dir(groupLastPostAtExpr(table)));
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
const field = docFieldSql(collection, table, path);
|
|
512
|
+
if (!field)
|
|
513
|
+
return undefined;
|
|
514
|
+
orderBy.push(dir(field));
|
|
515
|
+
}
|
|
516
|
+
return orderBy.length ? orderBy : undefined;
|
|
517
|
+
};
|
|
518
|
+
export const applyPostFilters = (docs, filters, defaultFilter) => {
|
|
519
|
+
const allFilters = [
|
|
520
|
+
...(defaultFilter ? [defaultFilter] : []),
|
|
521
|
+
...(filters !== null && filters !== void 0 ? filters : []),
|
|
522
|
+
];
|
|
523
|
+
return docs.filter((doc) => allFilters.every((f) => {
|
|
524
|
+
if (isSqlFilter(f))
|
|
525
|
+
return true;
|
|
526
|
+
return evaluateFilter(doc, f);
|
|
527
|
+
}));
|
|
528
|
+
};
|
|
529
|
+
export const applySort = (docs, sort) => {
|
|
530
|
+
if (!(sort === null || sort === void 0 ? void 0 : sort.length))
|
|
531
|
+
return docs;
|
|
532
|
+
return [...docs].sort((a, b) => {
|
|
533
|
+
for (const [expr, direction] of sort) {
|
|
534
|
+
const path = expr.replace(/^DOC\./, '');
|
|
535
|
+
const av = getPath(a, path);
|
|
536
|
+
const bv = getPath(b, path);
|
|
537
|
+
if (av === bv)
|
|
538
|
+
continue;
|
|
539
|
+
const cmp = av == null ? -1 : bv == null ? 1 : av < bv ? -1 : av > bv ? 1 : 0;
|
|
540
|
+
return direction === 'DESC' ? -cmp : cmp;
|
|
541
|
+
}
|
|
542
|
+
return 0;
|
|
543
|
+
});
|
|
544
|
+
};
|
|
545
|
+
export const applyLimit = (docs, limit) => {
|
|
546
|
+
if (!limit)
|
|
547
|
+
return docs;
|
|
548
|
+
if (typeof limit === 'number')
|
|
549
|
+
return docs.slice(0, limit);
|
|
550
|
+
const [offset, countValue] = limit;
|
|
551
|
+
return docs.slice(offset, offset + countValue);
|
|
552
|
+
};
|
|
553
|
+
export const applySqlLimit = (query, limit) => {
|
|
554
|
+
if (!limit)
|
|
555
|
+
return query;
|
|
556
|
+
if (typeof limit === 'number')
|
|
557
|
+
return query.limit(limit);
|
|
558
|
+
return query.offset(limit[0]).limit(limit[1]);
|
|
559
|
+
};
|
|
560
|
+
export const getEdgeTable = (edgeCollection) => {
|
|
561
|
+
const config = edgeRegistry[edgeCollection];
|
|
562
|
+
if (!config) {
|
|
563
|
+
throw new Error(`Unknown edge collection: ${edgeCollection}`);
|
|
564
|
+
}
|
|
565
|
+
return config.table;
|
|
566
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { DerivedProperty, Limit, MapData, ObjectSort, PgFilter, Relation, RelationWithMapping, SearchDefinition, WithId } from './queryTypes';
|
|
2
|
+
import type { PgDb } from '../client';
|
|
3
|
+
import type { PgQueryResult } from './types';
|
|
4
|
+
export type { PgQueryResult } from './types';
|
|
5
|
+
export type { DerivedProperty, ForeignKeyRelation, Limit, MapData, ObjectSort, OMFilter, OMFilterList, PgFilter, Relation, RelationWithMapping, SearchDefinition, SqlFilter, WithId, } from './queryTypes';
|
|
6
|
+
export type Mapping<T extends object, O extends {
|
|
7
|
+
id: string;
|
|
8
|
+
} = WithId<T>, F extends object = O> = {
|
|
9
|
+
addRelation: (relation: Relation) => Mapping<T, O, F>;
|
|
10
|
+
addRelations: (relations: Relation[]) => Mapping<T, O, F>;
|
|
11
|
+
removeRelation: (predicate: (relation: Relation) => boolean) => Mapping<T, O, F>;
|
|
12
|
+
addDerivedProperty: (derivedProperty: DerivedProperty) => Mapping<T, O, F>;
|
|
13
|
+
removeDefaultFilter: () => Mapping<T, O, F>;
|
|
14
|
+
filter: (filter?: PgFilter<F>) => Mapping<T, O, F>;
|
|
15
|
+
clearFilters: () => Mapping<T, O, F>;
|
|
16
|
+
sort: (sort?: ObjectSort) => Mapping<T, O, F>;
|
|
17
|
+
limit: (limit?: Limit) => Mapping<T, O, F>;
|
|
18
|
+
ignoreSoftDelete: () => Mapping<T, O, F>;
|
|
19
|
+
find: (db: PgDb, id: string, options?: {
|
|
20
|
+
ignoreSoftDelete?: boolean;
|
|
21
|
+
}) => Promise<O | undefined>;
|
|
22
|
+
findOneBy: (db: PgDb, filter: PgFilter<F>) => Promise<O | undefined>;
|
|
23
|
+
all: (db: PgDb) => Promise<O[]>;
|
|
24
|
+
fulltextSearch: (searchDefinition: SearchDefinition) => PgQueryResult<{
|
|
25
|
+
data: O;
|
|
26
|
+
score: number;
|
|
27
|
+
}>;
|
|
28
|
+
count: (db: PgDb) => Promise<number>;
|
|
29
|
+
first: (db: PgDb) => Promise<O | undefined>;
|
|
30
|
+
cursor: (db: PgDb) => AsyncGenerator<O>;
|
|
31
|
+
queryBuilder: () => never;
|
|
32
|
+
query: () => never;
|
|
33
|
+
data: () => MapData<O, F>;
|
|
34
|
+
relationsFrom: <R extends object, E extends object = R>(start: {
|
|
35
|
+
id: string;
|
|
36
|
+
}, relation: RelationWithMapping<R, E>) => PgQueryResult<E>;
|
|
37
|
+
create: (db: PgDb, data: T & {
|
|
38
|
+
id?: string;
|
|
39
|
+
}) => Promise<O>;
|
|
40
|
+
update: (db: PgDb, id: string, data: Partial<T>) => Promise<O>;
|
|
41
|
+
delete: (db: PgDb, id: string) => Promise<void>;
|
|
42
|
+
deleteRelations: (db: PgDb, id: string, relation: RelationWithMapping) => Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
export declare const map: <T extends object, O extends {
|
|
45
|
+
id: string;
|
|
46
|
+
} = WithId<T>, F extends object = O>(mapData: MapData<O, F>) => Mapping<T, O, F>;
|