@drfed/graphql 0.0.0-stage → 0.1.0-dev.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.
Files changed (45) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +254 -2
  3. package/dist/account.d.mts +6 -0
  4. package/dist/account.d.mts.map +1 -0
  5. package/dist/account.mjs +168 -0
  6. package/dist/account.mjs.map +1 -0
  7. package/dist/activity-delivery/entry.d.mts +6 -0
  8. package/dist/activity-delivery/entry.d.mts.map +1 -0
  9. package/dist/activity-delivery/entry.mjs +291 -0
  10. package/dist/activity-delivery/entry.mjs.map +1 -0
  11. package/dist/actor-BJvviz6Q.mjs +600 -0
  12. package/dist/actor-BJvviz6Q.mjs.map +1 -0
  13. package/dist/actor.d.mts +7 -0
  14. package/dist/actor.d.mts.map +1 -0
  15. package/dist/actor.mjs +2 -0
  16. package/dist/builder-BLioFAdv.mjs +152 -0
  17. package/dist/builder-BLioFAdv.mjs.map +1 -0
  18. package/dist/builder-CSxRffRp.d.mts +134 -0
  19. package/dist/builder-CSxRffRp.d.mts.map +1 -0
  20. package/dist/builder.d.mts +2 -0
  21. package/dist/builder.mjs +2 -0
  22. package/dist/classification.d.mts +62 -0
  23. package/dist/classification.d.mts.map +1 -0
  24. package/dist/classification.mjs +65 -0
  25. package/dist/classification.mjs.map +1 -0
  26. package/dist/index.d.mts +55 -0
  27. package/dist/index.d.mts.map +1 -0
  28. package/dist/index.mjs +86 -0
  29. package/dist/index.mjs.map +1 -0
  30. package/dist/instance.d.mts +32 -0
  31. package/dist/instance.d.mts.map +1 -0
  32. package/dist/instance.mjs +176 -0
  33. package/dist/instance.mjs.map +1 -0
  34. package/dist/object.d.mts +6 -0
  35. package/dist/object.d.mts.map +1 -0
  36. package/dist/object.mjs +321 -0
  37. package/dist/object.mjs.map +1 -0
  38. package/dist/readable-CSN0MPlO.mjs +140 -0
  39. package/dist/readable-CSN0MPlO.mjs.map +1 -0
  40. package/dist/schema-ZeV-COPn.mjs +275 -0
  41. package/dist/schema-ZeV-COPn.mjs.map +1 -0
  42. package/dist/schema.d.mts +11 -0
  43. package/dist/schema.d.mts.map +1 -0
  44. package/dist/schema.mjs +2 -0
  45. package/package.json +142 -3
