@openpeepshq/core 0.1.33 → 0.1.35
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/dist/accessTokens/finders.js +5 -6
- package/dist/accessTokens/mutations.js +1 -1
- package/dist/accessTokens/tokens.js +8 -11
- package/dist/accounts/helpers.js +6 -2
- package/dist/accounts/mutations.js +36 -33
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +17 -12
- package/dist/analytics/dateRange.js +3 -5
- package/dist/analytics/jobs.js +3 -4
- package/dist/analytics/pdfReport.js +45 -61
- package/dist/analytics/privacy.js +1 -1
- package/dist/analytics/read.js +164 -140
- package/dist/analytics/report.d.ts +22 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +82 -25
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +8 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +16 -8
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.js +15 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +25 -7
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/init.js +2 -3
- package/dist/db/migration/importCollections.d.ts +14 -9
- package/dist/db/migration/importCollections.js +121 -174
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +17 -87
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +12 -0
- package/dist/db/pg/filters/posts.js +30 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +40 -10
- package/dist/db/pg/map/helpers.js +5 -1
- package/dist/db/pg/map/index.js +46 -51
- package/dist/db/pg/map/mutations.js +65 -25
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +133 -56
- package/dist/db/pg/map/relations.js +76 -68
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +8 -9
- package/dist/db/pg/queries/activity.js +5 -5
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +279 -41
- package/dist/db/pg/schema/documents.js +136 -22
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +9 -2
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +49 -0
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +14 -3
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +25 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +58 -0
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +10 -0
- package/dist/jams/health.js +50 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +25 -18
- package/dist/jams/jobs.js +2 -3
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +62 -45
- package/dist/jams/mapping.d.ts +3 -3
- package/dist/jams/mutations.d.ts +1 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +33 -1
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +25 -18
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +9 -3
- package/dist/jobs/jobDetail.js +6 -12
- package/dist/jobs/jobLog.js +2 -3
- package/dist/lib/streams.js +4 -39
- package/dist/lib/zodDeepPartial.d.ts +1 -1
- package/dist/lib/zodDeepPartial.js +1 -1
- package/dist/log/index.js +13 -29
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +73 -12
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +25 -11
- package/dist/media/streaming.js +5 -5
- package/dist/media/streamingCleanupJobs.js +1 -2
- package/dist/media/streamingJobs.js +3 -4
- package/dist/media/streamingPrewarm.js +7 -11
- package/dist/mediaAttachments/index.js +6 -2
- package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
- package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
- package/dist/notifications/defaultNotifications/mention/index.js +20 -24
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
- package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
- package/dist/notifications/defaultNotifications/reply/index.js +21 -22
- package/dist/notifications/defaultNotifications/repost/index.js +16 -20
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.js +13 -10
- package/dist/notifications/jobs.js +10 -5
- package/dist/notifications/mutations.js +8 -1
- package/dist/notifications/push.js +11 -16
- package/dist/performance/index.js +3 -3
- package/dist/plugins/helpers.js +3 -6
- package/dist/plugins/index.js +39 -4
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +302 -56
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +13 -10
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +34 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +14 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -4
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +17 -8
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +22 -1
- package/dist/posts/finders.d.ts +56 -9
- package/dist/posts/finders.js +84 -23
- package/dist/posts/helpers/filters.js +13 -9
- package/dist/posts/helpers/index.d.ts +179 -14
- package/dist/posts/helpers/index.js +70 -34
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +765 -30
- package/dist/posts/mapping.js +74 -31
- package/dist/posts/mutations.d.ts +516 -3
- package/dist/posts/mutations.js +179 -41
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +4 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +23 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +21 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +82 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +1 -0
- package/dist/profiles/cache.js +30 -10
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +15 -8
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +31 -4
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.js +7 -3
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +85 -3
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/sentry/index.js +9 -11
- package/dist/seo/index.d.ts +50 -0
- package/dist/seo/index.js +145 -0
- package/dist/seo/route.d.ts +18 -0
- package/dist/seo/route.js +19 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.js +31 -14
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +97 -0
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +22 -9
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +39 -2
- package/dist/stats/mapping.js +8 -4
- package/dist/stripe/cache.js +5 -6
- package/dist/stripe/connection.js +3 -4
- package/dist/stripe/helpers.js +15 -20
- package/package.json +5 -7
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -33
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -20
- package/dist/db/migration/transform.js +0 -232
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
- package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.js +0 -4
- package/dist/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -95
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eq } from 'drizzle-orm';
|
|
2
2
|
import { uuidv7 } from 'uuidv7';
|
|
3
3
|
import { nowIso } from '../mappers.js';
|
|
4
|
-
import { asTable, documentRegistry, getCollectionConfig, getTableForCollection, } from './registry.js';
|
|
4
|
+
import { asTable, documentIdColumn, documentRegistry, getCollectionConfig, getTableForCollection, } from './registry.js';
|
|
5
5
|
import { executeFind } from './relations.js';
|
|
6
6
|
const EDGE_PATCH_META_KEYS = new Set([
|
|
7
7
|
'id',
|
|
@@ -23,16 +23,25 @@ const edgeBodyPatch = (patch) => {
|
|
|
23
23
|
return body;
|
|
24
24
|
};
|
|
25
25
|
export const createDocument = async (db, mapData, data) => {
|
|
26
|
-
var _a;
|
|
27
26
|
const collection = mapData.collection;
|
|
28
27
|
const config = documentRegistry[collection];
|
|
29
28
|
if (!config) {
|
|
30
29
|
throw new Error(`Cannot create in collection: ${collection}`);
|
|
31
30
|
}
|
|
32
|
-
const id =
|
|
31
|
+
const id = data.id ?? uuidv7();
|
|
33
32
|
const { scalars, body } = config.splitPatch(data);
|
|
34
33
|
const ts = nowIso();
|
|
35
|
-
await db.insert(config.table).values(
|
|
34
|
+
await db.insert(config.table).values({
|
|
35
|
+
id,
|
|
36
|
+
...scalars,
|
|
37
|
+
body,
|
|
38
|
+
createdAt: ts,
|
|
39
|
+
updatedAt: ts,
|
|
40
|
+
deletedAt: null,
|
|
41
|
+
...(collection === 'posts' && scalars.lastActivityAt === undefined
|
|
42
|
+
? { lastActivityAt: ts }
|
|
43
|
+
: {}),
|
|
44
|
+
});
|
|
36
45
|
const created = await executeFind(db, collection, mapData, id, true);
|
|
37
46
|
if (!created) {
|
|
38
47
|
throw new Error(`create ${collection}`);
|
|
@@ -40,7 +49,6 @@ export const createDocument = async (db, mapData, data) => {
|
|
|
40
49
|
return created;
|
|
41
50
|
};
|
|
42
51
|
export const updateDocument = async (db, mapData, id, patch) => {
|
|
43
|
-
var _a;
|
|
44
52
|
const collection = mapData.collection;
|
|
45
53
|
const config = getCollectionConfig(collection);
|
|
46
54
|
if (!config) {
|
|
@@ -50,29 +58,38 @@ export const updateDocument = async (db, mapData, id, patch) => {
|
|
|
50
58
|
const existing = await db
|
|
51
59
|
.select()
|
|
52
60
|
.from(config.table)
|
|
53
|
-
.where(eq(table
|
|
61
|
+
.where(eq(documentIdColumn(collection, table), id))
|
|
54
62
|
.limit(1);
|
|
55
63
|
const row = existing[0];
|
|
56
64
|
if (!row) {
|
|
57
65
|
throw new Error(`update ${collection} ${id}`);
|
|
58
66
|
}
|
|
59
67
|
if (config.kind === 'edge') {
|
|
60
|
-
const currentBody =
|
|
68
|
+
const currentBody = {
|
|
69
|
+
...(row.body ?? {}),
|
|
70
|
+
};
|
|
61
71
|
await db
|
|
62
72
|
.update(table)
|
|
63
73
|
.set({
|
|
64
|
-
body:
|
|
74
|
+
body: { ...currentBody, ...edgeBodyPatch(patch) },
|
|
65
75
|
updatedAt: nowIso(),
|
|
66
76
|
})
|
|
67
|
-
.where(eq(table
|
|
77
|
+
.where(eq(documentIdColumn(collection, table), id));
|
|
68
78
|
}
|
|
69
79
|
else {
|
|
70
|
-
const merged =
|
|
80
|
+
const merged = {
|
|
81
|
+
...rowToPatchInput(collection, row),
|
|
82
|
+
...patch,
|
|
83
|
+
};
|
|
71
84
|
const { scalars, body } = config.splitPatch(merged);
|
|
72
85
|
await db
|
|
73
86
|
.update(table)
|
|
74
|
-
.set(
|
|
75
|
-
|
|
87
|
+
.set({
|
|
88
|
+
...scalars,
|
|
89
|
+
body,
|
|
90
|
+
updatedAt: nowIso(),
|
|
91
|
+
})
|
|
92
|
+
.where(eq(documentIdColumn(collection, table), id));
|
|
76
93
|
}
|
|
77
94
|
const updated = await executeFind(db, collection, mapData, id, true);
|
|
78
95
|
if (!updated) {
|
|
@@ -87,26 +104,49 @@ const rowToPatchInput = (collection, row) => {
|
|
|
87
104
|
type: row.type,
|
|
88
105
|
visibility: row.visibility,
|
|
89
106
|
creatorId: row.creatorId,
|
|
107
|
+
lastActivityAt: row.lastActivityAt,
|
|
108
|
+
uri: row.uri,
|
|
109
|
+
inReplyToUri: row.inReplyToUri,
|
|
90
110
|
data: row.body,
|
|
91
111
|
};
|
|
92
112
|
case 'profiles':
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
:
|
|
113
|
+
return {
|
|
114
|
+
handle: row.handle,
|
|
115
|
+
type: row.type,
|
|
116
|
+
uri: row.uri,
|
|
117
|
+
inboxUrl: row.inboxUrl,
|
|
118
|
+
sharedInboxUrl: row.sharedInboxUrl,
|
|
119
|
+
publicKeyPem: row.publicKeyPem,
|
|
120
|
+
privateKeyPem: row.privateKeyPem,
|
|
121
|
+
keyId: row.keyId,
|
|
122
|
+
fetchedAt: row.fetchedAt,
|
|
123
|
+
...(row.activityPubDomain
|
|
124
|
+
? { activityPub: { domain: row.activityPubDomain } }
|
|
125
|
+
: {}),
|
|
126
|
+
...row.body,
|
|
127
|
+
};
|
|
96
128
|
case 'groups':
|
|
97
|
-
return
|
|
129
|
+
return { handle: row.handle, ...row.body };
|
|
98
130
|
case 'roles':
|
|
99
|
-
return
|
|
131
|
+
return {
|
|
132
|
+
key: row.key,
|
|
133
|
+
isDefault: row.isDefault,
|
|
134
|
+
...row.body,
|
|
135
|
+
};
|
|
100
136
|
case 'notifications':
|
|
101
|
-
return
|
|
137
|
+
return { profileId: row.profileId, ...row.body };
|
|
102
138
|
case 'jamEvents':
|
|
103
|
-
return
|
|
139
|
+
return { jamId: row.postId, ...row.body };
|
|
104
140
|
case 'processingStats':
|
|
105
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
filetype: row.filetype,
|
|
143
|
+
filesize: row.filesize,
|
|
144
|
+
...row.body,
|
|
145
|
+
};
|
|
106
146
|
case 'profileSettings':
|
|
107
|
-
return
|
|
147
|
+
return { id: row.profileId, ...row.body };
|
|
108
148
|
case 'inviteLinks':
|
|
109
|
-
return
|
|
149
|
+
return { slug: row.slug, ...row.body };
|
|
110
150
|
case 'accounts':
|
|
111
151
|
return {
|
|
112
152
|
email: row.email,
|
|
@@ -117,7 +157,7 @@ const rowToPatchInput = (collection, row) => {
|
|
|
117
157
|
case 'hashtags':
|
|
118
158
|
return { tag: row.name };
|
|
119
159
|
default:
|
|
120
|
-
return
|
|
160
|
+
return { ...row.body };
|
|
121
161
|
}
|
|
122
162
|
};
|
|
123
163
|
export const deleteDocument = async (db, mapData, id) => {
|
|
@@ -126,10 +166,10 @@ export const deleteDocument = async (db, mapData, id) => {
|
|
|
126
166
|
await db
|
|
127
167
|
.update(getTableForCollection(mapData.collection))
|
|
128
168
|
.set({ deletedAt: nowIso(), updatedAt: nowIso() })
|
|
129
|
-
.where(eq(
|
|
169
|
+
.where(eq(documentIdColumn(mapData.collection, table), id));
|
|
130
170
|
return;
|
|
131
171
|
}
|
|
132
172
|
await db
|
|
133
173
|
.delete(getTableForCollection(mapData.collection))
|
|
134
|
-
.where(eq(
|
|
174
|
+
.where(eq(documentIdColumn(mapData.collection, table), id));
|
|
135
175
|
};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export type PgTable = unknown;
|
|
2
2
|
export declare const asTable: (table: PgTable) => Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Column the map layer treats as a document's id. Profile settings are
|
|
5
|
+
* addressed by profile id; legacy rows keep a different primary key.
|
|
6
|
+
*/
|
|
7
|
+
export declare const documentIdColumn: (collection: string, table: Record<string, unknown>) => unknown;
|
|
3
8
|
export type DocumentConfig = {
|
|
4
9
|
kind: 'document';
|
|
5
10
|
table: PgTable;
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import * as documents from '../schema/documents.js';
|
|
13
2
|
import * as edges from '../schema/edges.js';
|
|
14
|
-
import { modelTimestampsFromRow, rowToModel, } from '../mappers.js';
|
|
3
|
+
import { modelTimestampsFromRow, normalizeIsoDatetime, rowToModel, } from '../mappers.js';
|
|
15
4
|
export const asTable = (table) => table;
|
|
5
|
+
/**
|
|
6
|
+
* Column the map layer treats as a document's id. Profile settings are
|
|
7
|
+
* addressed by profile id; legacy rows keep a different primary key.
|
|
8
|
+
*/
|
|
9
|
+
export const documentIdColumn = (collection, table) => (collection === 'profileSettings' ? table.profileId : table.id);
|
|
16
10
|
const bodyOnly = (data) => ({
|
|
17
11
|
scalars: {},
|
|
18
|
-
body:
|
|
12
|
+
body: { ...data },
|
|
19
13
|
});
|
|
20
14
|
const withScalars = (...scalarKeys) => (data) => {
|
|
21
15
|
const scalars = {};
|
|
22
|
-
const body =
|
|
16
|
+
const body = { ...data };
|
|
23
17
|
for (const key of scalarKeys) {
|
|
24
18
|
if (key in body) {
|
|
25
19
|
scalars[key] = body[key];
|
|
@@ -29,7 +23,7 @@ const withScalars = (...scalarKeys) => (data) => {
|
|
|
29
23
|
return { scalars, body };
|
|
30
24
|
};
|
|
31
25
|
const postsSplit = (data) => {
|
|
32
|
-
const { type, visibility, creatorId, data: postBody
|
|
26
|
+
const { type, visibility, creatorId, lastActivityAt, data: postBody, uri, inReplyToUri, ...rest } = data;
|
|
33
27
|
const scalars = {};
|
|
34
28
|
if (type !== undefined)
|
|
35
29
|
scalars.type = type;
|
|
@@ -37,16 +31,34 @@ const postsSplit = (data) => {
|
|
|
37
31
|
scalars.visibility = visibility;
|
|
38
32
|
if (creatorId !== undefined)
|
|
39
33
|
scalars.creatorId = creatorId;
|
|
40
|
-
|
|
34
|
+
if (lastActivityAt !== undefined)
|
|
35
|
+
scalars.lastActivityAt = lastActivityAt;
|
|
36
|
+
if (uri !== undefined)
|
|
37
|
+
scalars.uri = uri;
|
|
38
|
+
if (inReplyToUri !== undefined)
|
|
39
|
+
scalars.inReplyToUri = inReplyToUri;
|
|
40
|
+
const body = postBody !== undefined ? { ...postBody } : { ...rest };
|
|
41
41
|
if (postBody === undefined) {
|
|
42
42
|
delete body.type;
|
|
43
43
|
delete body.visibility;
|
|
44
44
|
delete body.creatorId;
|
|
45
|
+
delete body.lastActivityAt;
|
|
46
|
+
delete body.uri;
|
|
47
|
+
delete body.inReplyToUri;
|
|
45
48
|
}
|
|
46
49
|
return { scalars, body };
|
|
47
50
|
};
|
|
51
|
+
const ACTOR_SCALAR_KEYS = [
|
|
52
|
+
'uri',
|
|
53
|
+
'inboxUrl',
|
|
54
|
+
'sharedInboxUrl',
|
|
55
|
+
'publicKeyPem',
|
|
56
|
+
'privateKeyPem',
|
|
57
|
+
'keyId',
|
|
58
|
+
'fetchedAt',
|
|
59
|
+
];
|
|
48
60
|
const profilesSplit = (data) => {
|
|
49
|
-
const { handle, type, activityPub
|
|
61
|
+
const { handle, type, activityPub, ...rest } = data;
|
|
50
62
|
const scalars = {};
|
|
51
63
|
if (handle !== undefined)
|
|
52
64
|
scalars.handle = handle;
|
|
@@ -57,11 +69,18 @@ const profilesSplit = (data) => {
|
|
|
57
69
|
if (domain !== undefined)
|
|
58
70
|
scalars.activityPubDomain = domain;
|
|
59
71
|
}
|
|
60
|
-
|
|
72
|
+
const body = { ...rest };
|
|
73
|
+
for (const key of ACTOR_SCALAR_KEYS) {
|
|
74
|
+
if (key in body) {
|
|
75
|
+
scalars[key] = body[key];
|
|
76
|
+
delete body[key];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { scalars, body };
|
|
61
80
|
};
|
|
62
81
|
/** App model uses `tag`; Postgres column is `name`. */
|
|
63
82
|
const hashtagsSplit = (data) => {
|
|
64
|
-
const normalized =
|
|
83
|
+
const normalized = { ...data };
|
|
65
84
|
if ('tag' in normalized && !('name' in normalized)) {
|
|
66
85
|
normalized.name = normalized.tag;
|
|
67
86
|
delete normalized.tag;
|
|
@@ -71,25 +90,25 @@ const hashtagsSplit = (data) => {
|
|
|
71
90
|
}
|
|
72
91
|
return withScalars('name')(normalized);
|
|
73
92
|
};
|
|
74
|
-
/**
|
|
93
|
+
/** Older jam events stored jamId; the column is post_id. */
|
|
75
94
|
const jamEventsSplit = (data) => {
|
|
76
|
-
const { postId, jamId
|
|
95
|
+
const { postId, jamId, ...rest } = data;
|
|
77
96
|
const scalars = {};
|
|
78
|
-
const resolvedPostId = postId
|
|
97
|
+
const resolvedPostId = postId ?? jamId;
|
|
79
98
|
if (resolvedPostId !== undefined) {
|
|
80
99
|
scalars.postId = resolvedPostId;
|
|
81
100
|
}
|
|
82
|
-
return { scalars, body:
|
|
101
|
+
return { scalars, body: { ...rest } };
|
|
83
102
|
};
|
|
84
103
|
/** Legacy settings docs use profile id as document id, not profileId. */
|
|
85
104
|
const profileSettingsSplit = (data) => {
|
|
86
|
-
const { profileId, id
|
|
105
|
+
const { profileId, id, ...rest } = data;
|
|
87
106
|
const scalars = {};
|
|
88
|
-
const resolvedProfileId = profileId
|
|
107
|
+
const resolvedProfileId = profileId ?? id;
|
|
89
108
|
if (resolvedProfileId !== undefined) {
|
|
90
109
|
scalars.profileId = resolvedProfileId;
|
|
91
110
|
}
|
|
92
|
-
return { scalars, body:
|
|
111
|
+
return { scalars, body: { ...rest } };
|
|
93
112
|
};
|
|
94
113
|
export const documentRegistry = {
|
|
95
114
|
accounts: {
|
|
@@ -177,11 +196,6 @@ export const documentRegistry = {
|
|
|
177
196
|
table: documents.i18nEntries,
|
|
178
197
|
splitPatch: withScalars('locale', 'namespace'),
|
|
179
198
|
},
|
|
180
|
-
dataMigrations: {
|
|
181
|
-
kind: 'document',
|
|
182
|
-
table: documents.dataMigrations,
|
|
183
|
-
splitPatch: bodyOnly,
|
|
184
|
-
},
|
|
185
199
|
};
|
|
186
200
|
export const edgeRegistry = {
|
|
187
201
|
follows: {
|
|
@@ -190,6 +204,12 @@ export const edgeRegistry = {
|
|
|
190
204
|
fromCollection: 'profiles',
|
|
191
205
|
toCollection: 'profiles',
|
|
192
206
|
},
|
|
207
|
+
blocks: {
|
|
208
|
+
kind: 'edge',
|
|
209
|
+
table: edges.blocks,
|
|
210
|
+
fromCollection: 'profiles',
|
|
211
|
+
toCollection: 'profiles',
|
|
212
|
+
},
|
|
193
213
|
requestsFollow: {
|
|
194
214
|
kind: 'edge',
|
|
195
215
|
table: edges.requestsFollow,
|
|
@@ -226,12 +246,6 @@ export const edgeRegistry = {
|
|
|
226
246
|
fromCollection: 'profiles',
|
|
227
247
|
toCollection: 'posts',
|
|
228
248
|
},
|
|
229
|
-
reactions: {
|
|
230
|
-
kind: 'edge',
|
|
231
|
-
table: edges.reactions,
|
|
232
|
-
fromCollection: 'profiles',
|
|
233
|
-
toCollection: 'posts',
|
|
234
|
-
},
|
|
235
249
|
replyTo: {
|
|
236
250
|
kind: 'edge',
|
|
237
251
|
table: edges.replyTo,
|
|
@@ -334,8 +348,14 @@ export const edgeRegistry = {
|
|
|
334
348
|
fromCollection: 'profiles',
|
|
335
349
|
toCollection: 'posts',
|
|
336
350
|
},
|
|
351
|
+
profileHashtags: {
|
|
352
|
+
kind: 'edge',
|
|
353
|
+
table: edges.profileHashtags,
|
|
354
|
+
fromCollection: 'profiles',
|
|
355
|
+
toCollection: 'hashtags',
|
|
356
|
+
},
|
|
337
357
|
};
|
|
338
|
-
export const getCollectionConfig = (collection) =>
|
|
358
|
+
export const getCollectionConfig = (collection) => documentRegistry[collection] ?? edgeRegistry[collection];
|
|
339
359
|
export const getTableForCollection = (collection) => {
|
|
340
360
|
const config = getCollectionConfig(collection);
|
|
341
361
|
if (!config) {
|
|
@@ -353,7 +373,6 @@ export const parseDocRef = (ref) => {
|
|
|
353
373
|
export const docRef = (collection, id) => `${collection}/${id}`;
|
|
354
374
|
const rowTimestamps = (row) => modelTimestampsFromRow(row);
|
|
355
375
|
export const rowToDocument = (collection, row, keepMetadata = false) => {
|
|
356
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
357
376
|
const config = getCollectionConfig(collection);
|
|
358
377
|
if (!config) {
|
|
359
378
|
throw new Error(`Unknown collection: ${collection}`);
|
|
@@ -364,7 +383,14 @@ export const rowToDocument = (collection, row, keepMetadata = false) => {
|
|
|
364
383
|
const toId = row.toId;
|
|
365
384
|
// Body fields first; row id / edge refs / timestamps always win so a
|
|
366
385
|
// stale body.id (from older inserts) cannot shadow the primary key.
|
|
367
|
-
const base =
|
|
386
|
+
const base = {
|
|
387
|
+
...(row.body ?? {}),
|
|
388
|
+
id: row.id,
|
|
389
|
+
_from: docRef(config.fromCollection, fromId),
|
|
390
|
+
_to: docRef(config.toCollection, toId),
|
|
391
|
+
createdAt: timestamps.createdAt,
|
|
392
|
+
updatedAt: timestamps.updatedAt,
|
|
393
|
+
};
|
|
368
394
|
return keepMetadata ? base : base;
|
|
369
395
|
}
|
|
370
396
|
switch (collection) {
|
|
@@ -373,37 +399,88 @@ export const rowToDocument = (collection, row, keepMetadata = false) => {
|
|
|
373
399
|
email: row.email,
|
|
374
400
|
passwordHash: row.passwordHash,
|
|
375
401
|
emailValidated: row.emailValidated,
|
|
376
|
-
guest:
|
|
402
|
+
guest: row.guest ?? undefined,
|
|
377
403
|
}, timestamps);
|
|
378
404
|
case 'profiles':
|
|
379
|
-
return rowToModel(row.id, Object.assign(Object.assign({ handle: row.handle, type: row.type }, (row.activityPubDomain
|
|
380
|
-
? { activityPub: { domain: row.activityPubDomain } }
|
|
381
|
-
: {})), ((_c = row.body) !== null && _c !== void 0 ? _c : {})), timestamps);
|
|
382
|
-
case 'posts':
|
|
383
405
|
return rowToModel(row.id, {
|
|
406
|
+
handle: row.handle,
|
|
384
407
|
type: row.type,
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
408
|
+
...(row.activityPubDomain
|
|
409
|
+
? { activityPub: { domain: row.activityPubDomain } }
|
|
410
|
+
: {}),
|
|
411
|
+
...(row.body ?? {}),
|
|
412
|
+
...(typeof row.uri === 'string' ? { uri: row.uri } : {}),
|
|
413
|
+
...(typeof row.inboxUrl === 'string'
|
|
414
|
+
? { inboxUrl: row.inboxUrl }
|
|
415
|
+
: {}),
|
|
416
|
+
...(typeof row.sharedInboxUrl === 'string'
|
|
417
|
+
? { sharedInboxUrl: row.sharedInboxUrl }
|
|
418
|
+
: {}),
|
|
419
|
+
...(typeof row.publicKeyPem === 'string'
|
|
420
|
+
? { publicKeyPem: row.publicKeyPem }
|
|
421
|
+
: {}),
|
|
422
|
+
// privateKeyPem stays on the column and is never hydrated here.
|
|
423
|
+
...(typeof row.keyId === 'string' ? { keyId: row.keyId } : {}),
|
|
424
|
+
...(typeof row.fetchedAt === 'string'
|
|
425
|
+
? { fetchedAt: normalizeIsoDatetime(row.fetchedAt) }
|
|
426
|
+
: {}),
|
|
388
427
|
}, timestamps);
|
|
428
|
+
case 'posts': {
|
|
429
|
+
const lastActivityAt = row.lastActivityAt
|
|
430
|
+
? normalizeIsoDatetime(row.lastActivityAt)
|
|
431
|
+
: timestamps.createdAt;
|
|
432
|
+
return {
|
|
433
|
+
...rowToModel(row.id, {
|
|
434
|
+
type: row.type,
|
|
435
|
+
visibility: row.visibility,
|
|
436
|
+
creatorId: row.creatorId,
|
|
437
|
+
...(typeof row.uri === 'string' ? { uri: row.uri } : {}),
|
|
438
|
+
...(typeof row.inReplyToUri === 'string'
|
|
439
|
+
? { inReplyToUri: row.inReplyToUri }
|
|
440
|
+
: {}),
|
|
441
|
+
data: row.body ?? {},
|
|
442
|
+
}, timestamps),
|
|
443
|
+
lastActivityAt,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
389
446
|
case 'groups':
|
|
390
|
-
return rowToModel(row.id,
|
|
447
|
+
return rowToModel(row.id, {
|
|
448
|
+
handle: row.handle,
|
|
449
|
+
...(row.body ?? {}),
|
|
450
|
+
}, timestamps);
|
|
391
451
|
case 'hashtags':
|
|
392
452
|
return rowToModel(row.id, { tag: row.name }, timestamps);
|
|
393
453
|
case 'roles':
|
|
394
|
-
return rowToModel(row.id,
|
|
454
|
+
return rowToModel(row.id, {
|
|
455
|
+
key: row.key,
|
|
456
|
+
isDefault: row.isDefault,
|
|
457
|
+
...(row.body ?? {}),
|
|
458
|
+
}, timestamps);
|
|
395
459
|
case 'notifications':
|
|
396
|
-
return rowToModel(row.id,
|
|
460
|
+
return rowToModel(row.id, {
|
|
461
|
+
profileId: row.profileId,
|
|
462
|
+
...(row.body ?? {}),
|
|
463
|
+
}, timestamps);
|
|
397
464
|
case 'jamEvents':
|
|
398
|
-
return rowToModel(row.id,
|
|
465
|
+
return rowToModel(row.id, {
|
|
466
|
+
jamId: row.postId,
|
|
467
|
+
...(row.body ?? {}),
|
|
468
|
+
}, timestamps);
|
|
399
469
|
case 'processingStats':
|
|
400
|
-
return rowToModel(row.id,
|
|
470
|
+
return rowToModel(row.id, {
|
|
471
|
+
filetype: row.filetype,
|
|
472
|
+
filesize: row.filesize,
|
|
473
|
+
...(row.body ?? {}),
|
|
474
|
+
}, timestamps);
|
|
401
475
|
case 'profileSettings':
|
|
402
|
-
return rowToModel(row.profileId, (
|
|
476
|
+
return rowToModel(row.profileId, (row.body ?? {}), timestamps);
|
|
403
477
|
case 'inviteLinks':
|
|
404
|
-
return rowToModel(row.id,
|
|
478
|
+
return rowToModel(row.id, {
|
|
479
|
+
slug: row.slug,
|
|
480
|
+
...(row.body ?? {}),
|
|
481
|
+
}, timestamps);
|
|
405
482
|
default:
|
|
406
|
-
return rowToModel(row.id, (
|
|
483
|
+
return rowToModel(row.id, (row.body ?? {}), timestamps);
|
|
407
484
|
}
|
|
408
485
|
};
|
|
409
486
|
export const searchViewCollections = {
|