@openpeepshq/core 0.1.32 → 0.1.34
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/helpers.d.ts +2 -2
- package/dist/accessTokens/tokens.js +14 -7
- package/dist/accounts/mutations.d.ts +2 -2
- package/dist/accounts/mutations.js +33 -35
- package/dist/analytics/cache.js +12 -7
- package/dist/analytics/compile.js +16 -10
- package/dist/analytics/pdfReport.d.ts +1 -0
- package/dist/analytics/pdfReport.js +5 -4
- package/dist/analytics/privacy.d.ts +18 -0
- package/dist/analytics/privacy.js +10 -0
- package/dist/analytics/read.js +75 -19
- package/dist/analytics/report.d.ts +21 -1
- package/dist/analytics/report.js +9 -2
- package/dist/backups/index.js +78 -15
- package/dist/backups/metadata.d.ts +8 -2
- package/dist/backups/metadata.js +6 -2
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +7 -9
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +3 -0
- package/dist/config/defaults/db.d.ts +0 -2
- package/dist/config/defaults/db.js +0 -2
- package/dist/config/index.d.ts +25 -3
- package/dist/config/index.js +7 -1
- package/dist/db/helpers.d.ts +7 -28
- package/dist/db/helpers.js +30 -152
- package/dist/db/index.d.ts +3 -1
- package/dist/db/index.js +5 -0
- package/dist/db/init.js +2 -2
- package/dist/db/migration/importCollections.d.ts +15 -10
- package/dist/db/migration/importCollections.js +121 -155
- package/dist/db/migration/shared.d.ts +2 -37
- package/dist/db/migration/shared.js +2 -59
- package/dist/db/pg/client.js +4 -0
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/edges.d.ts +1 -1
- package/dist/db/pg/filters/edges.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +11 -0
- package/dist/db/pg/filters/posts.js +37 -3
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/map/filters.js +37 -2
- package/dist/db/pg/map/mutations.js +13 -8
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +64 -24
- package/dist/db/pg/map/relations.d.ts +1 -1
- package/dist/db/pg/map/relations.js +98 -46
- package/dist/db/pg/migrate.d.ts +22 -0
- package/dist/db/pg/migrate.js +88 -2
- package/dist/db/pg/queries/activity.js +3 -3
- 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 +422 -41
- package/dist/db/pg/schema/documents.js +43 -9
- package/dist/db/pg/schema/edges.d.ts +117 -7
- package/dist/db/pg/schema/edges.js +4 -2
- package/dist/db/pg/schema/index.d.ts +505 -15
- package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
- package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
- package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
- 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/meta/{0006_snapshot.json → 0015_snapshot.json} +393 -39
- package/dist/db/pg/sql/meta/_journal.json +64 -1
- package/dist/db/replaceOrigin.js +6 -0
- package/dist/db/types.d.ts +0 -4
- package/dist/email/render.js +11 -3
- package/dist/events/index.d.ts +6 -1
- package/dist/events/index.js +55 -33
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +26 -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 +3 -2
- package/dist/groups/helpers.d.ts +24 -6
- package/dist/groups/mapping.d.ts +6 -4
- package/dist/groups/mapping.js +2 -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/helpers.d.ts +4 -4
- package/dist/jams/cache.d.ts +1 -1
- package/dist/jams/cache.js +2 -1
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +60 -0
- package/dist/jams/finders.d.ts +2 -1
- package/dist/jams/finders.js +18 -7
- package/dist/jams/health.d.ts +8 -0
- package/dist/jams/health.js +46 -0
- package/dist/jams/helpers.d.ts +6 -2
- package/dist/jams/index.d.ts +6 -3
- package/dist/jams/index.js +41 -27
- package/dist/jams/jobs.js +1 -1
- package/dist/jams/livekit.d.ts +93 -10
- package/dist/jams/livekit.js +151 -52
- package/dist/jams/mapping.d.ts +17 -7
- package/dist/jams/mutations.d.ts +3 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +32 -0
- package/dist/jams/rtmp.d.ts +5 -0
- package/dist/jams/rtmp.js +8 -0
- package/dist/jams/token.d.ts +15 -3
- package/dist/jams/token.js +30 -16
- package/dist/jams/waitingRoom.d.ts +6 -6
- package/dist/jams/waitingRoom.js +24 -23
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +6 -1
- package/dist/jobs/jobDetail.js +1 -6
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +23 -8
- package/dist/media/processing.js +18 -7
- package/dist/notifications/defaultNotifications/follow/index.js +2 -2
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
- 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 +18 -0
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/helpers.js +6 -2
- package/dist/notifications/jobs.js +3 -1
- package/dist/notifications/mutations.js +4 -0
- package/dist/notifications/push.js +11 -4
- package/dist/plugins/helpers.d.ts +1 -0
- package/dist/plugins/helpers.js +1 -8
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +78 -5
- package/dist/plugins/install.d.ts +39 -0
- package/dist/plugins/install.js +455 -0
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +10 -6
- package/dist/plugins/state.d.ts +4 -0
- package/dist/plugins/state.js +29 -0
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +35 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +15 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -2
- package/dist/posts/eventAgenda.d.ts +166 -0
- package/dist/posts/eventAgenda.js +126 -0
- package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
- package/dist/posts/eventOccurrenceJobs.js +28 -0
- package/dist/posts/eventOccurrences.d.ts +10 -0
- package/dist/posts/eventOccurrences.js +61 -0
- package/dist/posts/finders.d.ts +47 -16
- package/dist/posts/finders.js +93 -62
- package/dist/posts/helpers/filters.js +14 -9
- package/dist/posts/helpers/index.d.ts +129 -30
- package/dist/posts/helpers/index.js +66 -33
- package/dist/posts/index.d.ts +7 -1
- package/dist/posts/index.js +7 -1
- package/dist/posts/mapping.d.ts +491 -13
- package/dist/posts/mapping.js +45 -10
- package/dist/posts/mutations.d.ts +441 -4
- package/dist/posts/mutations.js +177 -43
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +7 -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 +14 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.d.ts +2 -0
- package/dist/posts/unseenCounts.js +28 -8
- package/dist/profileSettings/cache.js +22 -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 +87 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +4 -1
- package/dist/profiles/cache.js +28 -7
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +8 -3
- package/dist/profiles/helpers.d.ts +7 -5
- package/dist/profiles/index.d.ts +3 -1
- package/dist/profiles/index.js +3 -1
- 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 +42 -15
- package/dist/pushSubscriptions/helpers.d.ts +2 -2
- package/dist/pushSubscriptions/mutations.js +13 -1
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.d.ts +6 -6
- 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 +86 -3
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/server/index.d.ts +19 -1
- package/dist/server/index.js +37 -18
- 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 +98 -0
- package/dist/stats/finders.d.ts +1 -16131
- package/dist/stats/finders.js +9 -5
- package/dist/stats/mapping.d.ts +21 -1
- package/dist/stats/mapping.js +0 -3
- package/package.json +6 -12
- package/dist/db/arango.d.ts +0 -2
- package/dist/db/arango.js +0 -110
- package/dist/db/migration/autoMigrate.d.ts +0 -2
- package/dist/db/migration/autoMigrate.js +0 -111
- package/dist/db/migration/cli.d.ts +0 -1
- package/dist/db/migration/cli.js +0 -56
- package/dist/db/migration/detect.d.ts +0 -6
- package/dist/db/migration/detect.js +0 -87
- package/dist/db/migration/exportArango.d.ts +0 -4
- package/dist/db/migration/exportArango.js +0 -80
- 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 -18
- package/dist/db/migration/transform.js +0 -209
- 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/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/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -94
package/dist/stats/finders.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { publicProfileWithActivityScoreSchema, publicPostWithActivityScoreSchema, } from '@openpeepshq/common/types';
|
|
2
2
|
import { sub } from 'date-fns';
|
|
3
|
+
import { hostResources } from '../server/status.js';
|
|
3
4
|
import { baseProfilesMapping } from '../profiles/index.js';
|
|
4
5
|
import { allpeepDb } from '../db/index.js';
|
|
5
6
|
import { postsMapping, postsWithReplyCountMapping, postsWithReplyToCountMapping, transformPost, } from '../posts/index.js';
|
|
6
|
-
import { entriesMapping, followsMapping, postsWithActivityScoreMapping, profileWithActivityScoreMapping,
|
|
7
|
+
import { entriesMapping, followsMapping, postsWithActivityScoreMapping, profileWithActivityScoreMapping, repostsMapping, } from './mapping.js';
|
|
7
8
|
import { compileStatsWithAll, createdAtFilter } from './helpers.js';
|
|
8
9
|
import { jamParticipantsMapping, jamSessionStartsMapping, } from '../jams/mapping.js';
|
|
9
10
|
import { edgeFilters, postFilters, profileFilters } from '../db/pg/filters/index.js';
|
|
10
11
|
import { sorts } from '../db/pg/queries/index.js';
|
|
11
|
-
import { entries, follows,
|
|
12
|
+
import { entries, follows, repost } from '../db/pg/schema/edges.js';
|
|
12
13
|
import { jamEvents, posts, profiles } from '../db/pg/schema/documents.js';
|
|
13
14
|
export const activeProfilesCount = (db, start, end) => profileWithActivityScoreMapping(start, end)
|
|
14
15
|
.filter(profileFilters.activityScorePositive(start, end))
|
|
@@ -37,7 +38,10 @@ export const postsRepliesCount = (db, start, end) => postsWithReplyToCountMappin
|
|
|
37
38
|
.filter({ matches: { replyToCount: 1 } })
|
|
38
39
|
.count(db);
|
|
39
40
|
export const postsRepliesStats = () => compileStatsWithAll(postsRepliesCount);
|
|
40
|
-
const reactionCount = (db, start, end) =>
|
|
41
|
+
const reactionCount = (db, start, end) => entriesMapping
|
|
42
|
+
.filter(createdAtFilter(entries, start, end))
|
|
43
|
+
.filter(edgeFilters.entryType('reaction'))
|
|
44
|
+
.count(db);
|
|
41
45
|
const rsvpCount = (db, start, end) => entriesMapping
|
|
42
46
|
.filter(createdAtFilter(entries, start, end))
|
|
43
47
|
.filter(edgeFilters.entryType('rsvp'))
|
|
@@ -45,8 +49,7 @@ const rsvpCount = (db, start, end) => entriesMapping
|
|
|
45
49
|
const followCount = (db, start, end) => followsMapping.filter(createdAtFilter(follows, start, end)).count(db);
|
|
46
50
|
const entryCount = (db, start, end) => entriesMapping.filter(createdAtFilter(entries, start, end)).count(db);
|
|
47
51
|
const repostCount = (db, start, end) => repostsMapping.filter(createdAtFilter(repost, start, end)).count(db);
|
|
48
|
-
const interactionsCount = async (db, start, end) => (await
|
|
49
|
-
(await followCount(db, start, end)) +
|
|
52
|
+
const interactionsCount = async (db, start, end) => (await followCount(db, start, end)) +
|
|
50
53
|
(await entryCount(db, start, end)) +
|
|
51
54
|
(await repostCount(db, start, end));
|
|
52
55
|
export const interactionsStats = () => compileStatsWithAll(interactionsCount);
|
|
@@ -164,4 +167,5 @@ export const serverStats = async () => ({
|
|
|
164
167
|
fourMonths: await signupsTimeline('P120D'),
|
|
165
168
|
},
|
|
166
169
|
},
|
|
170
|
+
host: await hostResources(),
|
|
167
171
|
});
|
package/dist/stats/mapping.d.ts
CHANGED
|
@@ -141,6 +141,27 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
|
|
|
141
141
|
} | undefined;
|
|
142
142
|
} | undefined;
|
|
143
143
|
url?: string | undefined;
|
|
144
|
+
recurrence?: {
|
|
145
|
+
freq: "DAILY" | "WEEKLY" | "MONTHLY";
|
|
146
|
+
interval?: number | undefined;
|
|
147
|
+
byDay?: ("MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU")[] | undefined;
|
|
148
|
+
until?: string | undefined;
|
|
149
|
+
count?: number | undefined;
|
|
150
|
+
} | undefined;
|
|
151
|
+
exceptions?: {
|
|
152
|
+
recurrenceId: string;
|
|
153
|
+
cancelled?: boolean | undefined;
|
|
154
|
+
start?: string | undefined;
|
|
155
|
+
end?: string | undefined;
|
|
156
|
+
physicalLocation?: {
|
|
157
|
+
text: string;
|
|
158
|
+
coordinates?: {
|
|
159
|
+
lat: number;
|
|
160
|
+
lng: number;
|
|
161
|
+
alt?: number | undefined;
|
|
162
|
+
} | undefined;
|
|
163
|
+
} | undefined;
|
|
164
|
+
}[] | undefined;
|
|
144
165
|
} | {
|
|
145
166
|
type: "article";
|
|
146
167
|
content?: string | undefined;
|
|
@@ -182,7 +203,6 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
|
|
|
182
203
|
}, DbPost & {
|
|
183
204
|
activityScore: number;
|
|
184
205
|
}>;
|
|
185
|
-
export declare const reactionsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
|
|
186
206
|
export declare const followsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
|
|
187
207
|
export declare const entriesMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
|
|
188
208
|
export declare const repostsMapping: import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("../db/pg/map").WithId<object>>;
|
package/dist/stats/mapping.js
CHANGED
|
@@ -5,9 +5,6 @@ import { map } from '../db/pg/map/index.js';
|
|
|
5
5
|
import { computedFields } from '../db/pg/queries/index.js';
|
|
6
6
|
export const profileWithActivityScoreMapping = (start, end) => map(Object.assign(Object.assign({}, baseProfilesMapping.data()), { activityWindow: { start, end }, computedFields: [computedFields.profileActivityScore({ start, end })] }));
|
|
7
7
|
export const postsWithActivityScoreMapping = map(Object.assign(Object.assign({}, postsMapping.data()), { computedFields: [computedFields.postActivityScore()] }));
|
|
8
|
-
export const reactionsMapping = map({
|
|
9
|
-
collection: collectionInfos.reactionsCollection.name,
|
|
10
|
-
});
|
|
11
8
|
export const followsMapping = map({
|
|
12
9
|
collection: collectionInfos.followsCollection.name,
|
|
13
10
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.34",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
40
|
"zod": "^4.4.3",
|
|
41
|
-
"@openpeepshq/common": "0.1.
|
|
41
|
+
"@openpeepshq/common": "0.1.46",
|
|
42
|
+
"@openpeepshq/i18n": "^0.1.10",
|
|
42
43
|
"@openpeepshq/geocoder": "^0.1.2",
|
|
43
|
-
"@openpeepshq/fetch-client": "^0.1.7"
|
|
44
|
-
"@openpeepshq/i18n": "^0.1.9"
|
|
44
|
+
"@openpeepshq/fetch-client": "^0.1.7"
|
|
45
45
|
},
|
|
46
46
|
"main": "dist/index.js",
|
|
47
47
|
"types": "dist/index.d.ts",
|
|
@@ -67,7 +67,6 @@
|
|
|
67
67
|
"@types/web-push": "^3.6.4",
|
|
68
68
|
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
69
69
|
"@typescript-eslint/parser": "^8.19.1",
|
|
70
|
-
"arangojs": "10.0.0",
|
|
71
70
|
"concurrently": "^9.1.2",
|
|
72
71
|
"drizzle-kit": "^0.31.1",
|
|
73
72
|
"eslint": "^9.17.0",
|
|
@@ -77,8 +76,7 @@
|
|
|
77
76
|
"prettier": "^3.4.2",
|
|
78
77
|
"tsc-alias": "^1.8.10",
|
|
79
78
|
"typescript": "^5.7.2",
|
|
80
|
-
"vitest": "^2.1.8"
|
|
81
|
-
"@openpeepshq/arango-querybuilder": "^0.4.7"
|
|
79
|
+
"vitest": "^2.1.8"
|
|
82
80
|
},
|
|
83
81
|
"scripts": {
|
|
84
82
|
"lint": "prettier --check . && ESLINT_USE_FLAT_CONFIG=false eslint .",
|
|
@@ -88,12 +86,8 @@
|
|
|
88
86
|
"build": "tsc && tsc-alias && rm -rf dist/db/pg/sql && cp -r src/db/pg/sql dist/db/pg/sql",
|
|
89
87
|
"build:watch": "tsc && tsc-alias && (concurrently \"tsc -w\" \"tsc-alias -w\")",
|
|
90
88
|
"uuidv7": "node -e 'import(\"uuidv7\").then(u => console.log(u.uuidv7()))'",
|
|
91
|
-
"create-migration": "node create-migration.js",
|
|
92
89
|
"db:generate": "drizzle-kit generate",
|
|
93
90
|
"db:migrate": "drizzle-kit migrate",
|
|
94
|
-
"db:studio": "drizzle-kit studio"
|
|
95
|
-
"db:export-arango": "pnpm build && node dist/db/migration/cli.js export",
|
|
96
|
-
"db:import-pg": "pnpm build && node dist/db/migration/cli.js import",
|
|
97
|
-
"db:validate-migration": "pnpm build && node dist/db/migration/cli.js validate"
|
|
91
|
+
"db:studio": "drizzle-kit studio"
|
|
98
92
|
}
|
|
99
93
|
}
|
package/dist/db/arango.d.ts
DELETED
package/dist/db/arango.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Database } from 'arangojs';
|
|
2
|
-
import { defaultConfig } from '../config/defaults/core.js';
|
|
3
|
-
import { ArangoError } from 'arangojs/errors';
|
|
4
|
-
import { logger } from '../log/index.js';
|
|
5
|
-
import { sleep } from '@openpeepshq/common/lib';
|
|
6
|
-
const log = logger('openpeeps:db');
|
|
7
|
-
const DB_AVAILABILITY_TIMEOUT = 10000;
|
|
8
|
-
let dbPromise;
|
|
9
|
-
const handleArangoError = (method, params) => (e) => {
|
|
10
|
-
var _a;
|
|
11
|
-
if (e instanceof ArangoError) {
|
|
12
|
-
if (method === 'query') {
|
|
13
|
-
log.error('===============================');
|
|
14
|
-
log.error('===============================');
|
|
15
|
-
// @ts-expect-error type guaranteed because of method name
|
|
16
|
-
if (params[0].query && typeof params[0].query === 'string') {
|
|
17
|
-
// @ts-expect-error type guaranteed because of method name
|
|
18
|
-
const queryText = params[0].query;
|
|
19
|
-
log.error(queryText
|
|
20
|
-
.split('\n')
|
|
21
|
-
.map((line, i) => `${i + 1}: ${line}`)
|
|
22
|
-
.join('\n'));
|
|
23
|
-
// @ts-expect-error type guaranteed because of method name
|
|
24
|
-
log.error(params[0].bindVars);
|
|
25
|
-
log.error('querylength', queryText.length);
|
|
26
|
-
}
|
|
27
|
-
log.error('===============================');
|
|
28
|
-
log.error(e.message);
|
|
29
|
-
log.error('===============================');
|
|
30
|
-
throw new Error(e.message);
|
|
31
|
-
}
|
|
32
|
-
throw {
|
|
33
|
-
request: {
|
|
34
|
-
method,
|
|
35
|
-
params,
|
|
36
|
-
},
|
|
37
|
-
response: (_a = e.response) === null || _a === void 0 ? void 0 : _a.body,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw e;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const waitForDatabase = async (config) => {
|
|
45
|
-
const start = Date.now();
|
|
46
|
-
// Ping the server via `_system`; the target database may not exist yet.
|
|
47
|
-
const database = new Database(Object.assign(Object.assign({}, config), { databaseName: '_system' }));
|
|
48
|
-
let tryCount = 1;
|
|
49
|
-
while (true) {
|
|
50
|
-
log.info(`Checking ArangoDB availability at ${config.url} (try ${tryCount})`);
|
|
51
|
-
const availability = await database.availability(true).catch(() => false);
|
|
52
|
-
if (availability) {
|
|
53
|
-
log.info(`ArangoDB is available at ${config.url}`);
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
if (Date.now() - start > DB_AVAILABILITY_TIMEOUT) {
|
|
57
|
-
log.error(`ArangoDB is not available at ${config.url} after ${DB_AVAILABILITY_TIMEOUT}ms`);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
await sleep(1);
|
|
61
|
-
tryCount++;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const initArangoDb = async () => {
|
|
65
|
-
const config = defaultConfig.db;
|
|
66
|
-
await waitForDatabase(config);
|
|
67
|
-
if (config.databaseName) {
|
|
68
|
-
log.info(`Using database "${config.databaseName}"`);
|
|
69
|
-
const systemDb = new Database(Object.assign(Object.assign({}, config), { databaseName: '_system' }));
|
|
70
|
-
if (!(await systemDb.database(config.databaseName).exists())) {
|
|
71
|
-
log.info(`Creating database "${config.databaseName}"`);
|
|
72
|
-
await systemDb.createDatabase(config.databaseName);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
log.info('Using default database');
|
|
77
|
-
}
|
|
78
|
-
return new Proxy(new Database(defaultConfig.db), {
|
|
79
|
-
get: (target, propertyName) => {
|
|
80
|
-
const property = target[propertyName];
|
|
81
|
-
if (typeof property === 'function') {
|
|
82
|
-
const decoratedFunction = (...args) => {
|
|
83
|
-
try {
|
|
84
|
-
// @ts-expect-error typing is guaranteed to be correct
|
|
85
|
-
const result = target[propertyName](...args);
|
|
86
|
-
if (result instanceof Promise) {
|
|
87
|
-
return result.catch(handleArangoError(propertyName, args));
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (e) {
|
|
94
|
-
handleArangoError(propertyName, args)(e);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
return decoratedFunction.bind(target);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return target[propertyName];
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
export const arangoDb = async () => {
|
|
106
|
-
if (!dbPromise) {
|
|
107
|
-
dbPromise = initArangoDb();
|
|
108
|
-
}
|
|
109
|
-
return dbPromise;
|
|
110
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const runCli: (argv?: string[]) => Promise<0 | 1>;
|
package/dist/db/migration/cli.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
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>;
|
|
@@ -1,87 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Postgres uuid compares case-insensitively; normalize so dedupe matches. */
|
|
2
|
-
export declare const normalizeImportId: (value: unknown) => string | undefined;
|
|
3
|
-
export declare const arangoDocToModel: (doc: Record<string, unknown>) => Record<string, unknown>;
|
|
4
|
-
export type ImportContext = {
|
|
5
|
-
postCreatorIdByPostId?: Map<string, string>;
|
|
6
|
-
/** Empty-name / duplicate-name hashtags: old id → kept id, or '' if dropped. */
|
|
7
|
-
hashtagIdRemap?: Map<string, string>;
|
|
8
|
-
};
|
|
9
|
-
/** Pre-scan entries edges so legacy posts without creatorId can be imported. */
|
|
10
|
-
export declare const buildPostCreatorIdByPostId: (collectionsDir: string) => Promise<Map<string, string>>;
|
|
11
|
-
/**
|
|
12
|
-
* Legacy Arango groups used discoverable/locked flags; capabilities were added
|
|
13
|
-
* later via an Arango-only data migration that never runs on Postgres restores.
|
|
14
|
-
*/
|
|
15
|
-
export declare const capabilitiesFromLegacyGroupFlags: (data: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
16
|
-
export declare const arangoDocToDocumentRow: (collection: string, doc: Record<string, unknown>, context?: ImportContext) => Record<string, unknown>;
|
|
17
|
-
export declare const arangoDocToEdgeRow: (collection: string, doc: Record<string, unknown>) => Record<string, unknown>;
|
|
18
|
-
export declare const isEdgeCollection: (collection: string) => boolean;
|