@@ -0,0 +1,321 @@
1
+ import { n as builder } from "./builder-BLioFAdv.mjs";
2
+ import { a as readableResource } from "./readable-CSN0MPlO.mjs";
3
+ import { a as ResourceDetail, i as ActivityType, o as registerAddressingFields, r as Activity, t as Actor } from "./actor-BJvviz6Q.mjs";
4
+ import { objectTypeEnum } from "@drfed/models/schema";
5
+ import { drizzleConnectionHelpers } from "@pothos/plugin-drizzle";
6
+ import { addActorCollectionItem, ensureResource, lockActorCollection, promoteResource, schema, storeAddressing } from "@drfed/models";
7
+ import { uuidV7, validateUuid } from "@drfed/models/uuid";
8
+ import { and, eq, gt, isNotNull, isNull } from "drizzle-orm";
9
+ import { activitySelection, objectSelection, toCreate, toObject } from "@drfed/federation/object";
10
+ import { Create, Object as Object$1 } from "@fedify/vocab";
11
+ //#region src/object.ts
12
+ const ObjectType = builder.enumType("ObjectType", { values: objectTypeEnum.enumValues });
13
+ const AddressingInput = builder.inputType("AddressingInput", { fields: (t) => ({
14
+ to: t.field({
15
+ type: ["URL"],
16
+ required: true,
17
+ defaultValue: []
18
+ }),
19
+ cc: t.field({
20
+ type: ["URL"],
21
+ required: true,
22
+ defaultValue: []
23
+ }),
24
+ bto: t.field({
25
+ type: ["URL"],
26
+ required: true,
27
+ defaultValue: []
28
+ }),
29
+ bcc: t.field({
30
+ type: ["URL"],
31
+ required: true,
32
+ defaultValue: []
33
+ }),
34
+ audience: t.field({
35
+ type: ["URL"],
36
+ required: true,
37
+ defaultValue: []
38
+ })
39
+ }) });
40
+ const ObjectRef = builder.drizzleNode("objects", {
41
+ name: "Object",
42
+ select: {
43
+ columns: {
44
+ id: true,
45
+ deleted: true
46
+ },
47
+ with: { actor: { columns: { deleted: true } } }
48
+ },
49
+ description: "Represents an ActivityPub object authored by an `Actor`. An object of a local actor is readable whatever its addressing. One of a remote actor is readable only when it or the activity it was received in is addressed to the public, by members of the local instances that received that activity and the object as stored with it, and by administrators; otherwise it is left out as if it did not exist.",
50
+ id: {
51
+ column: ({ id }) => id,
52
+ description: "The Relay global ID of the object."
53
+ },
54
+ fields: (t) => ({
55
+ resource: t.relation("resource"),
56
+ iri: t.field({
57
+ type: "URL",
58
+ select: { with: { resource: true } },
59
+ resolve: (row) => row.resource.iri
60
+ }),
61
+ uuid: t.expose("id", {
62
+ type: "UUID",
63
+ description: "The UUID of the ActivityPub Object."
64
+ }),
65
+ url: t.expose("url", {
66
+ type: "URL",
67
+ nullable: true,
68
+ description: "The human-readable page URL, if available."
69
+ }),
70
+ type: t.expose("type", {
71
+ type: ObjectType,
72
+ description: "The ActivityStreams vocabulary type: Note or Article."
73
+ }),
74
+ actor: t.relation("actor", { description: "The actor that authored the object." }),
75
+ document: t.expose("document", {
76
+ type: "JSON",
77
+ nullable: true,
78
+ description: "The JSON-LD document of the object. For a remote object embedded in the Create that delivered it, the object as received; null when it was not found within the first 64 places of that document, in which case the document of the Create, reachable through activities, holds it as received."
79
+ }),
80
+ name: t.exposeString("name", {
81
+ nullable: true,
82
+ description: "The optional title of the object."
83
+ }),
84
+ summary: t.exposeString("summary", {
85
+ nullable: true,
86
+ description: "The optional summary or content warning."
87
+ }),
88
+ contentHtml: t.exposeString("contentHtml", { description: "HTML preserved verbatim. Clients must sanitize it before browser rendering." }),
89
+ language: t.exposeString("language", {
90
+ nullable: true,
91
+ description: "The canonical BCP 47 tag used for contentMap, if specified."
92
+ }),
93
+ sensitive: t.exposeBoolean("sensitive", { description: "Whether the content is marked sensitive." }),
94
+ published: t.expose("published", {
95
+ type: "DateTime",
96
+ description: "The ActivityStreams publication time."
97
+ }),
98
+ updated: t.expose("updated", {
99
+ type: "DateTime",
100
+ description: "The time the stored object was last updated."
101
+ }),
102
+ created: t.expose("created", {
103
+ type: "DateTime",
104
+ description: "The time the object was stored in DrFed, distinct from its publication time."
105
+ })
106
+ })
107
+ });
108
+ const ActivityPubObject = ObjectRef;
109
+ ResourceDetail.addTypes([ActivityPubObject]);
110
+ registerAddressingFields("objects");
111
+ const activitiesConnection = drizzleConnectionHelpers(builder, "activities", { query: (args, ctx) => ({
112
+ where: {
113
+ actor: { deleted: { isNull: true } },
114
+ ...args.type == null ? {} : { type: args.type },
115
+ RAW: (table) => readableResource(ctx, table.id)
116
+ },
117
+ orderBy: {
118
+ published: "asc",
119
+ id: "asc"
120
+ }
121
+ }) });
122
+ builder.drizzleObjectField("objects", "activities", (t) => t.connection({
123
+ type: Activity,
124
+ args: { type: t.arg({ type: ActivityType }) },
125
+ description: "Activities referencing this object that the viewer may read, optionally filtered by type. Excludes deleted authors; ordered by published ASC, id ASC.",
126
+ select(args, ctx, nestedSelection) {
127
+ return { with: { activities: activitiesConnection.getQuery(args, ctx, nestedSelection) } };
128
+ },
129
+ resolve: (object, args, ctx) => activitiesConnection.resolve(object.activities, args, ctx, object)
130
+ }));
131
+ const objectsConnection = drizzleConnectionHelpers(builder, "objects", { query: (_, ctx) => ({
132
+ where: { RAW: (table) => readableResource(ctx, table.id) },
133
+ orderBy: {
134
+ published: "desc",
135
+ id: "desc"
136
+ }
137
+ }) });
138
+ builder.drizzleObjectField("actors", "objects", (t) => t.connection({
139
+ type: ActivityPubObject,
140
+ description: "Non-deleted objects the viewer may read, newest publication first. A local actor's objects are readable whatever their addressing; see `Object` for a remote actor's.",
141
+ select(args, ctx, nestedSelection) {
142
+ return { with: { objects: objectsConnection.getQuery(args, ctx, nestedSelection) } };
143
+ },
144
+ resolve(actor, args, ctx) {
145
+ return {
146
+ ...objectsConnection.resolve(actor.objects, args, ctx, actor),
147
+ totalCount() {
148
+ return ctx.db.$count(schema.objects, and(eq(schema.objects.actorId, actor.id), isNull(schema.objects.deleted), readableResource(ctx, schema.objects.id)));
149
+ }
150
+ };
151
+ }
152
+ }, {
153
+ name: "ObjectConnection",
154
+ fields: (fb) => ({ totalCount: fb.int({
155
+ description: "The number of non-deleted objects authored by this actor that the viewer may read.",
156
+ resolve: (connection) => connection.totalCount()
157
+ }) })
158
+ }, { name: "ObjectEdge" }));
159
+ const CreateObjectErrorType = builder.enumType("CreateObjectErrorType", { values: [
160
+ "ActorNotFound",
161
+ "InvalidContent",
162
+ "InvalidInstanceHost",
163
+ "InvalidLanguage"
164
+ ] });
165
+ const CreateObjectErrorRef = builder.objectRef("CreateObjectError");
166
+ CreateObjectErrorRef.implement({ fields: (t) => ({
167
+ type: t.expose("type", {
168
+ type: CreateObjectErrorType,
169
+ description: "The type of the error. Use this for programmatic error handling."
170
+ }),
171
+ message: t.exposeString("message", { description: "A human-readable message describing the error. Don't use this for programmatic error handling, use the `type` field instead." })
172
+ }) });
173
+ const CreateObjectResult = builder.unionType("CreateObjectResult", {
174
+ types: [ObjectRef, CreateObjectErrorRef],
175
+ resolveType: (value) => "message" in value ? CreateObjectErrorRef : ObjectRef
176
+ });
177
+ const actorNotFound = {
178
+ type: "ActorNotFound",
179
+ message: "Can't find the actor."
180
+ };
181
+ builder.mutationFields((t) => ({ createObject: t.field({
182
+ type: CreateObjectResult,
183
+ description: "Create a local ActivityPub object without delivering it to remote servers.",
184
+ authScopes: { authenticated: true },
185
+ args: {
186
+ actor: t.arg.globalID({
187
+ for: Actor,
188
+ required: true,
189
+ description: "The local author actor ID. The viewer must be an accepted instance member."
190
+ }),
191
+ type: t.arg({
192
+ type: ObjectType,
193
+ required: true,
194
+ defaultValue: "Note",
195
+ description: "The ActivityStreams object type to create."
196
+ }),
197
+ contentHtml: t.arg.string({
198
+ required: true,
199
+ description: "Non-empty HTML stored verbatim; browser clients must sanitize it before rendering."
200
+ }),
201
+ name: t.arg.string({ description: "Optional title. Empty or whitespace-only values are stored as null." }),
202
+ summary: t.arg.string({ description: "Optional summary or content warning. Empty or whitespace-only values are stored as null." }),
203
+ language: t.arg.string({ description: "A BCP 47 language tag, canonicalized and limited to 35 characters." }),
204
+ sensitive: t.arg.boolean({
205
+ required: true,
206
+ defaultValue: false,
207
+ description: "Whether to mark the content as sensitive."
208
+ }),
209
+ addressing: t.arg({
210
+ type: AddressingInput,
211
+ required: true,
212
+ description: "Explicit addressing preserved in order, including duplicates. Empty lists are allowed."
213
+ })
214
+ },
215
+ async resolve(_parent, { actor: { id: actorId }, language, addressing, ...input }, ctx) {
216
+ if (input.contentHtml.trim() === "") return {
217
+ type: "InvalidContent",
218
+ message: "Content must not be empty."
219
+ };
220
+ let canonicalLanguage = null;
221
+ if (language != null) try {
222
+ canonicalLanguage = Intl.getCanonicalLocales(language)[0] ?? null;
223
+ if (canonicalLanguage == null || canonicalLanguage.length > 35) throw new RangeError("Language tag is too long.");
224
+ } catch (error) {
225
+ if (!(error instanceof RangeError)) throw error;
226
+ return {
227
+ type: "InvalidLanguage",
228
+ message: "Language must be a valid BCP 47 tag of at most 35 characters."
229
+ };
230
+ }
231
+ const { account } = ctx;
232
+ if (account == null) throw new Error("You must be authenticated to create objects.");
233
+ if (!validateUuid(actorId)) return actorNotFound;
234
+ return await ctx.db.transaction(async (tx) => {
235
+ const [actor] = await tx.select({
236
+ id: schema.actors.id,
237
+ host: schema.instances.host
238
+ }).from(schema.actors).for("update", { of: schema.actors }).innerJoin(schema.instances, eq(schema.actors.instanceId, schema.instances.id)).innerJoin(schema.localInstances, eq(schema.instances.localId, schema.localInstances.id)).innerJoin(schema.instanceMembers, eq(schema.instanceMembers.instanceId, schema.instances.id)).where(and(eq(schema.actors.id, actorId), isNotNull(schema.actors.localId), isNull(schema.actors.deleted), gt(schema.localInstances.expires, Temporal.Now.instant()), eq(schema.instanceMembers.accountId, account.id), isNotNull(schema.instanceMembers.accepted))).limit(1);
239
+ if (actor == null) return actorNotFound;
240
+ const instanceUrl = `${ctx.rootOrigin.protocol}//${actor.host}`;
241
+ if (!URL.canParse(instanceUrl)) return {
242
+ type: "InvalidInstanceHost",
243
+ message: `The instance host ${JSON.stringify(actor.host)} cannot be parsed by this server. Contact the server administrator.`
244
+ };
245
+ await lockActorCollection(tx, actorId, "outbox");
246
+ const published = Temporal.Now.instant();
247
+ const id = uuidV7();
248
+ const fedCtx = ctx.federation.createContext(new URL(instanceUrl), void 0);
249
+ const iri = fedCtx.getObjectUri(Object$1, {
250
+ identifier: actorId,
251
+ id
252
+ }).href;
253
+ const activityId = uuidV7();
254
+ const activityIri = fedCtx.getObjectUri(Create, { id: activityId }).href;
255
+ await ensureResource(tx, activityIri, activityId);
256
+ const object = await promoteResource(tx, iri, "object", async (inner, resource) => {
257
+ const [row] = await inner.insert(schema.objects).values({
258
+ ...input,
259
+ name: normalizeOptionalText(input.name),
260
+ summary: normalizeOptionalText(input.summary),
261
+ id: resource.id,
262
+ actorId,
263
+ activityId,
264
+ language: canonicalLanguage,
265
+ published
266
+ }).returning();
267
+ if (row == null) throw new Error("Object insertion returned no row.");
268
+ return row;
269
+ }, id);
270
+ await storeAddressing(tx, object.id, addressing);
271
+ await promoteResource(tx, activityIri, "activity", async (inner, resource) => {
272
+ await inner.insert(schema.activities).values({
273
+ id: resource.id,
274
+ type: "Create",
275
+ actorId,
276
+ objectId: object.id,
277
+ published: object.published
278
+ });
279
+ await storeAddressing(inner, resource.id, addressing);
280
+ await addActorCollectionItem(inner, actorId, "outbox", resource.id);
281
+ }, activityId);
282
+ const storedObject = await tx.query.objects.findFirst({
283
+ where: { id: object.id },
284
+ with: objectSelection
285
+ });
286
+ const storedActivity = await tx.query.activities.findFirst({
287
+ where: { id: activityId },
288
+ with: activitySelection
289
+ });
290
+ if (storedObject == null || storedActivity == null) throw new Error("Missing newly created resource.");
291
+ const snapshot = {
292
+ ...asDocument(await toObject(fedCtx, storedObject).toJsonLd()),
293
+ ...addressing
294
+ };
295
+ await tx.update(schema.objects).set({
296
+ document: snapshot,
297
+ updated: object.updated
298
+ }).where(eq(schema.objects.id, object.id));
299
+ await tx.update(schema.activities).set({ document: {
300
+ ...asDocument(await toCreate(fedCtx, storedActivity).toJsonLd()),
301
+ ...addressing
302
+ } }).where(eq(schema.activities.id, activityId));
303
+ return {
304
+ ...object,
305
+ actor: storedObject.actor,
306
+ document: snapshot
307
+ };
308
+ });
309
+ }
310
+ }) }));
311
+ function normalizeOptionalText(value) {
312
+ return value == null || value.trim() === "" ? null : value;
313
+ }
314
+ function asDocument(value) {
315
+ if (value == null || typeof value !== "object" || Array.isArray(value)) throw new TypeError("Expected a JSON-LD object.");
316
+ return value;
317
+ }
318
+ //#endregion
319
+ export { ActivityPubObject };
320
+
321
+ //# sourceMappingURL=object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.mjs","names":["uuid","APObject"],"sources":["../src/object.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport {\n activitySelection,\n objectSelection,\n toCreate,\n toObject,\n} from \"@drfed/federation/object\";\nimport {\n addActorCollectionItem,\n ensureResource,\n lockActorCollection,\n promoteResource,\n schema,\n storeAddressing,\n} from \"@drfed/models\";\nimport { objectTypeEnum } from \"@drfed/models/schema\";\nimport { uuidV7 as uuid, validateUuid } from \"@drfed/models/uuid\";\nimport { Object as APObject, Create } from \"@fedify/vocab\";\nimport { drizzleConnectionHelpers } from \"@pothos/plugin-drizzle\";\nimport { and, eq, gt, isNotNull, isNull } from \"drizzle-orm\";\n\nimport { Actor } from \"./actor.ts\";\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\nimport { readableResource } from \"./readable.ts\";\nimport {\n Activity,\n ActivityType,\n ResourceDetail,\n registerAddressingFields,\n} from \"./resource.ts\";\n\nconst ObjectType = builder.enumType(\"ObjectType\", {\n values: objectTypeEnum.enumValues,\n});\nconst AddressingInput = builder.inputType(\"AddressingInput\", {\n fields: (t) => ({\n to: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n cc: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n bto: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n bcc: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n audience: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n }),\n});\nconst ObjectRef = builder.drizzleNode(\"objects\", {\n name: \"Object\",\n select: {\n columns: { id: true, deleted: true },\n with: { actor: { columns: { deleted: true } } },\n },\n description:\n \"Represents an ActivityPub object authored by an `Actor`. An object of \" +\n \"a local actor is readable whatever its addressing. One of a remote \" +\n \"actor is readable only when it or the activity it was received in is \" +\n \"addressed to the public, by members of the local instances that \" +\n \"received that activity and the object as stored with it, and by \" +\n \"administrators; otherwise it is left out as if it did not exist.\",\n id: {\n column: ({ id }) => id,\n description: \"The Relay global ID of the object.\",\n },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n uuid: t.expose(\"id\", {\n type: \"UUID\",\n description: \"The UUID of the ActivityPub Object.\",\n }),\n url: t.expose(\"url\", {\n type: \"URL\",\n nullable: true,\n description: \"The human-readable page URL, if available.\",\n }),\n type: t.expose(\"type\", {\n type: ObjectType,\n description: \"The ActivityStreams vocabulary type: Note or Article.\",\n }),\n actor: t.relation(\"actor\", {\n description: \"The actor that authored the object.\",\n }),\n document: t.expose(\"document\", {\n type: \"JSON\",\n nullable: true,\n description:\n \"The JSON-LD document of the object. For a remote object embedded in the Create that delivered it, the object as received; null when it was not found within the first 64 places of that document, in which case the document of the Create, reachable through activities, holds it as received.\",\n }),\n name: t.exposeString(\"name\", {\n nullable: true,\n description: \"The optional title of the object.\",\n }),\n summary: t.exposeString(\"summary\", {\n nullable: true,\n description: \"The optional summary or content warning.\",\n }),\n contentHtml: t.exposeString(\"contentHtml\", {\n description:\n \"HTML preserved verbatim. Clients must sanitize it before browser rendering.\",\n }),\n language: t.exposeString(\"language\", {\n nullable: true,\n description:\n \"The canonical BCP 47 tag used for contentMap, if specified.\",\n }),\n sensitive: t.exposeBoolean(\"sensitive\", {\n description: \"Whether the content is marked sensitive.\",\n }),\n published: t.expose(\"published\", {\n type: \"DateTime\",\n description: \"The ActivityStreams publication time.\",\n }),\n updated: t.expose(\"updated\", {\n type: \"DateTime\",\n description: \"The time the stored object was last updated.\",\n }),\n created: t.expose(\"created\", {\n type: \"DateTime\",\n description:\n \"The time the object was stored in DrFed, distinct from its publication time.\",\n }),\n }),\n});\nexport const ActivityPubObject: DrFedObjectRef = ObjectRef;\nResourceDetail.addTypes([ActivityPubObject]);\nregisterAddressingFields(\"objects\");\n\nconst activitiesConnection = drizzleConnectionHelpers(builder, \"activities\", {\n query: (\n args: {\n type?: typeof schema.activities.$inferSelect.type | null;\n },\n ctx,\n ) => ({\n where: {\n actor: { deleted: { isNull: true } },\n ...(args.type == null ? {} : { type: args.type }),\n RAW: (table) => readableResource(ctx, table.id),\n },\n orderBy: { published: \"asc\", id: \"asc\" },\n }),\n});\nbuilder.drizzleObjectField(\"objects\", \"activities\", (t) =>\n t.connection({\n type: Activity,\n args: { type: t.arg({ type: ActivityType }) },\n description:\n \"Activities referencing this object that the viewer may read, optionally filtered by type. Excludes deleted authors; ordered by published ASC, id ASC.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n activities: activitiesConnection.getQuery(args, ctx, nestedSelection),\n },\n };\n },\n resolve: (object, args, ctx) =>\n activitiesConnection.resolve(object.activities, args, ctx, object),\n }),\n);\n\nconst objectsConnection = drizzleConnectionHelpers(builder, \"objects\", {\n query: (_, ctx) => ({\n where: { RAW: (table) => readableResource(ctx, table.id) },\n orderBy: { published: \"desc\", id: \"desc\" },\n }),\n});\nbuilder.drizzleObjectField(\"actors\", \"objects\", (t) =>\n t.connection(\n {\n type: ActivityPubObject,\n description:\n \"Non-deleted objects the viewer may read, newest publication first. A local actor's objects are readable whatever their addressing; see `Object` for a remote actor's.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n objects: objectsConnection.getQuery(args, ctx, nestedSelection),\n },\n };\n },\n resolve(actor, args, ctx) {\n return {\n ...objectsConnection.resolve(actor.objects, args, ctx, actor),\n totalCount() {\n return ctx.db.$count(\n schema.objects,\n and(\n eq(schema.objects.actorId, actor.id),\n isNull(schema.objects.deleted),\n readableResource(ctx, schema.objects.id),\n ),\n );\n },\n };\n },\n },\n {\n name: \"ObjectConnection\",\n fields: (fb) => ({\n totalCount: fb.int({\n description:\n \"The number of non-deleted objects authored by this actor that the viewer may read.\",\n resolve: (connection) => connection.totalCount(),\n }),\n }),\n },\n { name: \"ObjectEdge\" },\n ),\n);\n\nconst CreateObjectErrorType = builder.enumType(\"CreateObjectErrorType\", {\n values: [\n \"ActorNotFound\",\n \"InvalidContent\",\n \"InvalidInstanceHost\",\n \"InvalidLanguage\",\n ] as const,\n});\ninterface CreateObjectError {\n readonly type: typeof CreateObjectErrorType.$inferType;\n readonly message: string;\n}\nconst CreateObjectErrorRef =\n builder.objectRef<CreateObjectError>(\"CreateObjectError\");\nCreateObjectErrorRef.implement({\n fields: (t) => ({\n type: t.expose(\"type\", {\n type: CreateObjectErrorType,\n description:\n \"The type of the error. Use this for programmatic error handling.\",\n }),\n message: t.exposeString(\"message\", {\n description:\n \"A human-readable message describing the error. \" +\n \"Don't use this for programmatic error handling, \" +\n \"use the `type` field instead.\",\n }),\n }),\n});\nconst CreateObjectResult = builder.unionType(\"CreateObjectResult\", {\n types: [ObjectRef, CreateObjectErrorRef],\n resolveType: (value) =>\n \"message\" in value ? CreateObjectErrorRef : ObjectRef,\n});\nconst actorNotFound: CreateObjectError = {\n type: \"ActorNotFound\",\n message: \"Can't find the actor.\",\n};\n\nbuilder.mutationFields((t) => ({\n createObject: t.field({\n type: CreateObjectResult,\n description:\n \"Create a local ActivityPub object without delivering it to remote servers.\",\n authScopes: { authenticated: true },\n args: {\n actor: t.arg.globalID({\n for: Actor,\n required: true,\n description:\n \"The local author actor ID. The viewer must be an accepted instance member.\",\n }),\n type: t.arg({\n type: ObjectType,\n required: true,\n defaultValue: \"Note\",\n description: \"The ActivityStreams object type to create.\",\n }),\n contentHtml: t.arg.string({\n required: true,\n description:\n \"Non-empty HTML stored verbatim; browser clients must sanitize it before rendering.\",\n }),\n name: t.arg.string({\n description:\n \"Optional title. Empty or whitespace-only values are stored as null.\",\n }),\n summary: t.arg.string({\n description:\n \"Optional summary or content warning. Empty or whitespace-only values are stored as null.\",\n }),\n language: t.arg.string({\n description:\n \"A BCP 47 language tag, canonicalized and limited to 35 characters.\",\n }),\n sensitive: t.arg.boolean({\n required: true,\n defaultValue: false,\n description: \"Whether to mark the content as sensitive.\",\n }),\n addressing: t.arg({\n type: AddressingInput,\n required: true,\n description:\n \"Explicit addressing preserved in order, including duplicates. Empty lists are allowed.\",\n }),\n },\n async resolve(\n _parent,\n { actor: { id: actorId }, language, addressing, ...input },\n ctx,\n ) {\n if (input.contentHtml.trim() === \"\") {\n return {\n type: \"InvalidContent\" as const,\n message: \"Content must not be empty.\",\n };\n }\n let canonicalLanguage: string | null = null;\n if (language != null) {\n try {\n canonicalLanguage = Intl.getCanonicalLocales(language)[0] ?? null;\n if (canonicalLanguage == null || canonicalLanguage.length > 35) {\n throw new RangeError(\"Language tag is too long.\");\n }\n } catch (error) {\n if (!(error instanceof RangeError)) throw error;\n return {\n type: \"InvalidLanguage\" as const,\n message:\n \"Language must be a valid BCP 47 tag of at most 35 characters.\",\n };\n }\n }\n const { account } = ctx;\n if (account == null) {\n throw new Error(\"You must be authenticated to create objects.\");\n }\n if (!validateUuid(actorId)) return actorNotFound;\n // Keep host validation and resource creation under the same actor lock.\n return await ctx.db.transaction(async (tx) => {\n const [actor] = await tx\n .select({ id: schema.actors.id, host: schema.instances.host })\n .from(schema.actors)\n .for(\"update\", { of: schema.actors })\n .innerJoin(\n schema.instances,\n eq(schema.actors.instanceId, schema.instances.id),\n )\n .innerJoin(\n schema.localInstances,\n eq(schema.instances.localId, schema.localInstances.id),\n )\n .innerJoin(\n schema.instanceMembers,\n eq(schema.instanceMembers.instanceId, schema.instances.id),\n )\n .where(\n and(\n eq(schema.actors.id, actorId),\n isNotNull(schema.actors.localId),\n isNull(schema.actors.deleted),\n gt(schema.localInstances.expires, Temporal.Now.instant()),\n eq(schema.instanceMembers.accountId, account.id),\n isNotNull(schema.instanceMembers.accepted),\n ),\n )\n .limit(1);\n if (actor == null) return actorNotFound;\n const instanceUrl = `${ctx.rootOrigin.protocol}//${actor.host}`;\n // Stored authorities can outlive the runtime that accepted them.\n if (!URL.canParse(instanceUrl)) {\n return {\n type: \"InvalidInstanceHost\" as const,\n message:\n `The instance host ${JSON.stringify(actor.host)} cannot be ` +\n \"parsed by this server. Contact the server administrator.\",\n };\n }\n await lockActorCollection(tx, actorId, \"outbox\");\n const published = Temporal.Now.instant();\n const id = uuid();\n const fedCtx = ctx.federation.createContext(\n new URL(instanceUrl),\n undefined,\n );\n const iri = fedCtx.getObjectUri(APObject, {\n identifier: actorId,\n id,\n }).href;\n const activityId = uuid();\n const activityIri = fedCtx.getObjectUri(Create, {\n id: activityId,\n }).href;\n await ensureResource(tx, activityIri, activityId);\n const object = await promoteResource(\n tx,\n iri,\n \"object\",\n async (inner, resource) => {\n const [row] = await inner\n .insert(schema.objects)\n .values({\n ...input,\n name: normalizeOptionalText(input.name),\n summary: normalizeOptionalText(input.summary),\n id: resource.id,\n actorId,\n activityId,\n language: canonicalLanguage,\n published,\n })\n .returning();\n if (row == null) {\n throw new Error(\"Object insertion returned no row.\");\n }\n return row;\n },\n id,\n );\n await storeAddressing(tx, object.id, addressing);\n await promoteResource(\n tx,\n activityIri,\n \"activity\",\n async (inner, resource) => {\n await inner.insert(schema.activities).values({\n id: resource.id,\n type: \"Create\",\n actorId,\n objectId: object.id,\n published: object.published,\n });\n await storeAddressing(inner, resource.id, addressing);\n await addActorCollectionItem(inner, actorId, \"outbox\", resource.id);\n },\n activityId,\n );\n const storedObject = await tx.query.objects.findFirst({\n where: { id: object.id },\n with: objectSelection,\n });\n const storedActivity = await tx.query.activities.findFirst({\n where: { id: activityId },\n with: activitySelection,\n });\n if (storedObject == null || storedActivity == null) {\n throw new Error(\"Missing newly created resource.\");\n }\n // Preserve blind recipients in the local snapshot; serving strips them.\n const snapshot = {\n ...asDocument(await toObject(fedCtx, storedObject).toJsonLd()),\n ...addressing,\n };\n await tx\n .update(schema.objects)\n .set({ document: snapshot, updated: object.updated })\n .where(eq(schema.objects.id, object.id));\n await tx\n .update(schema.activities)\n .set({\n document: {\n ...asDocument(await toCreate(fedCtx, storedActivity).toJsonLd()),\n ...addressing,\n },\n })\n .where(eq(schema.activities.id, activityId));\n return { ...object, actor: storedObject.actor, document: snapshot };\n });\n },\n }),\n}));\n\nfunction normalizeOptionalText(\n value: string | null | undefined,\n): string | null {\n return value == null || value.trim() === \"\" ? null : value;\n}\n\nfunction asDocument(value: unknown): Record<string, unknown> {\n if (value == null || typeof value !== \"object\" || Array.isArray(value)) {\n throw new TypeError(\"Expected a JSON-LD object.\");\n }\n return value as Record<string, unknown>;\n}\n"],"mappings":";;;;;;;;;;;AA8CA,MAAM,aAAa,QAAQ,SAAS,cAAc,EAChD,QAAQ,eAAe,WACzB,CAAC;AACD,MAAM,kBAAkB,QAAQ,UAAU,mBAAmB,EAC3D,SAAS,OAAO;CACd,IAAI,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAC/D,IAAI,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAC/D,KAAK,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,C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CAAC,CACD,MAAM,GAAG,OAAO,WAAW,IAAI,UAAU,CAAC;GAC7C,OAAO;IAAE,GAAG;IAAQ,OAAO,aAAa;IAAO,UAAU;GAAS;EACpE,CAAC;CACH;AACF,CAAC,EACH,EAAE;AAEF,SAAS,sBACP,OACe;CACf,OAAO,SAAS,QAAQ,MAAM,KAAK,MAAM,KAAK,OAAO;AACvD;AAEA,SAAS,WAAW,OAAyC;CAC3D,IAAI,SAAS,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACnE,MAAM,IAAI,UAAU,4BAA4B;CAElD,OAAO;AACT"}
@@ -0,0 +1,140 @@
1
+ import { activities, activityDeliveries, actors, addressing, instanceMembers, instances, objects, resources } from "@drfed/models/schema";
2
+ import { alias } from "drizzle-orm/pg-core";
3
+ import { PUBLIC_IRI } from "@drfed/models/resource";
4
+ import { validateUuid } from "@drfed/models/uuid";
5
+ import { and, eq, inArray, isNotNull, not, sql } from "drizzle-orm";
6
+ //#region src/readable.ts
7
+ /**
8
+ * The IRIs that address an activity or object to the public: the full one and
9
+ * the compacted forms a JSON-LD document may carry.
10
+ */
11
+ const PUBLIC_IRIS = [
12
+ PUBLIC_IRI,
13
+ "as:Public",
14
+ "Public"
15
+ ];
16
+ /**
17
+ * The local instances an account is an accepted member of; pending members,
18
+ * who have been invited but have not accepted yet, do not count.
19
+ * @returns A query of their IDs.
20
+ */
21
+ const memberInstances = (db, accountId, ...conditions) => db.select({ instanceId: instanceMembers.instanceId }).from(instanceMembers).innerJoin(instances, eq(instanceMembers.instanceId, instances.id)).where(and(eq(instanceMembers.accountId, accountId), isNotNull(instanceMembers.accepted), isNotNull(instances.localId), ...conditions));
22
+ /**
23
+ * Restricts rows to those of the local instances whose private records the
24
+ * viewer may read: every local instance for an administrator, and those the
25
+ * viewer is an accepted member of otherwise, as the `admin` and
26
+ * `localInstanceMember` scopes decide for one instance. Filtering rows by it
27
+ * before paging keeps a connection from telling of rows the viewer may not
28
+ * read.
29
+ * @param viewer The viewer and the database.
30
+ * @param instanceId The column of the instance a row belongs to.
31
+ * @returns The condition on the column.
32
+ */
33
+ function viewableInstance(viewer, instanceId) {
34
+ const { account } = viewer;
35
+ if (account == null) return sql`false`;
36
+ return account.admin ? inArray(instanceId, viewer.db.select({ id: instances.id }).from(instances).where(isNotNull(instances.localId))) : inArray(instanceId, memberInstances(viewer.db, account.id));
37
+ }
38
+ const authors = alias(actors, "readable_authors");
39
+ const remoteActivities = alias(activities, "readable_remote_activities");
40
+ const remoteObjects = alias(objects, "readable_remote_objects");
41
+ const carriers = alias(activities, "readable_carriers");
42
+ const entries = alias(addressing, "readable_addressing");
43
+ const targets = alias(resources, "readable_targets");
44
+ const deliveries = alias(activityDeliveries, "readable_deliveries");
45
+ const remoteActivity = (id) => sql`exists (
46
+ select 1 from ${activities} ${remoteActivities}
47
+ join ${actors} ${authors} on ${authors.id} = ${remoteActivities.actorId}
48
+ where ${remoteActivities.id} = ${id} and ${authors.localId} is null
49
+ )`;
50
+ const remoteObject = (id) => sql`exists (
51
+ select 1 from ${objects} ${remoteObjects}
52
+ join ${actors} ${authors} on ${authors.id} = ${remoteObjects.actorId}
53
+ where ${remoteObjects.id} = ${id} and ${authors.localId} is null
54
+ )`;
55
+ const addressedPublicly = (id) => sql`exists (
56
+ select 1 from ${addressing} ${entries}
57
+ join ${resources} ${targets} on ${targets.id} = ${entries.targetId}
58
+ where ${entries.sourceId} = ${id} and ${inArray(targets.iri, PUBLIC_IRIS)}
59
+ )`;
60
+ const received = (viewer, id, mark) => sql`exists (
61
+ select 1 from ${activityDeliveries} ${deliveries}
62
+ where ${deliveries.activityId} = ${id}
63
+ and ${deliveries.direction} = 'inbound'
64
+ and ${mark}
65
+ and ${viewableInstance(viewer, deliveries.instanceId)}
66
+ )`;
67
+ const readableActivity = (viewer, id) => sql`(not ${remoteActivity(id)} or ${addressedPublicly(id)} or ${received(viewer, id, deliveries.carriedSnapshot)})`;
68
+ const readableObject = (viewer, id) => sql`(not ${remoteObject(id)} or ${addressedPublicly(id)} or exists (
69
+ select 1 from ${objects} ${remoteObjects}
70
+ join ${activities} ${carriers} on ${carriers.id} = ${remoteObjects.activityId}
71
+ where ${remoteObjects.id} = ${id}
72
+ and (
73
+ (not ${remoteObjects.fetched} and ${addressedPublicly(carriers.id)})
74
+ or ${received(viewer, carriers.id, deliveries.carriedObjectSnapshot)}
75
+ )
76
+ ))`;
77
+ /**
78
+ * Restricts resources to those the viewer may read. Received content is an
79
+ * inbox's, which ActivityPub filters by the requester's permission (5.2) and
80
+ * opens without authentication only when addressed to the public (5.6):
81
+ *
82
+ * - An administrator reads everything.
83
+ * - An activity of a remote actor is readable when it is addressed to the
84
+ * public, or when one of the local instances the viewer is a member of
85
+ * received it, i.e. an inbound delivery to it is linked to the activity
86
+ * and carried it as stored. A delivery of the same IRI with other
87
+ * contents stays linked but opens nothing.
88
+ * - An object of a remote actor is readable when it is addressed to the
89
+ * public, when the activity that carried it embedded in it is, or when
90
+ * one of the local instances the viewer is a member of received that
91
+ * activity and the object as stored with it. An object fetched apart
92
+ * from the activity is opened neither by the activity being public nor
93
+ * by a delivery but one that fetched it as stored.
94
+ * - Everything else, including the activities and objects of local actors
95
+ * whatever their addressing, is readable.
96
+ *
97
+ * Filtering rows by it before paging keeps a connection from telling of rows
98
+ * the viewer may not read.
99
+ * @param viewer The viewer and the database.
100
+ * @param id The resource ID in an outer query.
101
+ * @returns The condition on the ID.
102
+ */
103
+ function readableResource(viewer, id) {
104
+ if (viewer.account?.admin === true) return sql`true`;
105
+ return sql`(${readableActivity(viewer, id)} and ${readableObject(viewer, id)})`;
106
+ }
107
+ /**
108
+ * Finds the resources among the given IDs that the viewer may not read, as
109
+ * {@link readableResource} decides. IDs of anything but a resource are never
110
+ * among them.
111
+ * @returns The IDs the viewer may not read.
112
+ */
113
+ async function unreadableResources(viewer, ids) {
114
+ if (ids.length === 0 || viewer.account?.admin === true) return /* @__PURE__ */ new Set();
115
+ const rows = await viewer.db.select({ id: resources.id }).from(resources).where(and(inArray(resources.id, [...ids]), not(readableResource(viewer, resources.id))));
116
+ return new Set(rows.map(({ id }) => id));
117
+ }
118
+ /**
119
+ * Determines whether the viewer may read the resource.
120
+ * @returns Whether {@link readableResource} holds for it.
121
+ */
122
+ const isReadableResource = async (viewer, id) => !(await unreadableResources(viewer, [id])).has(id);
123
+ const nodeIdOf = (node) => node != null && typeof node === "object" && "id" in node && validateUuid(node.id) ? node.id : null;
124
+ /**
125
+ * Replaces the Relay nodes the viewer may not read by null, as if they did
126
+ * not exist. Activities, objects, and resources share their IDs, so a node's
127
+ * ID alone tells whether it is one the viewer may not read.
128
+ * @returns The nodes, in the same order.
129
+ */
130
+ async function hideUnreadableNodes(viewer, nodes) {
131
+ const hidden = await unreadableResources(viewer, nodes.map(nodeIdOf).filter((id) => id != null));
132
+ return nodes.map((node) => {
133
+ const id = nodeIdOf(node);
134
+ return id != null && hidden.has(id) ? null : node;
135
+ });
136
+ }
137
+ //#endregion
138
+ export { readableResource as a, memberInstances as i, hideUnreadableNodes as n, viewableInstance as o, isReadableResource as r, PUBLIC_IRIS as t };
139
+
140
+ //# sourceMappingURL=readable-CSN0MPlO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readable-CSN0MPlO.mjs","names":[],"sources":["../src/readable.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport type { Database } from \"@drfed/models\";\nimport { PUBLIC_IRI } from \"@drfed/models/resource\";\nimport {\n type Account,\n activities,\n activityDeliveries,\n actors,\n addressing,\n instanceMembers,\n instances,\n objects,\n resources,\n} from \"@drfed/models/schema\";\nimport { type Uuid, validateUuid } from \"@drfed/models/uuid\";\nimport {\n type SQL,\n type SQLWrapper,\n and,\n eq,\n inArray,\n isNotNull,\n not,\n sql,\n} from \"drizzle-orm\";\nimport { type PgColumn, alias } from \"drizzle-orm/pg-core\";\n\n/**\n * The IRIs that address an activity or object to the public: the full one and\n * the compacted forms a JSON-LD document may carry.\n */\nexport const PUBLIC_IRIS: readonly string[] = [\n PUBLIC_IRI,\n \"as:Public\",\n \"Public\",\n];\n\n/**\n * Who reads, and the database to decide what they may read in.\n */\nexport interface Viewer {\n readonly db: Database;\n readonly account?: Account;\n}\n\n/**\n * The local instances an account is an accepted member of; pending members,\n * who have been invited but have not accepted yet, do not count.\n * @returns A query of their IDs.\n */\nexport const memberInstances = (\n db: Database,\n accountId: Uuid,\n ...conditions: SQL[]\n) =>\n db\n .select({ instanceId: instanceMembers.instanceId })\n .from(instanceMembers)\n .innerJoin(instances, eq(instanceMembers.instanceId, instances.id))\n .where(\n and(\n eq(instanceMembers.accountId, accountId),\n isNotNull(instanceMembers.accepted),\n isNotNull(instances.localId),\n ...conditions,\n ),\n );\n\n/**\n * Restricts rows to those of the local instances whose private records the\n * viewer may read: every local instance for an administrator, and those the\n * viewer is an accepted member of otherwise, as the `admin` and\n * `localInstanceMember` scopes decide for one instance. Filtering rows by it\n * before paging keeps a connection from telling of rows the viewer may not\n * read.\n * @param viewer The viewer and the database.\n * @param instanceId The column of the instance a row belongs to.\n * @returns The condition on the column.\n */\nexport function viewableInstance(viewer: Viewer, instanceId: PgColumn): SQL {\n const { account } = viewer;\n if (account == null) return sql`false`;\n return account.admin\n ? inArray(\n instanceId,\n viewer.db\n .select({ id: instances.id })\n .from(instances)\n .where(isNotNull(instances.localId)),\n )\n : inArray(instanceId, memberInstances(viewer.db, account.id));\n}\n\n// The predicates below are nested into queries on the same tables, so each\n// subquery reads an alias of its own to never capture the outer row. An\n// alias renders as its name alone, so a FROM clause names its table as well.\nconst authors = alias(actors, \"readable_authors\");\nconst remoteActivities = alias(activities, \"readable_remote_activities\");\nconst remoteObjects = alias(objects, \"readable_remote_objects\");\nconst carriers = alias(activities, \"readable_carriers\");\nconst entries = alias(addressing, \"readable_addressing\");\nconst targets = alias(resources, \"readable_targets\");\nconst deliveries = alias(activityDeliveries, \"readable_deliveries\");\n\nconst remoteActivity = (id: SQLWrapper): SQL => sql`exists (\n select 1 from ${activities} ${remoteActivities}\n join ${actors} ${authors} on ${authors.id} = ${remoteActivities.actorId}\n where ${remoteActivities.id} = ${id} and ${authors.localId} is null\n)`;\n\nconst remoteObject = (id: SQLWrapper): SQL => sql`exists (\n select 1 from ${objects} ${remoteObjects}\n join ${actors} ${authors} on ${authors.id} = ${remoteObjects.actorId}\n where ${remoteObjects.id} = ${id} and ${authors.localId} is null\n)`;\n\nconst addressedPublicly = (id: SQLWrapper): SQL => sql`exists (\n select 1 from ${addressing} ${entries}\n join ${resources} ${targets} on ${targets.id} = ${entries.targetId}\n where ${entries.sourceId} = ${id} and ${inArray(targets.iri, PUBLIC_IRIS)}\n)`;\n\n// Whether an instance the viewer may read received the activity, by one of\n// its deliveries the mark says carried what is opened.\nconst received = (viewer: Viewer, id: SQLWrapper, mark: PgColumn): SQL =>\n sql`exists (\n select 1 from ${activityDeliveries} ${deliveries}\n where ${deliveries.activityId} = ${id}\n and ${deliveries.direction} = 'inbound'\n and ${mark}\n and ${viewableInstance(viewer, deliveries.instanceId)}\n )`;\n\n// True for anything but an activity of a remote actor.\nconst readableActivity = (viewer: Viewer, id: SQLWrapper): SQL =>\n sql`(not ${remoteActivity(id)} or ${addressedPublicly(id)} or ${received(viewer, id, deliveries.carriedSnapshot)})`;\n\n// True for anything but an object of a remote actor. Only the activity that\n// carried the stored version opens it, since a later one may carry another;\n// one whose activity row is gone stays closed, since a missing row proves\n// nothing of who may read it. That activity being public opens only an\n// object embedded in it, since of one fetched apart it made public no more\n// than the IRI. Receiving that activity opens it only by a delivery that\n// carried the object as stored too, since one fetched apart from the activity\n// may differ from fetch to fetch.\nconst readableObject = (viewer: Viewer, id: SQLWrapper): SQL =>\n sql`(not ${remoteObject(id)} or ${addressedPublicly(id)} or exists (\n select 1 from ${objects} ${remoteObjects}\n join ${activities} ${carriers} on ${carriers.id} = ${remoteObjects.activityId}\n where ${remoteObjects.id} = ${id}\n and (\n (not ${remoteObjects.fetched} and ${addressedPublicly(carriers.id)})\n or ${received(viewer, carriers.id, deliveries.carriedObjectSnapshot)}\n )\n ))`;\n\n/**\n * Restricts resources to those the viewer may read. Received content is an\n * inbox's, which ActivityPub filters by the requester's permission (5.2) and\n * opens without authentication only when addressed to the public (5.6):\n *\n * - An administrator reads everything.\n * - An activity of a remote actor is readable when it is addressed to the\n * public, or when one of the local instances the viewer is a member of\n * received it, i.e. an inbound delivery to it is linked to the activity\n * and carried it as stored. A delivery of the same IRI with other\n * contents stays linked but opens nothing.\n * - An object of a remote actor is readable when it is addressed to the\n * public, when the activity that carried it embedded in it is, or when\n * one of the local instances the viewer is a member of received that\n * activity and the object as stored with it. An object fetched apart\n * from the activity is opened neither by the activity being public nor\n * by a delivery but one that fetched it as stored.\n * - Everything else, including the activities and objects of local actors\n * whatever their addressing, is readable.\n *\n * Filtering rows by it before paging keeps a connection from telling of rows\n * the viewer may not read.\n * @param viewer The viewer and the database.\n * @param id The resource ID in an outer query.\n * @returns The condition on the ID.\n */\nexport function readableResource(viewer: Viewer, id: SQLWrapper): SQL {\n if (viewer.account?.admin === true) return sql`true`;\n return sql`(${readableActivity(viewer, id)} and ${readableObject(viewer, id)})`;\n}\n\n/**\n * Finds the resources among the given IDs that the viewer may not read, as\n * {@link readableResource} decides. IDs of anything but a resource are never\n * among them.\n * @returns The IDs the viewer may not read.\n */\nexport async function unreadableResources(\n viewer: Viewer,\n ids: readonly Uuid[],\n): Promise<ReadonlySet<Uuid>> {\n if (ids.length === 0 || viewer.account?.admin === true) return new Set();\n const rows = await viewer.db\n .select({ id: resources.id })\n .from(resources)\n .where(\n and(\n inArray(resources.id, [...ids]),\n not(readableResource(viewer, resources.id)),\n ),\n );\n return new Set(rows.map(({ id }) => id));\n}\n\n/**\n * Determines whether the viewer may read the resource.\n * @returns Whether {@link readableResource} holds for it.\n */\nexport const isReadableResource = async (\n viewer: Viewer,\n id: Uuid,\n): Promise<boolean> => !(await unreadableResources(viewer, [id])).has(id);\n\nconst nodeIdOf = (node: unknown): Uuid | null =>\n node != null &&\n typeof node === \"object\" &&\n \"id\" in node &&\n validateUuid(node.id)\n ? node.id\n : null;\n\n/**\n * Replaces the Relay nodes the viewer may not read by null, as if they did\n * not exist. Activities, objects, and resources share their IDs, so a node's\n * ID alone tells whether it is one the viewer may not read.\n * @returns The nodes, in the same order.\n */\nexport async function hideUnreadableNodes(\n viewer: Viewer,\n nodes: readonly unknown[],\n): Promise<unknown[]> {\n const hidden = await unreadableResources(\n viewer,\n nodes.map(nodeIdOf).filter((id) => id != null),\n );\n return nodes.map((node) => {\n const id = nodeIdOf(node);\n return id != null && hidden.has(id) ? null : node;\n });\n}\n"],"mappings":";;;;;;;;;;AA8CA,MAAa,cAAiC;CAC5C;CACA;CACA;AACF;;;;;;AAeA,MAAa,mBACX,IACA,WACA,GAAG,eAEH,GACG,OAAO,EAAE,YAAY,gBAAgB,WAAW,CAAC,CAAC,CAClD,KAAK,eAAe,CAAC,CACrB,UAAU,WAAW,GAAG,gBAAgB,YAAY,UAAU,EAAE,CAAC,CAAC,CAClE,MACC,IACE,GAAG,gBAAgB,WAAW,SAAS,GACvC,UAAU,gBAAgB,QAAQ,GAClC,UAAU,UAAU,OAAO,GAC3B,GAAG,UACL,CACF;;;;;;;;;;;;AAaJ,SAAgB,iBAAiB,QAAgB,YAA2B;CAC1E,MAAM,EAAE,YAAY;CACpB,IAAI,WAAW,MAAM,OAAO,GAAG;CAC/B,OAAO,QAAQ,QACX,QACE,YACA,OAAO,GACJ,OAAO,EAAE,IAAI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