@openpeepshq/core 0.1.33 → 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/accounts/mutations.js +33 -35
- package/dist/analytics/compile.js +16 -10
- package/dist/analytics/read.js +52 -9
- package/dist/analytics/report.d.ts +20 -0
- package/dist/backups/index.js +75 -15
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +7 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +3 -0
- package/dist/config/index.d.ts +21 -0
- package/dist/config/index.js +7 -1
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +11 -3
- 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 +114 -164
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +2 -52
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/posts.d.ts +10 -0
- package/dist/db/pg/filters/posts.js +28 -4
- 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 +32 -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.js +9 -5
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +6 -6
- 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 +279 -41
- package/dist/db/pg/schema/documents.js +21 -8
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +2 -1
- package/dist/db/pg/schema/index.d.ts +362 -15
- 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/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +43 -1
- package/dist/email/render.js +11 -3
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- 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 +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/mapping.d.ts +4 -2
- 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/jams/export.d.ts +19 -0
- package/dist/jams/export.js +60 -0
- package/dist/jams/health.d.ts +8 -0
- package/dist/jams/health.js +46 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +23 -16
- package/dist/jams/jobs.js +1 -1
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +56 -39
- 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 +32 -0
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +18 -7
- package/dist/jams/waitingRoom.js +1 -1
- 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/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/jobs.js +3 -1
- package/dist/notifications/mutations.js +4 -0
- package/dist/plugins/index.js +37 -1
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +281 -49
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +10 -6
- 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 +1 -0
- package/dist/posts/eventAgenda.js +10 -4
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +21 -0
- package/dist/posts/finders.d.ts +15 -8
- package/dist/posts/finders.js +67 -18
- package/dist/posts/helpers/filters.js +13 -8
- package/dist/posts/helpers/index.d.ts +27 -14
- package/dist/posts/helpers/index.js +34 -14
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +216 -13
- package/dist/posts/mapping.js +14 -13
- package/dist/posts/mutations.d.ts +440 -3
- package/dist/posts/mutations.js +155 -32
- 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 -16
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- 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 +1 -0
- package/dist/profiles/cache.js +19 -6
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +8 -3
- 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 -2
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -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 +18 -0
- package/dist/server/index.js +24 -12
- 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 -17681
- package/dist/stats/finders.js +9 -5
- package/dist/stats/mapping.d.ts +0 -1
- package/dist/stats/mapping.js +0 -3
- package/package.json +4 -5
- 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
package/dist/config/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { deepmergeCustom } from 'deepmerge-ts';
|
|
2
2
|
import { coreConfigSchemaFactory, communityConfigSchemaFactory, capabilitiesConfigSchemaFactory, } from '@openpeepshq/common/types';
|
|
3
|
+
import { restorePasswordPlaceholders } from '@openpeepshq/common/lib';
|
|
3
4
|
import { zodDeepPartialSchema } from '../lib/zodDeepPartial.js';
|
|
4
5
|
import { defaultConfig } from './defaults/core.js';
|
|
5
6
|
import { defaultCommunityConfig } from './defaults/community.js';
|
|
6
7
|
import { default as logsConfig } from './defaults/logs.js';
|
|
7
8
|
import { default as dbConfig } from './defaults/db.js';
|
|
8
9
|
import { hub } from '../events/index.js';
|
|
10
|
+
import { stablePublicServerInfo } from '../server/stablePublicServerInfo.js';
|
|
9
11
|
import { loadConfig, storeConfig } from './db.js';
|
|
10
12
|
import { defaultCapabilitiesConfig } from './defaults/capabilities.js';
|
|
11
13
|
import { pruneEmptyConfigStrings } from './pruneEmptyConfigStrings.js';
|
|
@@ -38,6 +40,9 @@ const initConfig = async (namespace, name) => {
|
|
|
38
40
|
};
|
|
39
41
|
export const refreshConfig = (namespace = 'openpeeps', name = 'core') => {
|
|
40
42
|
configPromises.set(configKey(namespace, name), initConfig(namespace, name));
|
|
43
|
+
// /server/info is bucket-cached so RN clients do not remount. Drop that
|
|
44
|
+
// snapshot when config changes or SSO/theme patches stay invisible.
|
|
45
|
+
stablePublicServerInfo.reset();
|
|
41
46
|
};
|
|
42
47
|
/** Full-document write. Prefer `updateConfigValues` for patches. */
|
|
43
48
|
const replaceStoredConfig = (config, namespace = 'openpeeps', name = 'core') => storeConfig(configKey(namespace, name), {
|
|
@@ -52,7 +57,8 @@ const replaceStoredConfig = (config, namespace = 'openpeeps', name = 'core') =>
|
|
|
52
57
|
*/
|
|
53
58
|
export const updateConfigValues = (configValues, namespace = 'openpeeps', name = 'core') => loadConfig(configKey(namespace, name)).then((configDocument) => {
|
|
54
59
|
var _a;
|
|
55
|
-
|
|
60
|
+
const stored = (_a = configDocument === null || configDocument === void 0 ? void 0 : configDocument.config) !== null && _a !== void 0 ? _a : {};
|
|
61
|
+
return replaceStoredConfig(deepmerge(stored, restorePasswordPlaceholders(configValues, stored)), namespace, name);
|
|
56
62
|
});
|
|
57
63
|
export const config = (namespace = 'openpeeps', name = 'core') => {
|
|
58
64
|
const key = configKey(namespace, name);
|
package/dist/db/helpers.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare const sortNewestFirst: <T extends object>(mapping: Mapping<T>) =>
|
|
|
35
35
|
export declare const sortOldestFirst: <T extends object>(mapping: Mapping<T>) => Mapping<T, WithId<T>, WithId<T>>;
|
|
36
36
|
export declare const addStartLimit: <T extends object>(mapping: Mapping<T>, start?: string, limit?: number) => Mapping<T>;
|
|
37
37
|
export declare const addStart: <T extends object>(mapping: Mapping<T>, start?: string) => Mapping<T>;
|
|
38
|
+
export declare const addActivityStart: <T extends object>(mapping: Mapping<T>, start?: string) => Mapping<T>;
|
|
38
39
|
export declare const filterAndTransform: <I extends object, O extends object = I>(queryResult: PgQueryResult<I>, db: PgDb, options: FilterAndTransformOptions<I, O>) => Promise<O[]>;
|
|
39
40
|
export declare const composeFilters: <O extends object>(...filters: ObjectFilter<O>[]) => ObjectFilter<O>;
|
|
40
41
|
export declare const retrievePaged: <T extends object>(queryResult: PgQueryResult<T>, db: PgDb, options?: {
|
package/dist/db/helpers.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { parseFeedCursor } from '@openpeepshq/common';
|
|
2
|
+
import { and, eq } from 'drizzle-orm';
|
|
1
3
|
import { deleteEdge as deletePgEdge, insertEdge } from './pg/helpers.js';
|
|
2
4
|
import { asTable, edgeRegistry } from './pg/map/registry.js';
|
|
3
5
|
import { nowIso } from './pg/mappers.js';
|
|
4
|
-
import {
|
|
5
|
-
import { documentKeyAfter, documentKeyBefore } from './pg/filters/index.js';
|
|
6
|
+
import { documentKeyAfter, documentKeyBefore, postFilters } from './pg/filters/index.js';
|
|
6
7
|
import { sorts } from './pg/queries/index.js';
|
|
7
8
|
const getPgEdge = async (db, edgeCollectionName, fromId, toId) => {
|
|
8
9
|
const edgeConfig = edgeRegistry[edgeCollectionName];
|
|
@@ -60,7 +61,14 @@ export const addQuerySort = (mapping, sort) => ((sort === null || sort === void
|
|
|
60
61
|
export const sortNewestFirst = (mapping) => mapping.sort(sorts.idDesc);
|
|
61
62
|
export const sortOldestFirst = (mapping) => mapping.sort(sorts.idAsc);
|
|
62
63
|
export const addStartLimit = (mapping, start, limit = 100) => filterBefore(sortNewestFirst(mapping.limit(limit)), start);
|
|
63
|
-
export const addStart = (mapping, start) => filterBefore(sortNewestFirst(mapping), start);
|
|
64
|
+
export const addStart = (mapping, start) => { var _a; return filterBefore(sortNewestFirst(mapping), (_a = parseFeedCursor(start)) === null || _a === void 0 ? void 0 : _a.id); };
|
|
65
|
+
export const addActivityStart = (mapping, start) => {
|
|
66
|
+
const sorted = mapping.sort(sorts.lastActivityDesc);
|
|
67
|
+
const cursor = parseFeedCursor(start);
|
|
68
|
+
if (!cursor)
|
|
69
|
+
return sorted;
|
|
70
|
+
return sorted.filter(postFilters.afterActivity(cursor));
|
|
71
|
+
};
|
|
64
72
|
const buildLimit = (limit, offset) => limit && offset ? [offset, limit] : limit;
|
|
65
73
|
/**
|
|
66
74
|
* Ceiling on base rows read for one page, as a multiple of the page size. A
|
package/dist/db/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './explorer';
|
|
|
5
5
|
export { map } from './pg/map';
|
|
6
6
|
export { collectionInfos } from './pg/collections';
|
|
7
7
|
export type { CollectionInfoKey } from './pg/collections';
|
|
8
|
-
export type
|
|
8
|
+
export { closePostgres, type PgDb } from './pg/client';
|
|
9
9
|
export type { PgFilter, SqlFilter } from './pg/map/queryTypes';
|
|
10
10
|
export { combine, createdAtBetween, documentKeyAfter, documentKeyBefore, edgeFilters, eventTimeFilters, groupFilters, isSqlFilter, notificationFilters, pgSql, postFilters, profileFilters, } from './pg/filters';
|
|
11
11
|
export { computedFields, sorts } from './pg/queries';
|
package/dist/db/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { empty } from './examples.js';
|
|
|
3
3
|
export * from './explorer/index.js';
|
|
4
4
|
export { map } from './pg/map/index.js';
|
|
5
5
|
export { collectionInfos } from './pg/collections.js';
|
|
6
|
+
export { closePostgres } from './pg/client.js';
|
|
6
7
|
export { combine, createdAtBetween, documentKeyAfter, documentKeyBefore, edgeFilters, eventTimeFilters, groupFilters, isSqlFilter, notificationFilters, pgSql, postFilters, profileFilters, } from './pg/filters/index.js';
|
|
7
8
|
export { computedFields, sorts } from './pg/queries/index.js';
|
|
8
9
|
let dbPromise;
|
package/dist/db/init.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { logger } from '../log/index.js';
|
|
2
2
|
import { initPostgres } from './pg/client.js';
|
|
3
|
+
import { backfillLocalFederationIdentities } from '../federation/identity.js';
|
|
3
4
|
const log = logger('openpeeps:db');
|
|
4
5
|
export const initDb = async () => {
|
|
5
6
|
log.info('Initializing Postgres');
|
|
6
|
-
if (process.env.AUTO_MIGRATE_FROM_ARANGO === 'true') {
|
|
7
|
-
log.warn('AUTO_MIGRATE_FROM_ARANGO is ignored at runtime. Use @openpeepshq/arango-migrate (archive/arango-migrate) for Arango cutover.');
|
|
8
|
-
}
|
|
9
7
|
const db = await initPostgres();
|
|
8
|
+
await backfillLocalFederationIdentities();
|
|
10
9
|
return { db };
|
|
11
10
|
};
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
/** Arango exports can contain duplicate _key lines; keep the last row per id. */
|
|
1
|
+
/** Keep the last row per id when a JSONL file repeats keys. */
|
|
3
2
|
export declare const dedupeRowsById: <T extends Record<string, unknown>>(rows: T[]) => T[];
|
|
4
3
|
export declare const collectionJsonlPath: (collectionsDir: string, collection: string) => string;
|
|
5
4
|
export declare const truncateAllTables: () => Promise<void>;
|
|
6
5
|
export declare const isUuid: (value: unknown) => value is string;
|
|
7
|
-
/** Collapse empty / duplicate hashtag names onto one row (unique on name). */
|
|
8
|
-
export declare const prepareHashtagRows: (rows: Record<string, unknown>[], context: ImportContext) => Record<string, unknown>[];
|
|
9
|
-
export declare const importArangoCollection: (collection: string, collectionsDir: string, context?: ImportContext) => Promise<number>;
|
|
10
6
|
export declare const importPostgresRowCollection: (collection: string, collectionsDir: string) => Promise<number>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
/** Legacy reactions rows become append-only reaction entries. */
|
|
8
|
+
export declare const wrapReactionEntryBody: (body: Record<string, unknown> | null | undefined) => {
|
|
9
|
+
type: "reaction";
|
|
10
|
+
data: {
|
|
11
|
+
reaction: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** Older dumps may still have reactions.jsonl; store them as entries. */
|
|
15
|
+
export declare const importLegacyReactionsAsEntries: (collectionsDir: string) => Promise<number>;
|
|
16
|
+
export type PlaceholderColumn = {
|
|
17
|
+
table: string;
|
|
18
|
+
column: string;
|
|
19
|
+
};
|
|
15
20
|
export declare const importAllPostgresCollections: (collectionsDir: string, schemaVersionFromBackup?: string) => Promise<{
|
|
16
21
|
imported: Record<string, number>;
|
|
17
22
|
total: number;
|
|
@@ -2,16 +2,26 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { appendFile, access } from 'node:fs/promises';
|
|
3
3
|
import { constants } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { getTableName, sql } from 'drizzle-orm';
|
|
5
|
+
import { getTableColumns, getTableName, sql } from 'drizzle-orm';
|
|
6
6
|
import { logger } from '../../log/index.js';
|
|
7
7
|
import { pgDb } from '../pg/client.js';
|
|
8
8
|
import { resetAndMigrateToSchemaVersion, resolveRestoreSchemaVersion, runMigrations, } from '../pg/migrate.js';
|
|
9
|
-
import { documentRegistry, edgeRegistry, getTableForCollection, } from '../pg/map/registry.js';
|
|
10
|
-
import { arangoDocToDocumentRow, arangoDocToEdgeRow, buildPostCreatorIdByPostId, isEdgeCollection, normalizeImportId, } from './transform.js';
|
|
9
|
+
import { documentRegistry, edgeRegistry, getTableForCollection, isEdgeCollection, } from '../pg/map/registry.js';
|
|
11
10
|
import { BATCH_SIZE, DOCUMENT_IMPORT_ORDER, EDGE_IMPORT_ORDER, readJsonl, } from './shared.js';
|
|
12
11
|
const log = logger('core:db:import');
|
|
12
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
13
|
+
const normalizeImportId = (value) => {
|
|
14
|
+
if (typeof value !== 'string') {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const trimmed = value.trim();
|
|
18
|
+
if (!trimmed) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return UUID_RE.test(trimmed) ? trimmed.toLowerCase() : trimmed;
|
|
22
|
+
};
|
|
13
23
|
const rowDedupeKey = (row) => { var _a; return normalizeImportId((_a = row.id) !== null && _a !== void 0 ? _a : row.key); };
|
|
14
|
-
/**
|
|
24
|
+
/** Keep the last row per id when a JSONL file repeats keys. */
|
|
15
25
|
export const dedupeRowsById = (rows) => {
|
|
16
26
|
const byKey = new Map();
|
|
17
27
|
const withoutKey = [];
|
|
@@ -49,13 +59,7 @@ export const truncateAllTables = async () => {
|
|
|
49
59
|
}
|
|
50
60
|
await db.execute(sql.raw(`TRUNCATE TABLE ${existing.map((name) => `"${name}"`).join(', ')} RESTART IDENTITY CASCADE`));
|
|
51
61
|
};
|
|
52
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
53
62
|
export const isUuid = (value) => typeof value === 'string' && UUID_RE.test(value);
|
|
54
|
-
/**
|
|
55
|
-
* Edge `id` columns are uuid. Legacy Arango edge `_key`s are sometimes numeric
|
|
56
|
-
* (or otherwise non-UUID); replace those so the insert does not fail. Document
|
|
57
|
-
* collections are left alone (`data_migrations.id` is text, not uuid).
|
|
58
|
-
*/
|
|
59
63
|
const ensureEdgeUuidId = (collection, row) => {
|
|
60
64
|
var _a;
|
|
61
65
|
if (!isEdgeCollection(collection)) {
|
|
@@ -69,78 +73,7 @@ const ensureEdgeUuidId = (collection, row) => {
|
|
|
69
73
|
log.warn('Replaced non-UUID %s edge id %s with %s', collection, String(row.id), next.id);
|
|
70
74
|
return next;
|
|
71
75
|
};
|
|
72
|
-
const
|
|
73
|
-
if (collection === 'posts' && !row.creatorId) {
|
|
74
|
-
log.warn('Skipping post %s: missing creatorId', row.id);
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
if (collection === 'jamEvents' && !row.postId) {
|
|
78
|
-
log.warn('Skipping jam event %s: missing postId', row.id);
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
if (collection === 'profileSettings' && !row.profileId) {
|
|
82
|
-
log.warn('Skipping profile settings %s: missing profileId', row.id);
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
return true;
|
|
86
|
-
};
|
|
87
|
-
/** Collapse empty / duplicate hashtag names onto one row (unique on name). */
|
|
88
|
-
export const prepareHashtagRows = (rows, context) => {
|
|
89
|
-
var _a;
|
|
90
|
-
const remap = (_a = context.hashtagIdRemap) !== null && _a !== void 0 ? _a : new Map();
|
|
91
|
-
context.hashtagIdRemap = remap;
|
|
92
|
-
const byName = new Map();
|
|
93
|
-
const prepared = [];
|
|
94
|
-
for (const row of rows) {
|
|
95
|
-
const id = typeof row.id === 'string' ? row.id : undefined;
|
|
96
|
-
const name = typeof row.name === 'string' ? row.name.trim().toLowerCase() : '';
|
|
97
|
-
if (!name) {
|
|
98
|
-
if (id)
|
|
99
|
-
remap.set(id, '');
|
|
100
|
-
log.warn('Skipping hashtag %s: empty name', id !== null && id !== void 0 ? id : '(no id)');
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
row.name = name;
|
|
104
|
-
const existing = byName.get(name);
|
|
105
|
-
if (existing) {
|
|
106
|
-
const keptId = typeof existing.id === 'string' ? existing.id : '';
|
|
107
|
-
if (id)
|
|
108
|
-
remap.set(id, keptId);
|
|
109
|
-
log.warn('Skipping duplicate hashtag name "%s" (id %s → %s)', name, id, keptId || '(unknown)');
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
byName.set(name, row);
|
|
113
|
-
prepared.push(row);
|
|
114
|
-
}
|
|
115
|
-
return prepared;
|
|
116
|
-
};
|
|
117
|
-
const applyHashtagEdgeRemap = (collection, rows, context) => {
|
|
118
|
-
var _a;
|
|
119
|
-
if (collection !== 'postHashtags' || !((_a = context.hashtagIdRemap) === null || _a === void 0 ? void 0 : _a.size)) {
|
|
120
|
-
return rows;
|
|
121
|
-
}
|
|
122
|
-
const remap = context.hashtagIdRemap;
|
|
123
|
-
const out = [];
|
|
124
|
-
let dropped = 0;
|
|
125
|
-
for (const row of rows) {
|
|
126
|
-
const toId = typeof row.toId === 'string' ? row.toId : undefined;
|
|
127
|
-
if (!toId || !remap.has(toId)) {
|
|
128
|
-
out.push(row);
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const mapped = remap.get(toId);
|
|
132
|
-
if (!mapped) {
|
|
133
|
-
dropped += 1;
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
out.push(Object.assign(Object.assign({}, row), { toId: mapped }));
|
|
137
|
-
}
|
|
138
|
-
if (dropped > 0) {
|
|
139
|
-
log.warn('Dropped %d postHashtags edge(s) pointing at skipped hashtags', dropped);
|
|
140
|
-
}
|
|
141
|
-
return out;
|
|
142
|
-
};
|
|
143
|
-
export const importArangoCollection = async (collection, collectionsDir, context = {}) => {
|
|
76
|
+
export const importPostgresRowCollection = async (collection, collectionsDir) => {
|
|
144
77
|
if (!isKnownCollection(collection)) {
|
|
145
78
|
return 0;
|
|
146
79
|
}
|
|
@@ -151,120 +84,134 @@ export const importArangoCollection = async (collection, collectionsDir, context
|
|
|
151
84
|
catch (_a) {
|
|
152
85
|
return 0;
|
|
153
86
|
}
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
87
|
+
const mapped = await readJsonl(filePath);
|
|
88
|
+
if (mapped.length === 0) {
|
|
156
89
|
return 0;
|
|
157
90
|
}
|
|
91
|
+
const withValidIds = mapped.map((row) => ensureEdgeUuidId(collection, row));
|
|
92
|
+
const rows = dedupeRowsById(withValidIds);
|
|
93
|
+
if (rows.length < mapped.length) {
|
|
94
|
+
log.warn('Dropped %d duplicate row(s) while importing %s', mapped.length - rows.length, collection);
|
|
95
|
+
}
|
|
158
96
|
const table = getTableForCollection(collection);
|
|
159
97
|
const db = pgDb();
|
|
160
|
-
let mapped = docs.map((doc) => isEdgeCollection(collection)
|
|
161
|
-
? arangoDocToEdgeRow(collection, doc)
|
|
162
|
-
: arangoDocToDocumentRow(collection, doc, context));
|
|
163
|
-
if (collection === 'hashtags') {
|
|
164
|
-
mapped = prepareHashtagRows(mapped, context);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
mapped = mapped.filter((row) => documentRowIsImportable(collection, row));
|
|
168
|
-
}
|
|
169
|
-
mapped = applyHashtagEdgeRemap(collection, mapped, context);
|
|
170
|
-
mapped = mapped.map((row) => ensureEdgeUuidId(collection, row));
|
|
171
|
-
const beforeDedupe = mapped.length;
|
|
172
|
-
const rows = dedupeRowsById(mapped);
|
|
173
|
-
if (rows.length < beforeDedupe) {
|
|
174
|
-
log.warn('Dropped %d duplicate row(s) while importing %s (e.g. remapped config keys or duplicate _key)', beforeDedupe - rows.length, collection);
|
|
175
|
-
}
|
|
176
|
-
if (rows.length === 0) {
|
|
177
|
-
return 0;
|
|
178
|
-
}
|
|
179
98
|
let imported = 0;
|
|
180
99
|
for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) {
|
|
181
100
|
const batch = rows.slice(offset, offset + BATCH_SIZE);
|
|
182
|
-
|
|
183
|
-
await db.insert(table).values(batch);
|
|
184
|
-
}
|
|
185
|
-
catch (err) {
|
|
186
|
-
const cause = err && typeof err === 'object' && 'cause' in err
|
|
187
|
-
? err.cause
|
|
188
|
-
: undefined;
|
|
189
|
-
const detail = cause instanceof Error
|
|
190
|
-
? cause.message
|
|
191
|
-
: err instanceof Error
|
|
192
|
-
? err.message
|
|
193
|
-
: String(err);
|
|
194
|
-
throw new Error(`Failed importing ${collection} batch at offset ${offset} (${batch.length} rows): ${detail}`);
|
|
195
|
-
}
|
|
101
|
+
await db.insert(table).values(batch);
|
|
196
102
|
imported += batch.length;
|
|
197
103
|
}
|
|
198
|
-
log.info('Imported %d rows into %s from
|
|
104
|
+
log.info('Imported %d rows into %s from Postgres JSONL', imported, collection);
|
|
199
105
|
return imported;
|
|
200
106
|
};
|
|
201
|
-
|
|
202
|
-
|
|
107
|
+
/** Legacy reactions rows become append-only reaction entries. */
|
|
108
|
+
export const wrapReactionEntryBody = (body) => {
|
|
109
|
+
var _a;
|
|
110
|
+
if ((body === null || body === void 0 ? void 0 : body.type) === 'reaction') {
|
|
111
|
+
const reaction = typeof ((_a = body.data) === null || _a === void 0 ? void 0 : _a.reaction) ===
|
|
112
|
+
'string'
|
|
113
|
+
? body.data.reaction
|
|
114
|
+
: typeof body.reaction === 'string'
|
|
115
|
+
? body.reaction
|
|
116
|
+
: '👍';
|
|
117
|
+
return { type: 'reaction', data: { reaction } };
|
|
118
|
+
}
|
|
119
|
+
const reaction = typeof (body === null || body === void 0 ? void 0 : body.reaction) === 'string' ? body.reaction : '👍';
|
|
120
|
+
return { type: 'reaction', data: { reaction } };
|
|
121
|
+
};
|
|
122
|
+
const insertEntryRows = async (rows) => {
|
|
123
|
+
if (rows.length === 0)
|
|
203
124
|
return 0;
|
|
125
|
+
const table = getTableForCollection('entries');
|
|
126
|
+
const db = pgDb();
|
|
127
|
+
let imported = 0;
|
|
128
|
+
for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) {
|
|
129
|
+
const batch = rows.slice(offset, offset + BATCH_SIZE);
|
|
130
|
+
await db.insert(table).values(batch);
|
|
131
|
+
imported += batch.length;
|
|
204
132
|
}
|
|
205
|
-
|
|
133
|
+
return imported;
|
|
134
|
+
};
|
|
135
|
+
/** Older dumps may still have reactions.jsonl; store them as entries. */
|
|
136
|
+
export const importLegacyReactionsAsEntries = async (collectionsDir) => {
|
|
137
|
+
const filePath = collectionJsonlPath(collectionsDir, 'reactions');
|
|
206
138
|
try {
|
|
207
139
|
await access(filePath, constants.F_OK);
|
|
208
140
|
}
|
|
209
141
|
catch (_a) {
|
|
210
142
|
return 0;
|
|
211
143
|
}
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
144
|
+
const docs = await readJsonl(filePath);
|
|
145
|
+
if (docs.length === 0) {
|
|
214
146
|
return 0;
|
|
215
147
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
let imported = 0;
|
|
224
|
-
for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) {
|
|
225
|
-
const batch = rows.slice(offset, offset + BATCH_SIZE);
|
|
226
|
-
await db.insert(table).values(batch);
|
|
227
|
-
imported += batch.length;
|
|
228
|
-
}
|
|
229
|
-
log.info('Imported %d rows into %s from Postgres JSONL', imported, collection);
|
|
148
|
+
const mapped = docs.map((doc) => {
|
|
149
|
+
var _a;
|
|
150
|
+
return ensureEdgeUuidId('entries', Object.assign(Object.assign({}, doc), { body: wrapReactionEntryBody((_a = doc.body) !== null && _a !== void 0 ? _a : doc) }));
|
|
151
|
+
});
|
|
152
|
+
const rows = dedupeRowsById(mapped);
|
|
153
|
+
const imported = await insertEntryRows(rows);
|
|
154
|
+
log.info('Imported %d legacy reactions as entries', imported);
|
|
230
155
|
return imported;
|
|
231
156
|
};
|
|
232
157
|
const sumImported = (imported) => Object.values(imported).reduce((sum, count) => sum + count, 0);
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
|
|
158
|
+
const liveColumnNames = async (table) => {
|
|
159
|
+
const result = await pgDb().execute(sql `SELECT column_name FROM information_schema.columns
|
|
160
|
+
WHERE table_schema = 'public' AND table_name = ${table}`);
|
|
161
|
+
return new Set(result.rows.map((row) => row.column_name));
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* A restore loads rows at an older schema version, but Drizzle names every
|
|
165
|
+
* column of the current table objects in its INSERT, so a column a later
|
|
166
|
+
* migration adds (e.g. `search_vector` in 0001) breaks the load. Add those as
|
|
167
|
+
* nullable placeholders and drop them again before migrating forward, so the
|
|
168
|
+
* migration still creates them itself and runs its backfill.
|
|
169
|
+
*/
|
|
170
|
+
const addPlaceholderColumns = async () => {
|
|
171
|
+
const db = pgDb();
|
|
172
|
+
const added = [];
|
|
173
|
+
for (const collection of [...DOCUMENT_IMPORT_ORDER, ...EDGE_IMPORT_ORDER]) {
|
|
174
|
+
const table = getTableForCollection(collection);
|
|
175
|
+
const tableName = getTableName(table);
|
|
176
|
+
const live = await liveColumnNames(tableName);
|
|
177
|
+
if (live.size === 0) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
for (const column of Object.values(getTableColumns(table))) {
|
|
181
|
+
if (live.has(column.name)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
await db.execute(sql.raw(`ALTER TABLE "${tableName}" ADD COLUMN "${column.name}" ${column.getSQLType()}`));
|
|
185
|
+
added.push({ table: tableName, column: column.name });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (added.length > 0) {
|
|
189
|
+
log.info('Added %d placeholder column(s) for the restore: %s', added.length, added.map(({ table, column }) => `${table}.${column}`).join(', '));
|
|
190
|
+
}
|
|
191
|
+
return added;
|
|
192
|
+
};
|
|
193
|
+
const dropPlaceholderColumns = async (columns) => {
|
|
194
|
+
for (const { table, column } of columns) {
|
|
195
|
+
await pgDb().execute(sql.raw(`ALTER TABLE "${table}" DROP COLUMN IF EXISTS "${column}"`));
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const backfillFederationIdentities = async () => {
|
|
199
|
+
const { backfillLocalFederationIdentities } = await import('../../federation/identity.js');
|
|
200
|
+
await backfillLocalFederationIdentities();
|
|
201
|
+
};
|
|
202
|
+
const prepareSchemaForRestore = async (schemaVersionFromBackup) => {
|
|
203
|
+
const schemaVersion = resolveRestoreSchemaVersion(schemaVersionFromBackup);
|
|
204
|
+
log.info('Preparing postgres restore at schema %s', schemaVersion);
|
|
236
205
|
await resetAndMigrateToSchemaVersion(schemaVersion);
|
|
237
206
|
// 0006 added a unique (from_id, to_id) on post_seen; that was wrong for
|
|
238
207
|
// impressions. Drop it before import so pre-0007 backups with duplicate
|
|
239
208
|
// view rows can restore. 0007 (and later) drop it permanently.
|
|
240
209
|
await pgDb().execute(sql.raw('DROP INDEX IF EXISTS "post_seen_from_to_unique"'));
|
|
241
210
|
await truncateAllTables();
|
|
242
|
-
|
|
243
|
-
export const importAllArangoCollections = async (collectionsDir) => {
|
|
244
|
-
await prepareSchemaForRestore('arango');
|
|
245
|
-
const imported = {};
|
|
246
|
-
const context = {
|
|
247
|
-
postCreatorIdByPostId: await buildPostCreatorIdByPostId(collectionsDir),
|
|
248
|
-
hashtagIdRemap: new Map(),
|
|
249
|
-
};
|
|
250
|
-
// Skip dataMigrations — Arango-era migration ledger is unused on Postgres.
|
|
251
|
-
for (const collection of DOCUMENT_IMPORT_ORDER) {
|
|
252
|
-
if (collection === 'dataMigrations') {
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
imported[collection] = await importArangoCollection(collection, collectionsDir, context);
|
|
256
|
-
}
|
|
257
|
-
for (const collection of EDGE_IMPORT_ORDER) {
|
|
258
|
-
imported[collection] = await importArangoCollection(collection, collectionsDir, context);
|
|
259
|
-
}
|
|
260
|
-
log.info('Arango rows loaded; migrating schema forward to latest');
|
|
261
|
-
await runMigrations();
|
|
262
|
-
const total = sumImported(imported);
|
|
263
|
-
log.info('Arango JSONL import complete: %d rows across %d collections', total, Object.keys(imported).filter((key) => imported[key] > 0).length);
|
|
264
|
-
return { imported, total };
|
|
211
|
+
return addPlaceholderColumns();
|
|
265
212
|
};
|
|
266
213
|
export const importAllPostgresCollections = async (collectionsDir, schemaVersionFromBackup) => {
|
|
267
|
-
await prepareSchemaForRestore(
|
|
214
|
+
const placeholders = await prepareSchemaForRestore(schemaVersionFromBackup);
|
|
268
215
|
const imported = {};
|
|
269
216
|
for (const collection of DOCUMENT_IMPORT_ORDER) {
|
|
270
217
|
imported[collection] = await importPostgresRowCollection(collection, collectionsDir);
|
|
@@ -272,8 +219,11 @@ export const importAllPostgresCollections = async (collectionsDir, schemaVersion
|
|
|
272
219
|
for (const collection of EDGE_IMPORT_ORDER) {
|
|
273
220
|
imported[collection] = await importPostgresRowCollection(collection, collectionsDir);
|
|
274
221
|
}
|
|
222
|
+
imported.reactions = await importLegacyReactionsAsEntries(collectionsDir);
|
|
275
223
|
log.info('Postgres rows loaded; ensuring schema is at latest');
|
|
224
|
+
await dropPlaceholderColumns(placeholders);
|
|
276
225
|
await runMigrations();
|
|
226
|
+
await backfillFederationIdentities();
|
|
277
227
|
const total = sumImported(imported);
|
|
278
228
|
log.info('Postgres JSONL import complete: %d rows across %d collections', total, Object.keys(imported).filter((key) => imported[key] > 0).length);
|
|
279
229
|
return { imported, total };
|
|
@@ -1,35 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const collectionsDir: (exportDir: string) => string;
|
|
4
|
-
export declare const manifestPath: (exportDir: string) => string;
|
|
5
|
-
/** Counts actually inserted into Postgres (after skips / remaps / dedupe). */
|
|
6
|
-
export declare const importStatsPath: (exportDir: string) => string;
|
|
7
|
-
export type ImportStats = {
|
|
8
|
-
importedAt: string;
|
|
9
|
-
collections: CollectionCounts;
|
|
10
|
-
};
|
|
11
|
-
export declare const collectionFilePath: (exportDir: string, collection: string) => string;
|
|
12
|
-
export declare const DOCUMENT_IMPORT_ORDER: readonly ["configs", "i18n", "dataMigrations", "accounts", "roles", "profiles", "groups", "hashtags", "posts", "notifications", "reports", "accessTokens", "pushSubscriptions", "inviteLinks", "jamEvents", "mediaAttachments", "processingStats", "profileSettings"];
|
|
13
|
-
export declare const EDGE_IMPORT_ORDER: readonly ["controls", "follows", "requestsFollow", "mentions", "audience", "postHashtags", "entries", "reactions", "replyTo", "repost", "bookmarks", "postSeen", "hasSeen", "hasRead", "userGroups", "postGroups", "hasRole", "profileAccessTokens", "accountToPushSubscription", "createdReport", "isReportedProfile", "isReportedObject", "inviteLinkCreators", "inviteLinkRedeemers", "jamRecordings"];
|
|
14
|
-
export type CollectionCounts = Record<string, number>;
|
|
15
|
-
export type MigrationManifest = {
|
|
16
|
-
exportedAt: string;
|
|
17
|
-
dbUrl: string;
|
|
18
|
-
dbName?: string;
|
|
19
|
-
collections: CollectionCounts;
|
|
20
|
-
checksums: {
|
|
21
|
-
accountEmails: string;
|
|
22
|
-
postIds: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export declare const sha256: (value: string) => string;
|
|
26
|
-
export declare const sortedChecksum: (values: string[]) => string;
|
|
1
|
+
export declare const DOCUMENT_IMPORT_ORDER: readonly ["configs", "i18n", "accounts", "roles", "profiles", "groups", "hashtags", "posts", "notifications", "reports", "accessTokens", "pushSubscriptions", "inviteLinks", "jamEvents", "mediaAttachments", "processingStats", "profileSettings"];
|
|
2
|
+
export declare const EDGE_IMPORT_ORDER: readonly ["controls", "follows", "blocks", "requestsFollow", "mentions", "audience", "postHashtags", "entries", "replyTo", "repost", "bookmarks", "postSeen", "hasSeen", "hasRead", "userGroups", "postGroups", "hasRole", "profileAccessTokens", "accountToPushSubscription", "createdReport", "isReportedProfile", "isReportedObject", "inviteLinkCreators", "inviteLinkRedeemers", "jamRecordings", "profileHashtags"];
|
|
27
3
|
export declare const readJsonl: (filePath: string) => Promise<Record<string, unknown>[]>;
|
|
28
|
-
export declare const readManifest: (exportDir: string) => Promise<MigrationManifest>;
|
|
29
|
-
export declare const writeManifest: (exportDir: string, manifest: MigrationManifest) => Promise<void>;
|
|
30
|
-
export declare const writeImportStats: (exportDir: string, collections: CollectionCounts) => Promise<void>;
|
|
31
|
-
export declare const readImportStats: (exportDir: string) => Promise<ImportStats | null>;
|
|
32
|
-
/** Prefer post-import counts when present (skips / remaps / dedupe). */
|
|
33
|
-
export declare const expectedCollectionCount: (collection: string, manifestCounts: CollectionCounts, importedCounts: CollectionCounts | null) => number;
|
|
34
|
-
export declare const assertExportDir: (exportDir: string) => Promise<void>;
|
|
35
4
|
export declare const BATCH_SIZE = 500;
|
|
@@ -5,25 +5,11 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
5
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
6
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
7
7
|
};
|
|
8
|
-
import { createHash } from 'node:crypto';
|
|
9
8
|
import { createReadStream } from 'node:fs';
|
|
10
|
-
import { access, readFile, writeFile } from 'node:fs/promises';
|
|
11
|
-
import { constants } from 'node:fs';
|
|
12
9
|
import { createInterface } from 'node:readline';
|
|
13
|
-
import { join } from 'node:path';
|
|
14
|
-
import dotenv from 'dotenv';
|
|
15
|
-
dotenv.config();
|
|
16
|
-
export const DEFAULT_EXPORT_DIR = './arango-export';
|
|
17
|
-
export const exportDirFromEnv = () => { var _a; return (_a = process.env.MIGRATION_EXPORT_DIR) !== null && _a !== void 0 ? _a : DEFAULT_EXPORT_DIR; };
|
|
18
|
-
export const collectionsDir = (exportDir) => join(exportDir, 'collections');
|
|
19
|
-
export const manifestPath = (exportDir) => join(exportDir, 'manifest.json');
|
|
20
|
-
/** Counts actually inserted into Postgres (after skips / remaps / dedupe). */
|
|
21
|
-
export const importStatsPath = (exportDir) => join(exportDir, 'import-stats.json');
|
|
22
|
-
export const collectionFilePath = (exportDir, collection) => join(collectionsDir(exportDir), `${collection}.jsonl`);
|
|
23
10
|
export const DOCUMENT_IMPORT_ORDER = [
|
|
24
11
|
'configs',
|
|
25
12
|
'i18n',
|
|
26
|
-
'dataMigrations',
|
|
27
13
|
'accounts',
|
|
28
14
|
'roles',
|
|
29
15
|
'profiles',
|
|
@@ -43,12 +29,12 @@ export const DOCUMENT_IMPORT_ORDER = [
|
|
|
43
29
|
export const EDGE_IMPORT_ORDER = [
|
|
44
30
|
'controls',
|
|
45
31
|
'follows',
|
|
32
|
+
'blocks',
|
|
46
33
|
'requestsFollow',
|
|
47
34
|
'mentions',
|
|
48
35
|
'audience',
|
|
49
36
|
'postHashtags',
|
|
50
37
|
'entries',
|
|
51
|
-
'reactions',
|
|
52
38
|
'replyTo',
|
|
53
39
|
'repost',
|
|
54
40
|
'bookmarks',
|
|
@@ -66,9 +52,8 @@ export const EDGE_IMPORT_ORDER = [
|
|
|
66
52
|
'inviteLinkCreators',
|
|
67
53
|
'inviteLinkRedeemers',
|
|
68
54
|
'jamRecordings',
|
|
55
|
+
'profileHashtags',
|
|
69
56
|
];
|
|
70
|
-
export const sha256 = (value) => createHash('sha256').update(value).digest('hex');
|
|
71
|
-
export const sortedChecksum = (values) => sha256(values.filter(Boolean).sort().join('\n'));
|
|
72
57
|
export const readJsonl = async (filePath) => {
|
|
73
58
|
var _a, e_1, _b, _c;
|
|
74
59
|
const docs = [];
|
|
@@ -113,39 +98,4 @@ export const readJsonl = async (filePath) => {
|
|
|
113
98
|
}
|
|
114
99
|
return docs;
|
|
115
100
|
};
|
|
116
|
-
export const readManifest = async (exportDir) => {
|
|
117
|
-
const raw = await readFile(manifestPath(exportDir), 'utf-8');
|
|
118
|
-
return JSON.parse(raw);
|
|
119
|
-
};
|
|
120
|
-
export const writeManifest = async (exportDir, manifest) => {
|
|
121
|
-
await writeFile(manifestPath(exportDir), JSON.stringify(manifest, null, 2));
|
|
122
|
-
};
|
|
123
|
-
export const writeImportStats = async (exportDir, collections) => {
|
|
124
|
-
const stats = {
|
|
125
|
-
importedAt: new Date().toISOString(),
|
|
126
|
-
collections,
|
|
127
|
-
};
|
|
128
|
-
await writeFile(importStatsPath(exportDir), JSON.stringify(stats, null, 2));
|
|
129
|
-
};
|
|
130
|
-
export const readImportStats = async (exportDir) => {
|
|
131
|
-
try {
|
|
132
|
-
await access(importStatsPath(exportDir), constants.F_OK);
|
|
133
|
-
}
|
|
134
|
-
catch (_a) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
const raw = await readFile(importStatsPath(exportDir), 'utf-8');
|
|
138
|
-
return JSON.parse(raw);
|
|
139
|
-
};
|
|
140
|
-
/** Prefer post-import counts when present (skips / remaps / dedupe). */
|
|
141
|
-
export const expectedCollectionCount = (collection, manifestCounts, importedCounts) => {
|
|
142
|
-
var _a, _b;
|
|
143
|
-
return importedCounts
|
|
144
|
-
? ((_a = importedCounts[collection]) !== null && _a !== void 0 ? _a : 0)
|
|
145
|
-
: ((_b = manifestCounts[collection]) !== null && _b !== void 0 ? _b : 0);
|
|
146
|
-
};
|
|
147
|
-
export const assertExportDir = async (exportDir) => {
|
|
148
|
-
await access(manifestPath(exportDir), constants.F_OK);
|
|
149
|
-
await access(collectionsDir(exportDir), constants.F_OK);
|
|
150
|
-
};
|
|
151
101
|
export const BATCH_SIZE = 500;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CollectionInfo } from './map/queryTypes';
|
|
2
2
|
/** Named collection/edge refs aligned with `documentRegistry` and `edgeRegistry`. */
|
|
3
3
|
export declare const collectionInfos: {
|
|
4
|
-
readonly dataMigrationsCollection: CollectionInfo;
|
|
5
4
|
readonly i18nCollection: CollectionInfo;
|
|
6
5
|
readonly configCollection: CollectionInfo;
|
|
7
6
|
readonly accountsCollection: CollectionInfo;
|
|
8
7
|
readonly profilesCollection: CollectionInfo;
|
|
9
8
|
readonly followsCollection: CollectionInfo;
|
|
9
|
+
readonly blocksCollection: CollectionInfo;
|
|
10
10
|
readonly requestsFollowCollection: CollectionInfo;
|
|
11
11
|
readonly controlsCollection: CollectionInfo;
|
|
12
12
|
readonly postsCollection: CollectionInfo;
|
|
@@ -19,7 +19,6 @@ export declare const collectionInfos: {
|
|
|
19
19
|
readonly isReportedProfileCollection: CollectionInfo;
|
|
20
20
|
readonly isReportedObjectCollection: CollectionInfo;
|
|
21
21
|
readonly entriesCollection: CollectionInfo;
|
|
22
|
-
readonly reactionsCollection: CollectionInfo;
|
|
23
22
|
readonly repliesCollection: CollectionInfo;
|
|
24
23
|
readonly repostCollection: CollectionInfo;
|
|
25
24
|
readonly mediaAttachmentsCollection: CollectionInfo;
|
|
@@ -44,5 +43,6 @@ export declare const collectionInfos: {
|
|
|
44
43
|
readonly postSeenCollection: CollectionInfo;
|
|
45
44
|
readonly profileSettingsCollection: CollectionInfo;
|
|
46
45
|
readonly jamRecordingsCollection: CollectionInfo;
|
|
46
|
+
readonly profileHashtagsCollection: CollectionInfo;
|
|
47
47
|
};
|
|
48
48
|
export type CollectionInfoKey = keyof typeof collectionInfos;
|