@openpeepshq/core 0.1.34 → 0.2.0
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 +13 -8
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +1 -2
- 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 +116 -135
- package/dist/analytics/report.d.ts +2 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +13 -16
- package/dist/backups/metadata.js +1 -1
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/community.js +1 -0
- package/dist/config/defaults/core.js +13 -8
- package/dist/config/defaults/logs.d.ts +4 -0
- package/dist/config/defaults/logs.js +5 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.js +9 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.js +15 -5
- package/dist/db/migration/importCollections.js +15 -18
- package/dist/db/migration/shared.js +15 -35
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +2 -0
- package/dist/db/pg/filters/posts.js +3 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +8 -8
- 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 +56 -21
- package/dist/db/pg/map/registry.js +87 -50
- package/dist/db/pg/map/relations.js +67 -63
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.js +2 -3
- package/dist/db/pg/queries/activity.js +2 -2
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/schema/documents.js +119 -18
- package/dist/db/pg/schema/edges.js +7 -1
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/_journal.json +8 -1
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +7 -4
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.js +1 -2
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.js +2 -2
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.js +5 -7
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +6 -4
- package/dist/jams/health.js +15 -11
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.js +2 -2
- package/dist/jams/jobs.js +1 -2
- package/dist/jams/livekit.d.ts +2 -2
- package/dist/jams/livekit.js +8 -8
- package/dist/jams/mapping.d.ts +10 -10
- package/dist/jams/mutations.d.ts +2 -2
- package/dist/jams/recording.js +1 -1
- package/dist/jams/token.js +13 -17
- package/dist/jobs/index.js +7 -6
- package/dist/jobs/jobDetail.js +5 -6
- 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.d.ts +1 -0
- package/dist/log/index.js +14 -29
- package/dist/log/retention.d.ts +9 -0
- package/dist/log/retention.js +83 -0
- package/dist/log/retentionJobs.d.ts +17 -0
- package/dist/log/retentionJobs.js +50 -0
- package/dist/media/index.js +127 -4
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +7 -4
- 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/mediaAttachments/mapping.d.ts +1 -1
- 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 +14 -17
- 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/jamModerator/index.js +27 -20
- package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
- package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
- 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 +9 -10
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
- 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.js +24 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
- package/dist/notifications/eventIcsAttachment.d.ts +6 -0
- package/dist/notifications/eventIcsAttachment.js +32 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.d.ts +11 -1
- package/dist/notifications/helpers.js +38 -9
- package/dist/notifications/jobs.js +16 -7
- package/dist/notifications/mutations.js +13 -2
- 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 +2 -3
- package/dist/plugins/install.js +31 -17
- package/dist/plugins/pluginAuth.js +3 -4
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +1 -1
- package/dist/posts/activity.js +2 -3
- package/dist/posts/contextClosure.js +1 -2
- package/dist/posts/conversationQueries.js +2 -4
- package/dist/posts/eventAgenda.js +12 -7
- package/dist/posts/eventOccurrences.js +2 -2
- package/dist/posts/finders.d.ts +46 -6
- package/dist/posts/finders.js +21 -9
- package/dist/posts/helpers/filters.js +2 -3
- package/dist/posts/helpers/index.d.ts +170 -18
- package/dist/posts/helpers/index.js +43 -27
- package/dist/posts/mapping.d.ts +616 -84
- package/dist/posts/mapping.js +60 -18
- package/dist/posts/mutations.d.ts +85 -9
- package/dist/posts/mutations.js +47 -34
- package/dist/posts/pollEnd.js +3 -6
- package/dist/posts/rsvpConfirmationEmail.js +18 -8
- package/dist/posts/threadPreview.js +1 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +1 -2
- package/dist/profileSettings/mapping.d.ts +1 -0
- package/dist/profiles/activitySummary.js +23 -28
- package/dist/profiles/cache.js +15 -8
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.js +7 -5
- package/dist/profiles/mapping.d.ts +10 -10
- package/dist/profiles/mutations.js +3 -5
- package/dist/redis/connection.js +1 -1
- package/dist/reports/helpers.js +7 -3
- package/dist/reports/mapping.d.ts +1 -1
- package/dist/roles/mutations.js +20 -21
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- 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 +1 -0
- package/dist/server/index.js +16 -11
- package/dist/server/status.js +6 -7
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.js +13 -4
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +43 -5
- package/dist/stats/mapping.js +9 -2
- 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 -6
- package/LICENSE +0 -674
|
@@ -43,6 +43,8 @@ export const postFilters = {
|
|
|
43
43
|
return pgSql(or(eq(posts.creatorId, profileId), followed, groupMemberPost));
|
|
44
44
|
},
|
|
45
45
|
type: (type) => pgSql(eq(posts.type, type)),
|
|
46
|
+
inGroup: (groupId) => pgSql(sql `EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text AND ${postGroups.toId} = ${groupId})`),
|
|
47
|
+
notInAnyGroup: () => pgSql(sql `NOT EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text)`),
|
|
46
48
|
replyCount: (op, count) => pgSql(compareCount(postsReplyCountExpr, op, count)),
|
|
47
49
|
replyCountZero: () => postFilters.replyCount('==', 0),
|
|
48
50
|
replyCountPositive: () => postFilters.replyCount('>', 0),
|
|
@@ -53,7 +55,7 @@ export const postFilters = {
|
|
|
53
55
|
: undefined,
|
|
54
56
|
};
|
|
55
57
|
export const eventTimeFilters = {
|
|
56
|
-
upcoming: (now = new Date().toISOString()) => pgSql(
|
|
58
|
+
upcoming: (now = new Date().toISOString()) => pgSql(sql `${eventEffectiveEnd} >= ${now}::timestamptz`),
|
|
57
59
|
current: (now = new Date().toISOString()) => pgSql(and(sql `${eventStart}::timestamptz <= ${now}::timestamptz`, sql `${eventEffectiveEnd} >= ${now}::timestamptz`)),
|
|
58
60
|
past: (now = new Date().toISOString()) => pgSql(sql `${eventEffectiveEnd} < ${now}::timestamptz`),
|
|
59
61
|
};
|
package/dist/db/pg/helpers.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { and, eq, isNull, sql } from 'drizzle-orm';
|
|
13
2
|
import { nowIso } from './mappers.js';
|
|
14
3
|
import { uuidv7 } from 'uuidv7';
|
|
@@ -37,7 +26,7 @@ export const softDeleteById = async (db, table, id) => {
|
|
|
37
26
|
export const insertEdge = async (db, table, fromId, toId, body = {}) => {
|
|
38
27
|
// Callers (e.g. jam recordings) pass a pre-generated id on the body; use it
|
|
39
28
|
// as the row primary key and keep it out of jsonb so finds/updates match.
|
|
40
|
-
const { id: providedId
|
|
29
|
+
const { id: providedId, ...edgeBody } = body;
|
|
41
30
|
const id = typeof providedId === 'string' && providedId.length > 0
|
|
42
31
|
? providedId
|
|
43
32
|
: uuidv7();
|
|
@@ -58,10 +47,9 @@ export const deleteEdge = async (db, table, fromId, toId) => {
|
|
|
58
47
|
.where(and(eq(table.fromId, fromId), eq(table.toId, toId)));
|
|
59
48
|
};
|
|
60
49
|
export const countRows = async (db, table, where) => {
|
|
61
|
-
var _a, _b;
|
|
62
50
|
const query = db
|
|
63
51
|
.select({ count: sql `count(*)::int` })
|
|
64
52
|
.from(table);
|
|
65
53
|
const result = (where ? await query.where(where) : await query);
|
|
66
|
-
return
|
|
54
|
+
return result[0]?.count ?? 0;
|
|
67
55
|
};
|
|
@@ -57,7 +57,7 @@ export const evaluateStringFilter = (doc, expression) => {
|
|
|
57
57
|
const fn = new Function('doc', 'CHECK_CAPABILITIES', 'MERGE_CAPABILITIES', `return ${normalizeAqlExpression(expression)};`);
|
|
58
58
|
return Boolean(fn(doc, checkCapabilities, mergeCapabilities));
|
|
59
59
|
}
|
|
60
|
-
catch
|
|
60
|
+
catch {
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
63
|
};
|
|
@@ -90,7 +90,7 @@ export const evaluateFilter = (doc, filter) => {
|
|
|
90
90
|
if (parsed) {
|
|
91
91
|
const docRef = getPath(doc, field);
|
|
92
92
|
const docParsed = docRef ? parseDocRef(docRef) : undefined;
|
|
93
|
-
return
|
|
93
|
+
return docParsed?.id === parsed.id;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
return getPath(doc, field) === value;
|
|
@@ -116,7 +116,7 @@ const docFieldSql = (collection, table, fieldPath) => {
|
|
|
116
116
|
if (fieldPath === '_to' && t.toId)
|
|
117
117
|
return sql `${t.toId}`;
|
|
118
118
|
const scalars = SCALAR_COLUMNS[collection];
|
|
119
|
-
if (scalars
|
|
119
|
+
if (scalars?.includes(fieldPath))
|
|
120
120
|
return sql `${t[fieldPath]}`;
|
|
121
121
|
let jsonPath = fieldPath;
|
|
122
122
|
if (collection === 'posts' && jsonPath.startsWith('data.')) {
|
|
@@ -431,7 +431,7 @@ const matchToSql = (collection, table, match) => {
|
|
|
431
431
|
}
|
|
432
432
|
if (config.kind === 'document') {
|
|
433
433
|
const scalars = SCALAR_COLUMNS[collection];
|
|
434
|
-
if (scalars
|
|
434
|
+
if (scalars?.includes(key)) {
|
|
435
435
|
conditions.push(eq(t[key], value));
|
|
436
436
|
}
|
|
437
437
|
else if (t.body) {
|
|
@@ -491,7 +491,7 @@ export const partitionFilters = (collection, table, filters, defaultFilter, soft
|
|
|
491
491
|
}
|
|
492
492
|
for (const filter of [
|
|
493
493
|
...(defaultFilter ? [defaultFilter] : []),
|
|
494
|
-
...(filters
|
|
494
|
+
...(filters ?? []),
|
|
495
495
|
]) {
|
|
496
496
|
if (isSqlFilter(filter)) {
|
|
497
497
|
sqlConditions.push(filter.where);
|
|
@@ -519,7 +519,7 @@ export const applyDateRangeToEdgeSql = (table, filter) => {
|
|
|
519
519
|
return createdAtRangeSql(table, filter);
|
|
520
520
|
};
|
|
521
521
|
export const sortToSqlOrderBy = (collection, table, sort, activityWindow) => {
|
|
522
|
-
if (!
|
|
522
|
+
if (!sort?.length)
|
|
523
523
|
return undefined;
|
|
524
524
|
const orderBy = [];
|
|
525
525
|
for (const [expr, direction] of sort) {
|
|
@@ -553,7 +553,7 @@ export const sortToSqlOrderBy = (collection, table, sort, activityWindow) => {
|
|
|
553
553
|
export const applyPostFilters = (docs, filters, defaultFilter) => {
|
|
554
554
|
const allFilters = [
|
|
555
555
|
...(defaultFilter ? [defaultFilter] : []),
|
|
556
|
-
...(filters
|
|
556
|
+
...(filters ?? []),
|
|
557
557
|
];
|
|
558
558
|
return docs.filter((doc) => allFilters.every((f) => {
|
|
559
559
|
if (isSqlFilter(f))
|
|
@@ -562,7 +562,7 @@ export const applyPostFilters = (docs, filters, defaultFilter) => {
|
|
|
562
562
|
}));
|
|
563
563
|
};
|
|
564
564
|
export const applySort = (docs, sort) => {
|
|
565
|
-
if (!
|
|
565
|
+
if (!sort?.length)
|
|
566
566
|
return docs;
|
|
567
567
|
return [...docs].sort((a, b) => {
|
|
568
568
|
for (const [expr, direction] of sort) {
|
package/dist/db/pg/map/index.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
2
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
3
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
5
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
6
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
7
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
8
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
9
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
10
|
-
function fulfill(value) { resume("next", value); }
|
|
11
|
-
function reject(value) { resume("throw", value); }
|
|
12
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
13
|
-
};
|
|
14
1
|
import { addFilter } from './helpers.js';
|
|
15
2
|
import { createDocument, deleteDocument, updateDocument } from './mutations.js';
|
|
16
3
|
import { deleteRelationsFor, executeAll, executeCount, executeFind, executeFirst, relationsFrom, } from './relations.js';
|
|
@@ -22,43 +9,50 @@ const throwIfUndefined = (message) => (value) => {
|
|
|
22
9
|
return value;
|
|
23
10
|
};
|
|
24
11
|
export const map = (mapData) => ({
|
|
25
|
-
addRelation: (relation) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
addRelations: (relations) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
removeRelation: (predicate) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
addDerivedProperty: (derivedProperty) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
removeDefaultFilter: () => map(
|
|
12
|
+
addRelation: (relation) => map({
|
|
13
|
+
...mapData,
|
|
14
|
+
relations: [...(mapData.relations ?? []), relation],
|
|
15
|
+
}),
|
|
16
|
+
addRelations: (relations) => map({
|
|
17
|
+
...mapData,
|
|
18
|
+
relations: [...(mapData.relations ?? []), ...relations],
|
|
19
|
+
}),
|
|
20
|
+
removeRelation: (predicate) => map({
|
|
21
|
+
...mapData,
|
|
22
|
+
relations: mapData.relations?.filter(predicate),
|
|
23
|
+
}),
|
|
24
|
+
addDerivedProperty: (derivedProperty) => map({
|
|
25
|
+
...mapData,
|
|
26
|
+
derivedProperties: [
|
|
27
|
+
...(mapData.derivedProperties ?? []),
|
|
28
|
+
derivedProperty,
|
|
29
|
+
],
|
|
30
|
+
}),
|
|
31
|
+
removeDefaultFilter: () => map({
|
|
32
|
+
...mapData,
|
|
33
|
+
defaultFilter: undefined,
|
|
34
|
+
}),
|
|
45
35
|
filter: (filter) => map(addFilter(mapData, filter)),
|
|
46
|
-
clearFilters: () => map(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
clearFilters: () => map({
|
|
37
|
+
...mapData,
|
|
38
|
+
filters: [],
|
|
39
|
+
}),
|
|
40
|
+
sort: (sort) => sort ? map({ ...mapData, sort }) : map(mapData),
|
|
41
|
+
limit: (limit) => (limit ? map({ ...mapData, limit }) : map(mapData)),
|
|
42
|
+
ignoreSoftDelete: () => map({
|
|
43
|
+
...mapData,
|
|
44
|
+
softDelete: false,
|
|
45
|
+
}),
|
|
46
|
+
find: (db, id, options) => executeFind(db, mapData.collection, mapData, id, options?.ignoreSoftDelete),
|
|
51
47
|
findOneBy: (db, filter) => map(addFilter(mapData, filter)).first(db),
|
|
52
48
|
all: (db) => executeAll(db, mapData),
|
|
53
49
|
fulltextSearch: (searchDefinition) => buildSearchResult(mapData, searchDefinition),
|
|
54
50
|
count: (db) => executeCount(db, mapData),
|
|
55
51
|
first: (db) => executeFirst(db, mapData),
|
|
56
|
-
cursor: function (db) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
});
|
|
52
|
+
cursor: async function* (db) {
|
|
53
|
+
for (const row of await executeAll(db, mapData)) {
|
|
54
|
+
yield row;
|
|
55
|
+
}
|
|
62
56
|
},
|
|
63
57
|
queryBuilder: () => {
|
|
64
58
|
throw new Error('queryBuilder() is not supported for Postgres map()');
|
|
@@ -72,16 +66,17 @@ export const map = (mapData) => ({
|
|
|
72
66
|
all: (db) => relationsFrom(db, start, mapData.collection, relation),
|
|
73
67
|
count: (db) => relationsFrom(db, start, mapData.collection, relation).then((rows) => rows.length),
|
|
74
68
|
first: (db) => relationsFrom(db, start, mapData.collection, relation).then((rows) => rows[0]),
|
|
75
|
-
limit: (limit) => map(mapData).relationsFrom(start,
|
|
69
|
+
limit: (limit) => map(mapData).relationsFrom(start, {
|
|
70
|
+
...relation,
|
|
71
|
+
mapping: { ...relation.mapping, limit },
|
|
72
|
+
}),
|
|
76
73
|
query: () => {
|
|
77
74
|
throw new Error('query() is not supported for Postgres relationsFrom');
|
|
78
75
|
},
|
|
79
|
-
cursor: function (db) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
});
|
|
76
|
+
cursor: async function* (db) {
|
|
77
|
+
for (const row of await relationsFrom(db, start, mapData.collection, relation)) {
|
|
78
|
+
yield row;
|
|
79
|
+
}
|
|
85
80
|
},
|
|
86
81
|
};
|
|
87
82
|
return result;
|
|
@@ -23,18 +23,25 @@ const edgeBodyPatch = (patch) => {
|
|
|
23
23
|
return body;
|
|
24
24
|
};
|
|
25
25
|
export const createDocument = async (db, mapData, data) => {
|
|
26
|
-
var _a;
|
|
27
26
|
const collection = mapData.collection;
|
|
28
27
|
const config = documentRegistry[collection];
|
|
29
28
|
if (!config) {
|
|
30
29
|
throw new Error(`Cannot create in collection: ${collection}`);
|
|
31
30
|
}
|
|
32
|
-
const id =
|
|
31
|
+
const id = data.id ?? uuidv7();
|
|
33
32
|
const { scalars, body } = config.splitPatch(data);
|
|
34
33
|
const ts = nowIso();
|
|
35
|
-
await db.insert(config.table).values(
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
await db.insert(config.table).values({
|
|
35
|
+
id,
|
|
36
|
+
...scalars,
|
|
37
|
+
body,
|
|
38
|
+
createdAt: ts,
|
|
39
|
+
updatedAt: ts,
|
|
40
|
+
deletedAt: null,
|
|
41
|
+
...(collection === 'posts' && scalars.lastActivityAt === undefined
|
|
42
|
+
? { lastActivityAt: ts }
|
|
43
|
+
: {}),
|
|
44
|
+
});
|
|
38
45
|
const created = await executeFind(db, collection, mapData, id, true);
|
|
39
46
|
if (!created) {
|
|
40
47
|
throw new Error(`create ${collection}`);
|
|
@@ -42,7 +49,6 @@ export const createDocument = async (db, mapData, data) => {
|
|
|
42
49
|
return created;
|
|
43
50
|
};
|
|
44
51
|
export const updateDocument = async (db, mapData, id, patch) => {
|
|
45
|
-
var _a;
|
|
46
52
|
const collection = mapData.collection;
|
|
47
53
|
const config = getCollectionConfig(collection);
|
|
48
54
|
if (!config) {
|
|
@@ -59,21 +65,30 @@ export const updateDocument = async (db, mapData, id, patch) => {
|
|
|
59
65
|
throw new Error(`update ${collection} ${id}`);
|
|
60
66
|
}
|
|
61
67
|
if (config.kind === 'edge') {
|
|
62
|
-
const currentBody =
|
|
68
|
+
const currentBody = {
|
|
69
|
+
...(row.body ?? {}),
|
|
70
|
+
};
|
|
63
71
|
await db
|
|
64
72
|
.update(table)
|
|
65
73
|
.set({
|
|
66
|
-
body:
|
|
74
|
+
body: { ...currentBody, ...edgeBodyPatch(patch) },
|
|
67
75
|
updatedAt: nowIso(),
|
|
68
76
|
})
|
|
69
77
|
.where(eq(documentIdColumn(collection, table), id));
|
|
70
78
|
}
|
|
71
79
|
else {
|
|
72
|
-
const merged =
|
|
80
|
+
const merged = {
|
|
81
|
+
...rowToPatchInput(collection, row),
|
|
82
|
+
...patch,
|
|
83
|
+
};
|
|
73
84
|
const { scalars, body } = config.splitPatch(merged);
|
|
74
85
|
await db
|
|
75
86
|
.update(table)
|
|
76
|
-
.set(
|
|
87
|
+
.set({
|
|
88
|
+
...scalars,
|
|
89
|
+
body,
|
|
90
|
+
updatedAt: nowIso(),
|
|
91
|
+
})
|
|
77
92
|
.where(eq(documentIdColumn(collection, table), id));
|
|
78
93
|
}
|
|
79
94
|
const updated = await executeFind(db, collection, mapData, id, true);
|
|
@@ -95,23 +110,43 @@ const rowToPatchInput = (collection, row) => {
|
|
|
95
110
|
data: row.body,
|
|
96
111
|
};
|
|
97
112
|
case 'profiles':
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
:
|
|
113
|
+
return {
|
|
114
|
+
handle: row.handle,
|
|
115
|
+
type: row.type,
|
|
116
|
+
uri: row.uri,
|
|
117
|
+
inboxUrl: row.inboxUrl,
|
|
118
|
+
sharedInboxUrl: row.sharedInboxUrl,
|
|
119
|
+
publicKeyPem: row.publicKeyPem,
|
|
120
|
+
privateKeyPem: row.privateKeyPem,
|
|
121
|
+
keyId: row.keyId,
|
|
122
|
+
fetchedAt: row.fetchedAt,
|
|
123
|
+
...(row.activityPubDomain
|
|
124
|
+
? { activityPub: { domain: row.activityPubDomain } }
|
|
125
|
+
: {}),
|
|
126
|
+
...row.body,
|
|
127
|
+
};
|
|
101
128
|
case 'groups':
|
|
102
|
-
return
|
|
129
|
+
return { handle: row.handle, ...row.body };
|
|
103
130
|
case 'roles':
|
|
104
|
-
return
|
|
131
|
+
return {
|
|
132
|
+
key: row.key,
|
|
133
|
+
isDefault: row.isDefault,
|
|
134
|
+
...row.body,
|
|
135
|
+
};
|
|
105
136
|
case 'notifications':
|
|
106
|
-
return
|
|
137
|
+
return { profileId: row.profileId, ...row.body };
|
|
107
138
|
case 'jamEvents':
|
|
108
|
-
return
|
|
139
|
+
return { jamId: row.postId, ...row.body };
|
|
109
140
|
case 'processingStats':
|
|
110
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
filetype: row.filetype,
|
|
143
|
+
filesize: row.filesize,
|
|
144
|
+
...row.body,
|
|
145
|
+
};
|
|
111
146
|
case 'profileSettings':
|
|
112
|
-
return
|
|
147
|
+
return { id: row.profileId, ...row.body };
|
|
113
148
|
case 'inviteLinks':
|
|
114
|
-
return
|
|
149
|
+
return { slug: row.slug, ...row.body };
|
|
115
150
|
case 'accounts':
|
|
116
151
|
return {
|
|
117
152
|
email: row.email,
|
|
@@ -122,7 +157,7 @@ const rowToPatchInput = (collection, row) => {
|
|
|
122
157
|
case 'hashtags':
|
|
123
158
|
return { tag: row.name };
|
|
124
159
|
default:
|
|
125
|
-
return
|
|
160
|
+
return { ...row.body };
|
|
126
161
|
}
|
|
127
162
|
};
|
|
128
163
|
export const deleteDocument = async (db, mapData, id) => {
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import * as documents from '../schema/documents.js';
|
|
13
2
|
import * as edges from '../schema/edges.js';
|
|
14
3
|
import { modelTimestampsFromRow, normalizeIsoDatetime, rowToModel, } from '../mappers.js';
|
|
@@ -20,11 +9,11 @@ export const asTable = (table) => table;
|
|
|
20
9
|
export const documentIdColumn = (collection, table) => (collection === 'profileSettings' ? table.profileId : table.id);
|
|
21
10
|
const bodyOnly = (data) => ({
|
|
22
11
|
scalars: {},
|
|
23
|
-
body:
|
|
12
|
+
body: { ...data },
|
|
24
13
|
});
|
|
25
14
|
const withScalars = (...scalarKeys) => (data) => {
|
|
26
15
|
const scalars = {};
|
|
27
|
-
const body =
|
|
16
|
+
const body = { ...data };
|
|
28
17
|
for (const key of scalarKeys) {
|
|
29
18
|
if (key in body) {
|
|
30
19
|
scalars[key] = body[key];
|
|
@@ -34,7 +23,7 @@ const withScalars = (...scalarKeys) => (data) => {
|
|
|
34
23
|
return { scalars, body };
|
|
35
24
|
};
|
|
36
25
|
const postsSplit = (data) => {
|
|
37
|
-
const { type, visibility, creatorId, lastActivityAt, data: postBody, uri, inReplyToUri
|
|
26
|
+
const { type, visibility, creatorId, lastActivityAt, data: postBody, uri, inReplyToUri, ...rest } = data;
|
|
38
27
|
const scalars = {};
|
|
39
28
|
if (type !== undefined)
|
|
40
29
|
scalars.type = type;
|
|
@@ -48,7 +37,7 @@ const postsSplit = (data) => {
|
|
|
48
37
|
scalars.uri = uri;
|
|
49
38
|
if (inReplyToUri !== undefined)
|
|
50
39
|
scalars.inReplyToUri = inReplyToUri;
|
|
51
|
-
const body = postBody !== undefined ?
|
|
40
|
+
const body = postBody !== undefined ? { ...postBody } : { ...rest };
|
|
52
41
|
if (postBody === undefined) {
|
|
53
42
|
delete body.type;
|
|
54
43
|
delete body.visibility;
|
|
@@ -69,7 +58,7 @@ const ACTOR_SCALAR_KEYS = [
|
|
|
69
58
|
'fetchedAt',
|
|
70
59
|
];
|
|
71
60
|
const profilesSplit = (data) => {
|
|
72
|
-
const { handle, type, activityPub
|
|
61
|
+
const { handle, type, activityPub, ...rest } = data;
|
|
73
62
|
const scalars = {};
|
|
74
63
|
if (handle !== undefined)
|
|
75
64
|
scalars.handle = handle;
|
|
@@ -80,7 +69,7 @@ const profilesSplit = (data) => {
|
|
|
80
69
|
if (domain !== undefined)
|
|
81
70
|
scalars.activityPubDomain = domain;
|
|
82
71
|
}
|
|
83
|
-
const body =
|
|
72
|
+
const body = { ...rest };
|
|
84
73
|
for (const key of ACTOR_SCALAR_KEYS) {
|
|
85
74
|
if (key in body) {
|
|
86
75
|
scalars[key] = body[key];
|
|
@@ -91,7 +80,7 @@ const profilesSplit = (data) => {
|
|
|
91
80
|
};
|
|
92
81
|
/** App model uses `tag`; Postgres column is `name`. */
|
|
93
82
|
const hashtagsSplit = (data) => {
|
|
94
|
-
const normalized =
|
|
83
|
+
const normalized = { ...data };
|
|
95
84
|
if ('tag' in normalized && !('name' in normalized)) {
|
|
96
85
|
normalized.name = normalized.tag;
|
|
97
86
|
delete normalized.tag;
|
|
@@ -103,23 +92,23 @@ const hashtagsSplit = (data) => {
|
|
|
103
92
|
};
|
|
104
93
|
/** Older jam events stored jamId; the column is post_id. */
|
|
105
94
|
const jamEventsSplit = (data) => {
|
|
106
|
-
const { postId, jamId
|
|
95
|
+
const { postId, jamId, ...rest } = data;
|
|
107
96
|
const scalars = {};
|
|
108
|
-
const resolvedPostId = postId
|
|
97
|
+
const resolvedPostId = postId ?? jamId;
|
|
109
98
|
if (resolvedPostId !== undefined) {
|
|
110
99
|
scalars.postId = resolvedPostId;
|
|
111
100
|
}
|
|
112
|
-
return { scalars, body:
|
|
101
|
+
return { scalars, body: { ...rest } };
|
|
113
102
|
};
|
|
114
103
|
/** Legacy settings docs use profile id as document id, not profileId. */
|
|
115
104
|
const profileSettingsSplit = (data) => {
|
|
116
|
-
const { profileId, id
|
|
105
|
+
const { profileId, id, ...rest } = data;
|
|
117
106
|
const scalars = {};
|
|
118
|
-
const resolvedProfileId = profileId
|
|
107
|
+
const resolvedProfileId = profileId ?? id;
|
|
119
108
|
if (resolvedProfileId !== undefined) {
|
|
120
109
|
scalars.profileId = resolvedProfileId;
|
|
121
110
|
}
|
|
122
|
-
return { scalars, body:
|
|
111
|
+
return { scalars, body: { ...rest } };
|
|
123
112
|
};
|
|
124
113
|
export const documentRegistry = {
|
|
125
114
|
accounts: {
|
|
@@ -366,7 +355,7 @@ export const edgeRegistry = {
|
|
|
366
355
|
toCollection: 'hashtags',
|
|
367
356
|
},
|
|
368
357
|
};
|
|
369
|
-
export const getCollectionConfig = (collection) =>
|
|
358
|
+
export const getCollectionConfig = (collection) => documentRegistry[collection] ?? edgeRegistry[collection];
|
|
370
359
|
export const getTableForCollection = (collection) => {
|
|
371
360
|
const config = getCollectionConfig(collection);
|
|
372
361
|
if (!config) {
|
|
@@ -384,7 +373,6 @@ export const parseDocRef = (ref) => {
|
|
|
384
373
|
export const docRef = (collection, id) => `${collection}/${id}`;
|
|
385
374
|
const rowTimestamps = (row) => modelTimestampsFromRow(row);
|
|
386
375
|
export const rowToDocument = (collection, row, keepMetadata = false) => {
|
|
387
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
388
376
|
const config = getCollectionConfig(collection);
|
|
389
377
|
if (!config) {
|
|
390
378
|
throw new Error(`Unknown collection: ${collection}`);
|
|
@@ -395,7 +383,14 @@ export const rowToDocument = (collection, row, keepMetadata = false) => {
|
|
|
395
383
|
const toId = row.toId;
|
|
396
384
|
// Body fields first; row id / edge refs / timestamps always win so a
|
|
397
385
|
// stale body.id (from older inserts) cannot shadow the primary key.
|
|
398
|
-
const base =
|
|
386
|
+
const base = {
|
|
387
|
+
...(row.body ?? {}),
|
|
388
|
+
id: row.id,
|
|
389
|
+
_from: docRef(config.fromCollection, fromId),
|
|
390
|
+
_to: docRef(config.toCollection, toId),
|
|
391
|
+
createdAt: timestamps.createdAt,
|
|
392
|
+
updatedAt: timestamps.updatedAt,
|
|
393
|
+
};
|
|
399
394
|
return keepMetadata ? base : base;
|
|
400
395
|
}
|
|
401
396
|
switch (collection) {
|
|
@@ -404,46 +399,88 @@ export const rowToDocument = (collection, row, keepMetadata = false) => {
|
|
|
404
399
|
email: row.email,
|
|
405
400
|
passwordHash: row.passwordHash,
|
|
406
401
|
emailValidated: row.emailValidated,
|
|
407
|
-
guest:
|
|
402
|
+
guest: row.guest ?? undefined,
|
|
408
403
|
}, timestamps);
|
|
409
404
|
case 'profiles':
|
|
410
|
-
return rowToModel(row.id,
|
|
411
|
-
|
|
412
|
-
:
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
? {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
405
|
+
return rowToModel(row.id, {
|
|
406
|
+
handle: row.handle,
|
|
407
|
+
type: row.type,
|
|
408
|
+
...(row.activityPubDomain
|
|
409
|
+
? { activityPub: { domain: row.activityPubDomain } }
|
|
410
|
+
: {}),
|
|
411
|
+
...(row.body ?? {}),
|
|
412
|
+
...(typeof row.uri === 'string' ? { uri: row.uri } : {}),
|
|
413
|
+
...(typeof row.inboxUrl === 'string'
|
|
414
|
+
? { inboxUrl: row.inboxUrl }
|
|
415
|
+
: {}),
|
|
416
|
+
...(typeof row.sharedInboxUrl === 'string'
|
|
417
|
+
? { sharedInboxUrl: row.sharedInboxUrl }
|
|
418
|
+
: {}),
|
|
419
|
+
...(typeof row.publicKeyPem === 'string'
|
|
420
|
+
? { publicKeyPem: row.publicKeyPem }
|
|
421
|
+
: {}),
|
|
422
|
+
// privateKeyPem stays on the column and is never hydrated here.
|
|
423
|
+
...(typeof row.keyId === 'string' ? { keyId: row.keyId } : {}),
|
|
424
|
+
...(typeof row.fetchedAt === 'string'
|
|
425
|
+
? { fetchedAt: normalizeIsoDatetime(row.fetchedAt) }
|
|
426
|
+
: {}),
|
|
427
|
+
}, timestamps);
|
|
421
428
|
case 'posts': {
|
|
422
429
|
const lastActivityAt = row.lastActivityAt
|
|
423
430
|
? normalizeIsoDatetime(row.lastActivityAt)
|
|
424
431
|
: timestamps.createdAt;
|
|
425
|
-
return
|
|
426
|
-
|
|
427
|
-
|
|
432
|
+
return {
|
|
433
|
+
...rowToModel(row.id, {
|
|
434
|
+
type: row.type,
|
|
435
|
+
visibility: row.visibility,
|
|
436
|
+
creatorId: row.creatorId,
|
|
437
|
+
...(typeof row.uri === 'string' ? { uri: row.uri } : {}),
|
|
438
|
+
...(typeof row.inReplyToUri === 'string'
|
|
439
|
+
? { inReplyToUri: row.inReplyToUri }
|
|
440
|
+
: {}),
|
|
441
|
+
data: row.body ?? {},
|
|
442
|
+
}, timestamps),
|
|
443
|
+
lastActivityAt,
|
|
444
|
+
};
|
|
428
445
|
}
|
|
429
446
|
case 'groups':
|
|
430
|
-
return rowToModel(row.id,
|
|
447
|
+
return rowToModel(row.id, {
|
|
448
|
+
handle: row.handle,
|
|
449
|
+
...(row.body ?? {}),
|
|
450
|
+
}, timestamps);
|
|
431
451
|
case 'hashtags':
|
|
432
452
|
return rowToModel(row.id, { tag: row.name }, timestamps);
|
|
433
453
|
case 'roles':
|
|
434
|
-
return rowToModel(row.id,
|
|
454
|
+
return rowToModel(row.id, {
|
|
455
|
+
key: row.key,
|
|
456
|
+
isDefault: row.isDefault,
|
|
457
|
+
...(row.body ?? {}),
|
|
458
|
+
}, timestamps);
|
|
435
459
|
case 'notifications':
|
|
436
|
-
return rowToModel(row.id,
|
|
460
|
+
return rowToModel(row.id, {
|
|
461
|
+
profileId: row.profileId,
|
|
462
|
+
...(row.body ?? {}),
|
|
463
|
+
}, timestamps);
|
|
437
464
|
case 'jamEvents':
|
|
438
|
-
return rowToModel(row.id,
|
|
465
|
+
return rowToModel(row.id, {
|
|
466
|
+
jamId: row.postId,
|
|
467
|
+
...(row.body ?? {}),
|
|
468
|
+
}, timestamps);
|
|
439
469
|
case 'processingStats':
|
|
440
|
-
return rowToModel(row.id,
|
|
470
|
+
return rowToModel(row.id, {
|
|
471
|
+
filetype: row.filetype,
|
|
472
|
+
filesize: row.filesize,
|
|
473
|
+
...(row.body ?? {}),
|
|
474
|
+
}, timestamps);
|
|
441
475
|
case 'profileSettings':
|
|
442
|
-
return rowToModel(row.profileId, (
|
|
476
|
+
return rowToModel(row.profileId, (row.body ?? {}), timestamps);
|
|
443
477
|
case 'inviteLinks':
|
|
444
|
-
return rowToModel(row.id,
|
|
478
|
+
return rowToModel(row.id, {
|
|
479
|
+
slug: row.slug,
|
|
480
|
+
...(row.body ?? {}),
|
|
481
|
+
}, timestamps);
|
|
445
482
|
default:
|
|
446
|
-
return rowToModel(row.id, (
|
|
483
|
+
return rowToModel(row.id, (row.body ?? {}), timestamps);
|
|
447
484
|
}
|
|
448
485
|
};
|
|
449
486
|
export const searchViewCollections = {
|