@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
|
@@ -6,17 +6,16 @@ const DEFAULT_SETTINGS = {
|
|
|
6
6
|
recipients: [],
|
|
7
7
|
};
|
|
8
8
|
export const getAnalyticsReportSettings = async () => {
|
|
9
|
-
var _a, _b, _c, _d;
|
|
10
9
|
const db = await database();
|
|
11
10
|
const rows = await db
|
|
12
11
|
.select()
|
|
13
12
|
.from(analyticsSettings)
|
|
14
13
|
.where(eq(analyticsSettings.id, 'default'))
|
|
15
14
|
.limit(1);
|
|
16
|
-
const body = (
|
|
15
|
+
const body = (rows[0]?.body ?? {});
|
|
17
16
|
return {
|
|
18
|
-
enabled:
|
|
19
|
-
recipients:
|
|
17
|
+
enabled: body.enabled ?? DEFAULT_SETTINGS.enabled,
|
|
18
|
+
recipients: body.recipients ?? DEFAULT_SETTINGS.recipients,
|
|
20
19
|
};
|
|
21
20
|
};
|
|
22
21
|
export const setAnalyticsReportSettings = async (settings) => {
|
package/dist/backups/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { access, cp, mkdir, mkdtemp, readdir, rm, writeFile, readFile, } from 'node:fs/promises';
|
|
1
|
+
import { access, cp, mkdir, mkdtemp, readdir, rm, writeFile, readFile, stat, } from 'node:fs/promises';
|
|
2
2
|
import { constants, createWriteStream } from 'node:fs';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
4
|
import { emptyDir } from 'fs-extra';
|
|
@@ -7,26 +7,30 @@ import { tmpdir } from 'node:os';
|
|
|
7
7
|
import archiver from 'archiver';
|
|
8
8
|
import extract from 'extract-zip';
|
|
9
9
|
import { collectionInfos } from '../db/index.js';
|
|
10
|
-
import { communityConfig, config } from '../config/index.js';
|
|
11
|
-
import { exportAllPostgresCollections,
|
|
10
|
+
import { communityConfig, config, defaultConfig } from '../config/index.js';
|
|
11
|
+
import { exportAllPostgresCollections, importAllPostgresCollections, } from '../db/migration/importCollections.js';
|
|
12
12
|
import { getLatestSchemaVersion } from '../db/pg/migrate.js';
|
|
13
13
|
import { replaceOrigin } from '../db/replaceOrigin.js';
|
|
14
14
|
import { logger } from '../log/index.js';
|
|
15
15
|
import { setDefaultRoles } from '../roles/index.js';
|
|
16
|
+
import { backfillMissingEventOccurrences } from '../posts/eventOccurrences.js';
|
|
16
17
|
import { serverRootUrl } from '../server/index.js';
|
|
17
|
-
import {
|
|
18
|
+
import { linkHostPeerDependencies } from '../plugins/index.js';
|
|
19
|
+
import { resolveBackupDatabaseType } from './metadata.js';
|
|
18
20
|
export { resolveBackupDatabaseType } from './metadata.js';
|
|
19
21
|
const log = logger('core:backups');
|
|
22
|
+
const pathExists = (p) => access(p)
|
|
23
|
+
.then(() => true)
|
|
24
|
+
.catch(() => false);
|
|
20
25
|
/** Safety net if extraction stalls (normal 1 GiB restore finishes in a few minutes). */
|
|
21
26
|
const EXTRACT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
22
27
|
const extractWithUnzipCli = (zipPath, tempDir) => {
|
|
23
|
-
var _a, _b;
|
|
24
28
|
const proc = spawn('unzip', ['-qq', '-o', zipPath, '-d', tempDir], {
|
|
25
29
|
stdio: ['ignore', 'ignore', 'pipe'],
|
|
26
30
|
});
|
|
27
31
|
let stderrTail = '';
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
proc.stderr?.setEncoding('utf8');
|
|
33
|
+
proc.stderr?.on('data', (chunk) => {
|
|
30
34
|
stderrTail = (stderrTail + chunk).slice(-4096);
|
|
31
35
|
});
|
|
32
36
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -41,7 +45,7 @@ const extractWithUnzipCli = (zipPath, tempDir) => {
|
|
|
41
45
|
return;
|
|
42
46
|
}
|
|
43
47
|
const detail = stderrTail.trim();
|
|
44
|
-
reject(new Error(`unzip exited with code ${code
|
|
48
|
+
reject(new Error(`unzip exited with code ${code ?? 'null'}${detail ? `: ${detail}` : ''}`));
|
|
45
49
|
});
|
|
46
50
|
});
|
|
47
51
|
return {
|
|
@@ -79,7 +83,7 @@ const extractZipArchive = (zipPath, tempDir) => {
|
|
|
79
83
|
promise,
|
|
80
84
|
kill: () => {
|
|
81
85
|
cli.kill();
|
|
82
|
-
fallbackKill
|
|
86
|
+
fallbackKill?.();
|
|
83
87
|
},
|
|
84
88
|
};
|
|
85
89
|
};
|
|
@@ -104,13 +108,47 @@ const zipDirectory = (sourceDir, zipPath) => new Promise((resolve, reject) => {
|
|
|
104
108
|
archive.directory(sourceDir, false);
|
|
105
109
|
void archive.finalize();
|
|
106
110
|
});
|
|
111
|
+
/**
|
|
112
|
+
* Peer-dependency symlinks in a restored plugin were created against the host
|
|
113
|
+
* packages of the image the backup came from. Re-anchor them to the current
|
|
114
|
+
* host tree so restored plugins resolve even after an image update.
|
|
115
|
+
*/
|
|
116
|
+
const relinkRestoredPlugins = async (pluginsPath) => {
|
|
117
|
+
const namespaces = await readdir(pluginsPath).catch(() => []);
|
|
118
|
+
for (const namespace of namespaces) {
|
|
119
|
+
const namespaceDir = join(pluginsPath, namespace);
|
|
120
|
+
if (!(await stat(namespaceDir)
|
|
121
|
+
.then((s) => s.isDirectory())
|
|
122
|
+
.catch(() => false))) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const names = await readdir(namespaceDir).catch(() => []);
|
|
126
|
+
for (const name of names) {
|
|
127
|
+
const pluginDir = join(namespaceDir, name);
|
|
128
|
+
let pkg;
|
|
129
|
+
try {
|
|
130
|
+
pkg = JSON.parse(await readFile(join(pluginDir, 'package.json'), 'utf8'));
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const peers = Object.keys(pkg.peerDependencies ?? {});
|
|
136
|
+
if (peers.length === 0)
|
|
137
|
+
continue;
|
|
138
|
+
const linked = await linkHostPeerDependencies(pluginDir, peers);
|
|
139
|
+
if (!linked.success) {
|
|
140
|
+
log.warn(`Restored plugin ${pkg.name ?? pluginDir} peer re-link failed: ${linked.error}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
107
145
|
const withTimeout = (promise, ms, message, onTimeout) => {
|
|
108
146
|
let timeoutId;
|
|
109
147
|
return Promise.race([
|
|
110
148
|
promise,
|
|
111
149
|
new Promise((_, reject) => {
|
|
112
150
|
timeoutId = setTimeout(() => {
|
|
113
|
-
onTimeout
|
|
151
|
+
onTimeout?.();
|
|
114
152
|
reject(new Error(message));
|
|
115
153
|
}, ms);
|
|
116
154
|
}),
|
|
@@ -137,14 +175,13 @@ const assertBackupExtracted = async (tempDir) => {
|
|
|
137
175
|
try {
|
|
138
176
|
await access(metadataPath, constants.F_OK);
|
|
139
177
|
}
|
|
140
|
-
catch
|
|
141
|
-
|
|
142
|
-
log.warn(`Backup has no metadata.json under ${tempDir}; treating as legacy Arango JSONL`);
|
|
178
|
+
catch {
|
|
179
|
+
throw new Error('Backup invalid: missing metadata.json (Postgres JSONL archives only)');
|
|
143
180
|
}
|
|
144
181
|
try {
|
|
145
182
|
await access(collectionsPath, constants.F_OK);
|
|
146
183
|
}
|
|
147
|
-
catch
|
|
184
|
+
catch {
|
|
148
185
|
throw new Error('Backup invalid: missing collections/ directory after extract');
|
|
149
186
|
}
|
|
150
187
|
const files = await readdir(collectionsPath);
|
|
@@ -154,15 +191,14 @@ const assertBackupExtracted = async (tempDir) => {
|
|
|
154
191
|
}
|
|
155
192
|
log.info(`Found ${jsonlFiles.length} collection backup files in archive`);
|
|
156
193
|
};
|
|
157
|
-
const restoreDatabaseFromBackup = async (collectionsDir,
|
|
158
|
-
log.info('Restoring
|
|
159
|
-
const { total } =
|
|
160
|
-
? await importAllPostgresCollections(collectionsDir, schemaVersion)
|
|
161
|
-
: await importAllArangoCollections(collectionsDir);
|
|
194
|
+
const restoreDatabaseFromBackup = async (collectionsDir, schemaVersion) => {
|
|
195
|
+
log.info('Restoring postgres database from JSONL collections');
|
|
196
|
+
const { total } = await importAllPostgresCollections(collectionsDir, schemaVersion);
|
|
162
197
|
if (total === 0) {
|
|
163
198
|
throw new Error('Backup restore completed with zero rows; archive may be empty or corrupt');
|
|
164
199
|
}
|
|
165
|
-
|
|
200
|
+
const backfilled = await backfillMissingEventOccurrences();
|
|
201
|
+
log.info('Restored %d database rows from backup; indexed %d events', total, backfilled);
|
|
166
202
|
};
|
|
167
203
|
export const createBackup = async () => {
|
|
168
204
|
try {
|
|
@@ -187,6 +223,14 @@ export const createBackup = async () => {
|
|
|
187
223
|
await cp(coreConfig.logs.local.path, logsDir, {
|
|
188
224
|
recursive: true,
|
|
189
225
|
});
|
|
226
|
+
// Admin-installed plugins, so restores and moves carry them with the
|
|
227
|
+
// instance. Missing (e.g. fresh installs) is not an error.
|
|
228
|
+
const pluginsPath = defaultConfig.plugins.path;
|
|
229
|
+
if (await pathExists(pluginsPath)) {
|
|
230
|
+
const backupPluginsDir = join(backupDir, 'plugins');
|
|
231
|
+
await mkdir(backupPluginsDir);
|
|
232
|
+
await cp(pluginsPath, backupPluginsDir, { recursive: true });
|
|
233
|
+
}
|
|
190
234
|
await writeFile(join(metaDir, 'collectionInfos.json'), JSON.stringify(collectionInfos, null, 2));
|
|
191
235
|
await writeFile(join(backupDir, 'metadata.json'), JSON.stringify({
|
|
192
236
|
databaseType: 'postgres',
|
|
@@ -219,7 +263,6 @@ export const listAllBackups = async () => {
|
|
|
219
263
|
.map((filename) => filename.replace('.zip', ''));
|
|
220
264
|
};
|
|
221
265
|
export const restoreBackups = async (zipFilePath) => {
|
|
222
|
-
var _a, _b, _c;
|
|
223
266
|
console.log('Restoring backup', zipFilePath);
|
|
224
267
|
log.info(`Restoring backup ${zipFilePath}`);
|
|
225
268
|
const coreConfig = await config();
|
|
@@ -244,7 +287,7 @@ export const restoreBackups = async (zipFilePath) => {
|
|
|
244
287
|
const backupMetadata = await readFile(join(tempDir, 'metadata.json'), 'utf-8')
|
|
245
288
|
.then(JSON.parse)
|
|
246
289
|
.catch(() => undefined);
|
|
247
|
-
|
|
290
|
+
resolveBackupDatabaseType(backupMetadata);
|
|
248
291
|
log.info(`Emptying media directory ${coreConfig.media.storage.params.path}`);
|
|
249
292
|
await emptyDir(coreConfig.media.storage.params.path);
|
|
250
293
|
log.info(`Copying media from backup to ${coreConfig.media.storage.params.path}`);
|
|
@@ -257,12 +300,26 @@ export const restoreBackups = async (zipFilePath) => {
|
|
|
257
300
|
await cp(join(tempDir, 'logs'), coreConfig.logs.local.path, {
|
|
258
301
|
recursive: true,
|
|
259
302
|
});
|
|
260
|
-
|
|
303
|
+
// Older images never archived plugins; never wipe a live plugins tree for
|
|
304
|
+
// such a backup.
|
|
305
|
+
const pluginsPath = defaultConfig.plugins.path;
|
|
306
|
+
const backupPluginsDir = join(tempDir, 'plugins');
|
|
307
|
+
if (await pathExists(backupPluginsDir)) {
|
|
308
|
+
log.info(`Emptying plugins directory ${pluginsPath}`);
|
|
309
|
+
await emptyDir(pluginsPath);
|
|
310
|
+
log.info(`Copying plugins from backup to ${pluginsPath}`);
|
|
311
|
+
await cp(backupPluginsDir, pluginsPath, { recursive: true });
|
|
312
|
+
await relinkRestoredPlugins(pluginsPath);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
log.info('Backup contains no plugins; leaving existing plugins in place.');
|
|
316
|
+
}
|
|
317
|
+
await restoreDatabaseFromBackup(collectionsDir, backupMetadata?.schemaVersion);
|
|
261
318
|
// Repoint the backup's absolute URLs at this server's full origin (scheme +
|
|
262
319
|
// host + port). Matching by the backup hostname means a prod backup on
|
|
263
320
|
// `https://host` restores cleanly onto `http://localhost:5174` without
|
|
264
321
|
// stranding the old scheme/port.
|
|
265
|
-
await replaceOrigin(
|
|
266
|
-
log.info(`Restored
|
|
322
|
+
await replaceOrigin(backupMetadata?.config?.hostname, await serverRootUrl());
|
|
323
|
+
log.info(`Restored postgres backup (hostname was ${backupMetadata?.config?.hostname ?? 'unknown'})`);
|
|
267
324
|
await setDefaultRoles();
|
|
268
325
|
};
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
export type BackupDatabaseType = '
|
|
1
|
+
export type BackupDatabaseType = 'postgres';
|
|
2
2
|
export type BackupMetadata = {
|
|
3
3
|
databaseType?: BackupDatabaseType;
|
|
4
4
|
/** When this backup archive was created (ISO-8601). */
|
|
5
5
|
createdAt?: string;
|
|
6
6
|
/**
|
|
7
7
|
* Drizzle journal tag the database was on when the backup was created
|
|
8
|
-
* (e.g. `0007_shallow_oracle`).
|
|
8
|
+
* (e.g. `0007_shallow_oracle`).
|
|
9
9
|
*/
|
|
10
10
|
schemaVersion?: string;
|
|
11
11
|
config?: {
|
|
12
12
|
hostname?: string;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
/** Legacy Arango backups omit databaseType; treat them as Arango JSONL. */
|
|
16
15
|
export declare const resolveBackupDatabaseType: (metadata?: BackupMetadata) => BackupDatabaseType;
|
package/dist/backups/metadata.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export const resolveBackupDatabaseType = (metadata) => {
|
|
2
|
+
if (metadata?.databaseType === 'postgres') {
|
|
3
|
+
return 'postgres';
|
|
4
|
+
}
|
|
5
|
+
throw new Error('Backup is not a Postgres JSONL archive (missing metadata.json databaseType: "postgres")');
|
|
6
|
+
};
|
package/dist/config/db.js
CHANGED
|
@@ -3,7 +3,6 @@ import { allpeepDb } from '../db/index.js';
|
|
|
3
3
|
import { configs } from '../db/pg/schema/documents.js';
|
|
4
4
|
import { nowIso } from '../db/pg/mappers.js';
|
|
5
5
|
export const storeConfig = (key, config) => allpeepDb().then(async ({ db }) => {
|
|
6
|
-
var _a;
|
|
7
6
|
const ts = nowIso();
|
|
8
7
|
const rows = await db
|
|
9
8
|
.insert(configs)
|
|
@@ -13,14 +12,13 @@ export const storeConfig = (key, config) => allpeepDb().then(async ({ db }) => {
|
|
|
13
12
|
set: { body: config, updatedAt: ts },
|
|
14
13
|
})
|
|
15
14
|
.returning();
|
|
16
|
-
return
|
|
15
|
+
return rows[0]?.body;
|
|
17
16
|
});
|
|
18
17
|
export const loadConfig = (key) => allpeepDb().then(async ({ db }) => {
|
|
19
|
-
var _a;
|
|
20
18
|
const rows = await db
|
|
21
19
|
.select()
|
|
22
20
|
.from(configs)
|
|
23
21
|
.where(eq(configs.key, key))
|
|
24
22
|
.limit(1);
|
|
25
|
-
return
|
|
23
|
+
return rows[0]?.body;
|
|
26
24
|
});
|
|
@@ -35,8 +35,19 @@ export const defaultCapabilitiesConfig = {
|
|
|
35
35
|
],
|
|
36
36
|
},
|
|
37
37
|
self: { add: ['core-profiles-update', ...postCapabilities] },
|
|
38
|
-
blocked: {
|
|
39
|
-
|
|
38
|
+
blocked: {
|
|
39
|
+
remove: [
|
|
40
|
+
'core-posts-*',
|
|
41
|
+
'core-profiles-read',
|
|
42
|
+
'core-profiles-follow',
|
|
43
|
+
'core-profiles-unfollow',
|
|
44
|
+
'core-profiles-requestFollow',
|
|
45
|
+
'core-profiles-block',
|
|
46
|
+
'core-profiles-mute',
|
|
47
|
+
'core-profiles-unmute',
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
'blocked-by': { remove: ['*'] },
|
|
40
51
|
},
|
|
41
52
|
report: {
|
|
42
53
|
reporter: { add: ['core-reports-read'] },
|
|
@@ -7,14 +7,18 @@ export const defaultCommunityConfig = {
|
|
|
7
7
|
light: {
|
|
8
8
|
primaryHex: '#15678a',
|
|
9
9
|
logoSmall: '/img/logo-small.png',
|
|
10
|
-
defaultProfileAvatar
|
|
10
|
+
// No defaultProfileAvatar — profiles without a custom avatar fall back
|
|
11
|
+
// to letter initials in the Avatar component.
|
|
11
12
|
defaultGroupAvatar: '/img/default-group-avatar.svg',
|
|
12
13
|
backgroundAuth: '/img/background-auth.png',
|
|
13
14
|
},
|
|
14
15
|
dark: {
|
|
15
|
-
|
|
16
|
+
// Lighter than the light-mode primary so it stays readable on the
|
|
17
|
+
// near-black dark background.
|
|
18
|
+
primaryHex: '#38aee1',
|
|
16
19
|
logoSmall: '/img/logo-small-white.png',
|
|
17
|
-
defaultProfileAvatar
|
|
20
|
+
// No defaultProfileAvatar — profiles without a custom avatar fall back
|
|
21
|
+
// to letter initials in the Avatar component.
|
|
18
22
|
defaultGroupAvatar: '/img/default-group-avatar.svg',
|
|
19
23
|
backgroundAuth: '/img/background-auth.png',
|
|
20
24
|
},
|
|
@@ -26,6 +30,7 @@ export const defaultCommunityConfig = {
|
|
|
26
30
|
},
|
|
27
31
|
settings: {
|
|
28
32
|
openRegistrations: process.env.COMMUNITY_SETTINGS_OPEN_REGISTRATIONS !== 'false',
|
|
33
|
+
indexProfiles: process.env.COMMUNITY_SETTINGS_INDEX_PROFILES === 'true',
|
|
29
34
|
},
|
|
30
35
|
content: {},
|
|
31
36
|
roles: {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CoreConfig } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const defaultConfig: CoreConfig;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_MAX_MEDIA_UPLOAD_MB, } from '@openpeepshq/common/types';
|
|
1
2
|
import db from './db.js';
|
|
2
3
|
import redis from './redis.js';
|
|
3
4
|
import { readEnvInteger, resolveJwtSecret } from '../helpers.js';
|
|
@@ -20,17 +21,23 @@ export const defaultConfig = {
|
|
|
20
21
|
service: 'smtp',
|
|
21
22
|
defaultTemplatePath: 'assets/email/templates',
|
|
22
23
|
defaultFrom: process.env.EMAIL_DEFAULT_FROM,
|
|
23
|
-
transportConfig:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
transportConfig: {
|
|
25
|
+
host: process.env.EMAIL_CONFIG_HOST || 'localhost',
|
|
26
|
+
port: readEnvInteger('EMAIL_CONFIG_PORT', 465),
|
|
27
|
+
secure: process.env.EMAIL_CONFIG_SECURE !== 'false',
|
|
28
|
+
...(process.env.EMAIL_CONFIG_AUTH_USER
|
|
29
|
+
? {
|
|
30
|
+
auth: {
|
|
31
|
+
user: process.env.EMAIL_CONFIG_AUTH_USER,
|
|
32
|
+
pass: process.env.EMAIL_CONFIG_AUTH_PASS,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
36
|
+
},
|
|
31
37
|
},
|
|
32
38
|
logs,
|
|
33
39
|
media: {
|
|
40
|
+
maxUploadMb: DEFAULT_MAX_MEDIA_UPLOAD_MB,
|
|
34
41
|
storage: {
|
|
35
42
|
driver: 'openpeeps',
|
|
36
43
|
params: {
|
|
@@ -65,6 +72,7 @@ export const defaultConfig = {
|
|
|
65
72
|
},
|
|
66
73
|
federation: {
|
|
67
74
|
active: false,
|
|
75
|
+
allowedHosts: [],
|
|
68
76
|
},
|
|
69
77
|
activityPub: {
|
|
70
78
|
defaultDomain: process.env.ACTIVITY_PUB_DEFAULT_DOMAIN || 'localhost',
|
package/dist/config/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export declare const config: <T = {
|
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
53
|
media: {
|
|
54
|
+
maxUploadMb: number;
|
|
54
55
|
storage: {
|
|
55
56
|
driver: "openpeeps";
|
|
56
57
|
params: {
|
|
@@ -84,6 +85,7 @@ export declare const config: <T = {
|
|
|
84
85
|
};
|
|
85
86
|
federation: {
|
|
86
87
|
active: boolean;
|
|
88
|
+
allowedHosts: string[];
|
|
87
89
|
};
|
|
88
90
|
activityPub: {
|
|
89
91
|
defaultDomain: string;
|
|
@@ -118,6 +120,10 @@ export declare const config: <T = {
|
|
|
118
120
|
tokenUrl: string;
|
|
119
121
|
userinfoUrl: string;
|
|
120
122
|
clientId: string;
|
|
123
|
+
kind?: "oidc" | "github" | "gitlab" | "gitlab-selfhosted" | "google" | "entra" | "auth0" | "keycloak" | "authentik" | "okta" | "discord" | "pocketid" | undefined;
|
|
124
|
+
instanceUrl?: string | undefined;
|
|
125
|
+
tenant?: string | undefined;
|
|
126
|
+
emailsUrl?: string | undefined;
|
|
121
127
|
jwksUri?: string | undefined;
|
|
122
128
|
clientSecret?: string | undefined;
|
|
123
129
|
scope?: string | undefined;
|
|
@@ -201,6 +207,13 @@ export declare const communityConfig: () => Promise<{
|
|
|
201
207
|
};
|
|
202
208
|
icon?: string | undefined;
|
|
203
209
|
mobileIcon?: string | undefined;
|
|
210
|
+
primaryHex?: string | undefined;
|
|
211
|
+
logoFull?: string | undefined;
|
|
212
|
+
logoSmall?: string | undefined;
|
|
213
|
+
defaultProfileAvatar?: string | undefined;
|
|
214
|
+
defaultGroupAvatar?: string | undefined;
|
|
215
|
+
backgroundAuth?: string | undefined;
|
|
216
|
+
background?: string | undefined;
|
|
204
217
|
};
|
|
205
218
|
info: {
|
|
206
219
|
name: string;
|
|
@@ -219,6 +232,9 @@ export declare const communityConfig: () => Promise<{
|
|
|
219
232
|
settings: {
|
|
220
233
|
openRegistrations: boolean;
|
|
221
234
|
defaultLanguage?: string | undefined;
|
|
235
|
+
defaultTimeZone?: string | undefined;
|
|
236
|
+
defaultFeedFormat?: "threaded" | "linear" | undefined;
|
|
237
|
+
indexProfiles?: boolean | undefined;
|
|
222
238
|
};
|
|
223
239
|
roles: {
|
|
224
240
|
onRegistration: {
|
|
@@ -277,6 +293,7 @@ export declare const sanitizedConfigWithDefaults: <T = {
|
|
|
277
293
|
};
|
|
278
294
|
};
|
|
279
295
|
media: {
|
|
296
|
+
maxUploadMb: number;
|
|
280
297
|
storage: {
|
|
281
298
|
driver: "openpeeps";
|
|
282
299
|
params: {
|
|
@@ -310,6 +327,7 @@ export declare const sanitizedConfigWithDefaults: <T = {
|
|
|
310
327
|
};
|
|
311
328
|
federation: {
|
|
312
329
|
active: boolean;
|
|
330
|
+
allowedHosts: string[];
|
|
313
331
|
};
|
|
314
332
|
activityPub: {
|
|
315
333
|
defaultDomain: string;
|
|
@@ -344,6 +362,10 @@ export declare const sanitizedConfigWithDefaults: <T = {
|
|
|
344
362
|
tokenUrl: string;
|
|
345
363
|
userinfoUrl: string;
|
|
346
364
|
clientId: string;
|
|
365
|
+
kind?: "oidc" | "github" | "gitlab" | "gitlab-selfhosted" | "google" | "entra" | "auth0" | "keycloak" | "authentik" | "okta" | "discord" | "pocketid" | undefined;
|
|
366
|
+
instanceUrl?: string | undefined;
|
|
367
|
+
tenant?: string | undefined;
|
|
368
|
+
emailsUrl?: string | undefined;
|
|
347
369
|
jwksUri?: string | undefined;
|
|
348
370
|
clientSecret?: string | undefined;
|
|
349
371
|
scope?: string | undefined;
|
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';
|
|
@@ -32,12 +34,15 @@ const initConfig = async (namespace, name) => {
|
|
|
32
34
|
if (!factory) {
|
|
33
35
|
throw new Error(`No config registered for ${key}`);
|
|
34
36
|
}
|
|
35
|
-
const customConfig =
|
|
37
|
+
const customConfig = customConfigDocument?.config &&
|
|
36
38
|
zodDeepPartialSchema(factory()).parse(pruneEmptyConfigStrings(customConfigDocument.config));
|
|
37
39
|
return (customConfig ? deepmerge(defaults, customConfig) : defaults);
|
|
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), {
|
|
@@ -51,8 +56,8 @@ const replaceStoredConfig = (config, namespace = 'openpeeps', name = 'core') =>
|
|
|
51
56
|
* admin UI forms and pin/unpin all send partial trees.
|
|
52
57
|
*/
|
|
53
58
|
export const updateConfigValues = (configValues, namespace = 'openpeeps', name = 'core') => loadConfig(configKey(namespace, name)).then((configDocument) => {
|
|
54
|
-
|
|
55
|
-
return replaceStoredConfig(deepmerge((
|
|
59
|
+
const stored = configDocument?.config ?? {};
|
|
60
|
+
return replaceStoredConfig(deepmerge(stored, restorePasswordPlaceholders(configValues, stored)), namespace, name);
|
|
56
61
|
});
|
|
57
62
|
export const config = (namespace = 'openpeeps', name = 'core') => {
|
|
58
63
|
const key = configKey(namespace, name);
|
|
@@ -67,17 +72,16 @@ export const config = (namespace = 'openpeeps', name = 'core') => {
|
|
|
67
72
|
return configPromises.get(key);
|
|
68
73
|
};
|
|
69
74
|
export const communityConfig = () => config('openpeeps', 'community');
|
|
70
|
-
export const capabilitiesConfig = () => config('openpeeps', 'capabilities').then((loaded) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
75
|
+
export const capabilitiesConfig = () => config('openpeeps', 'capabilities').then((loaded) => ({
|
|
76
|
+
...loaded,
|
|
77
|
+
accessToken: deepmerge(defaultCapabilitiesConfig.accessToken ?? {}, loaded.accessToken ?? {}),
|
|
78
|
+
}));
|
|
74
79
|
export const sanitizedConfigWithDefaults = async (namespace = 'openpeeps', name = 'core') => {
|
|
75
|
-
var _a;
|
|
76
80
|
const key = configKey(namespace, name);
|
|
77
|
-
const { defaults, factory } =
|
|
81
|
+
const { defaults, factory } = configSchemaRegistry.get(key) ?? {};
|
|
78
82
|
const sanitizedSchema = factory && factory(true);
|
|
79
83
|
return {
|
|
80
|
-
config: sanitizedSchema
|
|
81
|
-
defaults: sanitizedSchema
|
|
84
|
+
config: sanitizedSchema?.parse(await config(namespace, name)),
|
|
85
|
+
defaults: sanitizedSchema?.parse(defaults),
|
|
82
86
|
};
|
|
83
87
|
};
|
|
@@ -2,10 +2,10 @@ import { pgPool } from '../pg/client.js';
|
|
|
2
2
|
import { assertKnownColumns, describeExplorerTable, getExplorerTable, primaryKeyColumns, quoteIdent, } from './tables.js';
|
|
3
3
|
export const DEFAULT_ROW_LIMIT = 100;
|
|
4
4
|
/** Hard cap for browse page sizes (50 / 200 / 1000 / All). */
|
|
5
|
-
export const MAX_ROW_LIMIT =
|
|
6
|
-
export const MAX_EXPORT_LIMIT =
|
|
5
|
+
export const MAX_ROW_LIMIT = 10_000;
|
|
6
|
+
export const MAX_EXPORT_LIMIT = 10_000;
|
|
7
7
|
export const clampLimit = (limit, max) => {
|
|
8
|
-
const n = limit
|
|
8
|
+
const n = limit ?? DEFAULT_ROW_LIMIT;
|
|
9
9
|
if (!Number.isFinite(n) || n < 1)
|
|
10
10
|
return DEFAULT_ROW_LIMIT;
|
|
11
11
|
return Math.min(Math.floor(n), max);
|
|
@@ -21,13 +21,14 @@ export const buildFilterClause = (tableName, filters, params) => {
|
|
|
21
21
|
return ` WHERE ${parts.join(' AND ')}`;
|
|
22
22
|
};
|
|
23
23
|
export const listExplorerRows = async (input, options) => {
|
|
24
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
25
24
|
const tableName = input.table;
|
|
26
25
|
const meta = describeExplorerTable(getExplorerTable(tableName));
|
|
27
|
-
const maxLimit =
|
|
26
|
+
const maxLimit = options?.maxLimit ?? MAX_ROW_LIMIT;
|
|
28
27
|
const limit = clampLimit(input.limit, maxLimit);
|
|
29
|
-
const offset = Math.max(0, Math.floor(
|
|
30
|
-
const orderCol =
|
|
28
|
+
const offset = Math.max(0, Math.floor(input.offset ?? 0));
|
|
29
|
+
const orderCol = input.orderBy ??
|
|
30
|
+
primaryKeyColumns(tableName)[0]?.name ??
|
|
31
|
+
meta.columns[0]?.name;
|
|
31
32
|
if (!orderCol) {
|
|
32
33
|
throw new Error(`Table ${tableName} has no columns`);
|
|
33
34
|
}
|
|
@@ -36,7 +37,7 @@ export const listExplorerRows = async (input, options) => {
|
|
|
36
37
|
const where = buildFilterClause(tableName, input.filters, filterParams);
|
|
37
38
|
const tableSql = quoteIdent(tableName);
|
|
38
39
|
const countResult = await pgPool().query(`SELECT count(*)::text AS count FROM ${tableSql}${where}`, filterParams);
|
|
39
|
-
const total = Number(
|
|
40
|
+
const total = Number(countResult.rows[0]?.count ?? 0);
|
|
40
41
|
const result = await pgPool().query(`SELECT * FROM ${tableSql}${where} ORDER BY ${quoteIdent(orderCol)} LIMIT $${filterParams.length + 1} OFFSET $${filterParams.length + 2}`, [...filterParams, limit, offset]);
|
|
41
42
|
return {
|
|
42
43
|
columns: meta.columns.map((c) => c.name),
|
package/dist/db/explorer/sql.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { pgPool } from '../pg/client.js';
|
|
2
|
-
export const SQL_STATEMENT_TIMEOUT_MS =
|
|
2
|
+
export const SQL_STATEMENT_TIMEOUT_MS = 15_000;
|
|
3
3
|
/** Absolute cap for returned SQL rows (All). */
|
|
4
|
-
export const SQL_HARD_MAX_ROWS =
|
|
4
|
+
export const SQL_HARD_MAX_ROWS = 100_000;
|
|
5
5
|
/** Default cap when the client does not request a limit. */
|
|
6
|
-
export const SQL_DEFAULT_MAX_ROWS =
|
|
6
|
+
export const SQL_DEFAULT_MAX_ROWS = 1_000;
|
|
7
7
|
/** @deprecated Use SQL_HARD_MAX_ROWS */
|
|
8
8
|
export const SQL_MAX_ROWS = SQL_HARD_MAX_ROWS;
|
|
9
9
|
export const runExplorerSql = async (statement, options) => {
|
|
10
|
-
var _a, _b, _c;
|
|
11
10
|
const trimmed = statement.trim();
|
|
12
11
|
if (!trimmed) {
|
|
13
12
|
throw new Error('SQL statement is empty');
|
|
14
13
|
}
|
|
15
|
-
const requested = options
|
|
14
|
+
const requested = options?.limit;
|
|
16
15
|
const maxRows = requested != null && Number.isFinite(requested) && requested > 0
|
|
17
16
|
? Math.min(Math.floor(requested), SQL_HARD_MAX_ROWS)
|
|
18
17
|
: SQL_DEFAULT_MAX_ROWS;
|
|
@@ -22,11 +21,12 @@ export const runExplorerSql = async (statement, options) => {
|
|
|
22
21
|
const result = await client.query(trimmed);
|
|
23
22
|
const allRows = result.rows;
|
|
24
23
|
const rows = allRows.slice(0, maxRows);
|
|
25
|
-
const columns =
|
|
24
|
+
const columns = result.fields?.map((f) => f.name) ??
|
|
25
|
+
(rows[0] ? Object.keys(rows[0]) : []);
|
|
26
26
|
return {
|
|
27
27
|
columns,
|
|
28
28
|
rows,
|
|
29
|
-
rowCount:
|
|
29
|
+
rowCount: result.rowCount ?? allRows.length,
|
|
30
30
|
command: result.command,
|
|
31
31
|
};
|
|
32
32
|
}
|
|
@@ -34,7 +34,7 @@ export const runExplorerSql = async (statement, options) => {
|
|
|
34
34
|
try {
|
|
35
35
|
await client.query('SET statement_timeout = 0');
|
|
36
36
|
}
|
|
37
|
-
catch
|
|
37
|
+
catch {
|
|
38
38
|
// ignore reset failures on a broken connection
|
|
39
39
|
}
|
|
40
40
|
client.release();
|
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?: {
|