@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
package/README.md CHANGED
@@ -1,3 +1,255 @@
1
- # Temporary Holding Version
1
+ @drfed/graphql
2
+ ==============
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ GraphQL server for [DrFed], built with [Pothos] and [GraphQL Yoga]. Exposes
5
+ a Relay-compatible schema backed by Drizzle ORM.
6
+
7
+ [DrFed]: https://drfed.org/
8
+ [Pothos]: https://pothos-graphql.dev/
9
+ [GraphQL Yoga]: https://the-guild.dev/graphql/yoga-server
10
+
11
+
12
+ Scalars
13
+ -------
14
+
15
+ | Scalar | Description |
16
+ | ---------- | ------------------------- |
17
+ | `DateTime` | ISO 8601 timestamp |
18
+ | `Email` | Normalized e-mail address |
19
+ | `UUID` | RFC 4122 UUID |
20
+
21
+
22
+ Usage
23
+ -----
24
+
25
+ ~~~~ ts
26
+ import createFederation from "@drfed/federation";
27
+ import { createYogaServer } from "@drfed/graphql";
28
+
29
+ const federation = await createFederation(db, { kv });
30
+ const yoga = createYogaServer(db, federation, {
31
+ rootOrigin,
32
+ loginOrigins: new Set(["https://drfed.example.com"]),
33
+ });
34
+ // For a dedicated GraphQL listener; the application CLI owns combined routing.
35
+ serve({ fetch: yoga.fetch });
36
+ ~~~~
37
+
38
+ `createFederation`, from [`@drfed/federation`], builds a Fedify `Federation`
39
+ with every DrFed dispatcher registered. `createYogaServer` accepts a Drizzle
40
+ database instance, that federation, and server options, and returns a GraphQL
41
+ Yoga server ready to handle HTTP requests. The federation is stored in the
42
+ resolver context as is; `createYogaServer` never registers anything on it.
43
+
44
+ The installed `drfed-server` routes only the exact `/graphql` path to Yoga.
45
+ Combined mode injects `yoga.fetch` directly into the web runtime; `drfed-web`
46
+ uses a configured backend origin over HTTP. Both bridges promote only a
47
+ validated session token to Bearer authentication. Federation requests never
48
+ fall back to GraphQL or the frontend. See the
49
+ [CLI documentation](../drfed/README.md) for combined and `--no-web` deployments.
50
+
51
+ [`@drfed/federation`]: https://github.com/fedify-dev/drfed/tree/main/packages/federation
52
+
53
+
54
+ Reading activities and objects
55
+ ------------------------------
56
+
57
+ Activities and objects of local actors are readable by anyone, whatever their
58
+ addressing, since they are what DrFed's users make to debug with. What
59
+ remote actors sent is an inbox's content, which [ActivityPub] filters by the
60
+ requester's permission (section 5.2) and opens without authentication only
61
+ when addressed to the public (section 5.6):
62
+
63
+ - An activity of a remote actor is readable when it is addressed to the
64
+ public, or by an accepted member of a local instance that received it,
65
+ i.e. one of whose accepted inbound deliveries is linked to it and carried
66
+ it as stored. A delivery of the same activity IRI with other contents
67
+ stays linked for debugging, but grants nothing.
68
+ - An object of a remote actor is readable when it is addressed to the
69
+ public, when the activity it was received in is, or by an accepted member
70
+ of a local instance that received that activity and the object as stored
71
+ with it. When the object was fetched apart from the activity, only a
72
+ delivery whose inbox listener fetched it as stored received it so, since
73
+ it may differ from fetch to fetch.
74
+ - Administrators read everything.
75
+
76
+ `as:Public` and `Public` count as the public as well as its full IRI. What the
77
+ viewer may not read is left out as if it did not exist: `node` and `nodes`
78
+ return null for it, as do `Resource.detail` and `Activity.object`, and
79
+ `Actor.objects`, `Object.activities`, and `Collection.items` leave it out
80
+ before paging, so that neither cursors nor `totalCount` tell of it.
81
+
82
+ [ActivityPub]: https://www.w3.org/TR/activitypub/
83
+
84
+
85
+ Login mail and shutdown
86
+ -----------------------
87
+
88
+ `loginByEmail` returns a challenge ID for both known and unknown accounts.
89
+ A failed mail receipt or a provider exception keeps this response unchanged;
90
+ operators receive a fixed outcome diagnostic without provider error text or
91
+ message IDs. Users can request another link if mail does not arrive.
92
+
93
+ Pass `shutdownSignal` to `createYogaServer` to combine runtime shutdown with
94
+ each request's cancellation signal. The combined signal reaches Upyo's send
95
+ options. `trackOperation` keeps resolver work registered until the provider
96
+ settles, including a provider that ignores cancellation after the HTTP response
97
+ ends. The runtime owner must drain these operations before closing resources;
98
+ passing a signal alone does not guarantee that a transport stops.
99
+ See [Yoga execution cancellation] for the distinction between canceling an
100
+ HTTP response and stopping resolver work.
101
+
102
+ [Yoga execution cancellation]: https://the-guild.dev/graphql/yoga-server/docs/features/execution-cancellation
103
+
104
+
105
+ Activity deliveries
106
+ -------------------
107
+
108
+ `Instance.activityDeliveries` and `Actor.activityDeliveries` expose delivery
109
+ observations, newest first, with direction, status, and type filters. Only
110
+ accepted local instance members and site administrators can read them,
111
+ including through Relay node IDs. `Actor.activityDeliveries` lists the
112
+ deliveries that arrived at the actor's inbox, that the actor sent, and that are
113
+ addressed to the actor through any inbox, the shared one included. Addressing
114
+ through a collection counts as far as DrFed has stored the collection's
115
+ members. Each of its edges tells how the delivery concerns the actor:
116
+ `inboxOwner`, `sender`, `addressed`, `addressedDirectly` when the activity
117
+ named the actor itself, and `viaCollections`, every addressed collection the
118
+ actor was a member of when the delivery arrived, so that a shared-inbox
119
+ delivery, whose `actor` is null, still explains why it is in the actor's feed.
120
+ `ActivityDelivery.attempts` is a connection, oldest attempt first.
121
+
122
+ `ActivityDelivery.activity` is the stored activity a delivery is linked to,
123
+ and `Activity.deliveries` lists an activity's deliveries, newest first. Since
124
+ one activity's deliveries span instances, `Activity.deliveries` leaves out,
125
+ before paging, those of instances the viewer may not read, rather than failing
126
+ on them.
127
+
128
+ Wrap the federation HTTP surface with `createInboundRecorder` from
129
+ [`@drfed/federation`], passing a federation made by `createFederation` from
130
+ the same package and the root origin. Every inbox `POST`
131
+ is recorded, whether or not its body is JSON; recording errors never replace
132
+ federation responses. A request Fedify throws on is recorded too, with the
133
+ exception in `error` and no `statusCode`, and the exception is thrown again.
134
+ An inbound delivery keeps:
135
+
136
+ - The request as received: `rawBody` (or `rawBodyBase64` when the body is not
137
+ valid UTF-8), `requestHeaders`, and `requestUrl`. `payload` is the body
138
+ parsed as JSON for querying, and is `null` when it does not parse or
139
+ holds U+0000 or an unpaired surrogate, which PostgreSQL cannot store.
140
+ `cookie` headers are dropped, and `authorization` is kept only for the
141
+ `Signature` scheme.
142
+ - `inboxUrl`, the canonical IRI of the inbox, however the request spelled its
143
+ host or scheme.
144
+ - `verificationMechanism` and `verificationResult` summarize Fedify's
145
+ `onRequestFinished()` report, independently of OpenTelemetry sampling.
146
+ DrFed verifies nothing again. The result is `unattempted` when no
147
+ signature check ran before a preparation or parsing failure, and
148
+ `unobserved` when the report is missing or observation fails.
149
+ - The report can contain several attempts and keys; the delivery retains
150
+ one representative check. Root activity evaluations take precedence over
151
+ embedded portable objects. An authenticating attempt wins, followed by
152
+ the last cryptographically successful evaluation, including an attribution
153
+ refusal, then the last meaningful failed evaluation. A partly invalid
154
+ proof set remains `invalid_signature` or `key_fetch_error`.
155
+ - `key_fetch_error` comes from an explicit fetch failure. `error` includes
156
+ `keyFetchError:` and the HTTP status or the original error's name and
157
+ message, including for cached failures. A document with no usable key
158
+ that Fedify reports as `invalidSignature` is `invalid_signature`.
159
+ - A valid signature or proof can still fail authentication. Linked Data
160
+ Signatures with the wrong owner and Object Integrity Proofs with uncovered
161
+ attributions remain `verified` with `status` `rejected`. `error` records
162
+ Fedify's attribution, ownership, nonce or proof-policy reason. Other
163
+ refusals and processing failures use the completion report's reason;
164
+ exceptions retain the original thrown value's description.
165
+ - `verificationKey` is the actual successful key of the selected check, or
166
+ its last tried key on failure, including when refreshing a cached key
167
+ fails. Its history uses the key snapshot's ID, falling back to a valid
168
+ declared key ID when the snapshot has none. `signedKeyIri` is the HTTP
169
+ signature's declaration, preferring the successful check when several
170
+ HTTP signatures were evaluated. It may differ from the history ID or
171
+ refer to a mechanism that did not authenticate the request. Malformed
172
+ declarations remain in the raw request.
173
+ - `status`, which follows the response Fedify gave: `received` when the inbox
174
+ listener ran, `acknowledged` when the request was answered 2xx without it
175
+ (a duplicate, for instance), `rejected` when a verified activity was
176
+ refused or its handling threw, and `unverified` otherwise. With an inbox
177
+ queue, a delivery is
178
+ `acknowledged` when the request is answered and becomes `received` once the
179
+ queue worker runs the listener; the queued message carries its delivery ID.
180
+
181
+ `KeyVersion.firstSeen` and `lastSeen` are DrFed observation times, not remote
182
+ rotation times or evidence of continuous use. `Key` and `KeyVersion` hold
183
+ public material only and are readable by any authenticated viewer.
184
+
185
+ `deliverActivity`, also from [`@drfed/federation`], is the outbound entry point
186
+ for explicit recipients once local actor keys are available (#87). It removes
187
+ `bto` and `bcc` before delivery, records one row per destination inbox with
188
+ every recipient sharing it in `recipientIris`, and settles each delivery
189
+ independently. A recipient without an ID or an inbox is left out, because
190
+ Fedify does not deliver to it. The recorded `payload` is the document before
191
+ signing. `attempts` keeps every attempt that ended, with the status the remote
192
+ inbox answered, read from the responses `fetch()` publishes on
193
+ `diagnostics_channel`, and the causes of network errors. When the inbox
194
+ redirects a delivery, the status is the one the redirects ended with, whether
195
+ Fedify followed them, as it does when it signs the request, or `fetch()` did.
196
+ With a message queue, `createFederation` observes Fedify's outbox worker, and
197
+ each queued message carries the delivery it belongs to. A delivery becomes
198
+ `sent` when Fedify reports `activitypub.activity.sent` for its inbox, stays
199
+ `failed` while it is retried, and ends `permanently_failed`, or `abandoned`
200
+ when Fedify measures it abandoned after its retries ran out. A delivery Fedify
201
+ returns from without sending to the inbox, or without enqueuing a message to
202
+ it, is `permanently_failed` with no attempt, since Fedify makes none. The
203
+ queue is handed to Fedify as one without native retries, so that every retry
204
+ follows Fedify's policy and is recorded. Activity resource persistence (#88),
205
+ retention policies, and the activity-log UI (#13) are separate.
206
+
207
+ URL fields hold only values that parse as URLs, and no text field holds
208
+ U+0000; anything else a remote server sent stays in `rawBody` and
209
+ `requestHeaders`, and in `payload` when PostgreSQL can store it. `error` and
210
+ `responseBody` keep what a remote server answered with U+FFFD for each U+0000.
211
+ Deliveries are ordered by `created`, which for an inbound delivery is when the
212
+ request arrived; `completed` is when DrFed answered it.
213
+
214
+
215
+ Moved exports
216
+ -------------
217
+
218
+ The ActivityPub code that used to live in this package moved to
219
+ [`@drfed/federation`], which does not depend on GraphQL:
220
+
221
+ | Previous import | Replacement |
222
+ | ------------------------------------------------------ | ------------------------------------- |
223
+ | `@drfed/graphql/federation` (factory functions) | `@drfed/federation` |
224
+ | `@drfed/graphql/federation` (selections, serializers) | `@drfed/federation/object` |
225
+ | `@drfed/graphql/origin` | `@drfed/federation/origin` |
226
+ | `@drfed/graphql/activity-delivery` (runtime functions) | `@drfed/federation/activity-delivery` |
227
+
228
+ `@drfed/graphql/activity-delivery` now holds only the GraphQL types for
229
+ activity deliveries.
230
+
231
+
232
+ Generating the schema
233
+ ---------------------
234
+
235
+ Run `mise run generate:graphql-schema --output-file schema.graphql` from the
236
+ repository root. This task builds models, federation, and GraphQL through
237
+ `build:backend`, then imports the built schema directly. It does not build
238
+ the application CLI or frontend, so frontend compilation can use it without
239
+ creating a dependency cycle. Omitting `--output-file` writes to stdout.
240
+
241
+ The installed `drfed-server --generate-graphql-schema` option remains available
242
+ for users who need the schema from their installed version.
243
+
244
+
245
+ Runtime ownership
246
+ -----------------
247
+
248
+ `createYogaServer()` accepts an optional `trackOperation` callback. Supply a
249
+ callback that registers and returns each operation's completion promise when
250
+ the runtime closes database or mail resources on shutdown. It tracks context
251
+ loading and complete field and type resolvers, including work still running
252
+ after [Yoga cancels execution]. The CLI supplies its operation registry;
253
+ callers that omit the callback retain the existing behavior.
254
+
255
+ [Yoga cancels execution]: https://the-guild.dev/graphql/yoga-server/docs/features/execution-cancellation
@@ -0,0 +1,6 @@
1
+ import { t as DrFedObjectRef } from "./builder-CSxRffRp.mjs";
2
+ //#region src/account.d.ts
3
+ declare const Account: DrFedObjectRef;
4
+ //#endregion
5
+ export { Account };
6
+ //# sourceMappingURL=account.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.mts","names":[],"sources":["../src/account.ts"],"mappings":";;cAqFa,SAAS"}
@@ -0,0 +1,168 @@
1
+ import { n as builder } from "./builder-BLioFAdv.mjs";
2
+ import { Instance } from "./instance.mjs";
3
+ import { instanceMembers } from "@drfed/models/schema";
4
+ import { drizzleConnectionHelpers } from "@pothos/plugin-drizzle";
5
+ import { and, eq, isNotNull } from "drizzle-orm/sql/expressions";
6
+ //#region src/account.ts
7
+ /**
8
+ * The auth scopes for `Account` fields that only the `Account` itself and
9
+ * site administrators may read.
10
+ *
11
+ * @param account The `Account` the field belongs to.
12
+ * @returns A scope map granting access to the account itself or a site
13
+ * administrator.
14
+ */
15
+ function selfOrSiteAdmin(account) {
16
+ return { $any: {
17
+ admin: true,
18
+ accountSelf: account.id,
19
+ $granted: "ownAccount"
20
+ } };
21
+ }
22
+ const AccountRef = builder.drizzleNode("accounts", {
23
+ name: "Account",
24
+ description: "Represents an `Account` in the DrFed platform. Note that it differs from the ActivityPub `Actor`s that belong to `Instance`s.",
25
+ id: {
26
+ column(account) {
27
+ return account.id;
28
+ },
29
+ description: "The unique identifier of the `Account`."
30
+ },
31
+ fields: (t) => ({
32
+ uuid: t.expose("id", {
33
+ type: "UUID",
34
+ description: "The UUID of the `Account`."
35
+ }),
36
+ email: t.expose("email", {
37
+ type: "Email",
38
+ nullable: true,
39
+ description: "The email address of the `Account`. `null` unless the viewer is the `Account` itself or a site administrator.",
40
+ authScopes: selfOrSiteAdmin
41
+ }),
42
+ name: t.exposeString("name", { description: "The display name of the `Account`." }),
43
+ admin: t.exposeBoolean("admin", {
44
+ nullable: true,
45
+ description: "Whether the `Account` has administrator privileges. `null` unless the viewer is the `Account` itself or a site administrator.",
46
+ authScopes: selfOrSiteAdmin
47
+ }),
48
+ created: t.expose("created", {
49
+ type: "DateTime",
50
+ description: "The date/time when the `Account` was created."
51
+ })
52
+ })
53
+ });
54
+ const Account = AccountRef;
55
+ const accountInstancesConnection = drizzleConnectionHelpers(builder, "instanceMembers", {
56
+ query: { orderBy: {
57
+ created: "desc",
58
+ instanceId: "desc"
59
+ } },
60
+ select(nestedSelection) {
61
+ return { with: { instance: nestedSelection() } };
62
+ },
63
+ resolveNode(instanceMember) {
64
+ return instanceMember.instance;
65
+ }
66
+ });
67
+ builder.drizzleObjectField(AccountRef, "instances", (t) => t.connection({
68
+ type: Instance,
69
+ nullable: true,
70
+ description: "The `Instance`s that the `Account` belongs to. `null` unless the viewer is the `Account` itself or a site administrator; an empty connection means the `Account` belongs to no `Instance`.",
71
+ authScopes: selfOrSiteAdmin,
72
+ select(args, ctx, nestedSelection) {
73
+ return { with: { instanceMembers: accountInstancesConnection.getQuery(args, ctx, nestedSelection) } };
74
+ },
75
+ resolve(account, args, ctx) {
76
+ return {
77
+ ...accountInstancesConnection.resolve(account.instanceMembers, args, ctx, account),
78
+ totalCount() {
79
+ return ctx.db.$count(instanceMembers, and(eq(instanceMembers.accountId, account.id), isNotNull(instanceMembers.accepted)));
80
+ }
81
+ };
82
+ }
83
+ }, { fields(fb) {
84
+ return { totalCount: fb.int({
85
+ description: "The total number of `Instance`s that the `Account` belongs to.Note that pending memberships are not counted.",
86
+ resolve(connection) {
87
+ return connection.totalCount();
88
+ }
89
+ }) };
90
+ } }, { fields(fb) {
91
+ return {
92
+ created: fb.expose("created", {
93
+ type: "DateTime",
94
+ description: "The date/time when the `Account` was added to the `Instance`."
95
+ }),
96
+ accepted: fb.expose("accepted", {
97
+ type: "DateTime",
98
+ nullable: true,
99
+ description: "The date/time when the `Account` accepted membership in the `Instance`."
100
+ }),
101
+ admin: fb.exposeBoolean("admin", { description: "Whether the `Account` has administrator privileges in the `Instance`." })
102
+ };
103
+ } }));
104
+ builder.queryFields((t) => ({ accountByUuid: t.drizzleField({
105
+ args: { uuid: t.arg({
106
+ description: "The UUID of the `Account` to retrieve.",
107
+ required: true,
108
+ type: "UUID"
109
+ }) },
110
+ description: "Get an `Account` by its UUID.",
111
+ nullable: true,
112
+ authScopes: { authenticated: true },
113
+ resolve(query, _, { uuid }, ctx) {
114
+ return ctx.db.query.accounts.findFirst(query({ where: { id: uuid } }));
115
+ },
116
+ type: AccountRef
117
+ }) }));
118
+ const instanceMembersConnection = drizzleConnectionHelpers(builder, "instanceMembers", {
119
+ query: { orderBy: {
120
+ created: "desc",
121
+ accountId: "desc"
122
+ } },
123
+ select(nestedSelection) {
124
+ return { with: { account: nestedSelection() } };
125
+ },
126
+ resolveNode(instanceMember) {
127
+ return instanceMember.account;
128
+ }
129
+ });
130
+ builder.drizzleObjectField("instances", "members", (t) => t.connection({
131
+ type: Account,
132
+ description: "The `Account`s that belong to the `Instance`.",
133
+ select(args, ctx, nestedSelection) {
134
+ return { with: { instanceMembers: instanceMembersConnection.getQuery(args, ctx, nestedSelection) } };
135
+ },
136
+ resolve(instance, args, ctx) {
137
+ return {
138
+ ...instanceMembersConnection.resolve(instance.instanceMembers, args, ctx, instance),
139
+ totalCount() {
140
+ return ctx.db.$count(instanceMembers, and(eq(instanceMembers.instanceId, instance.id), isNotNull(instanceMembers.accepted)));
141
+ }
142
+ };
143
+ }
144
+ }, { fields(fb) {
145
+ return { totalCount: fb.int({
146
+ description: "The total number of `Account`s that belong to the `Instance`. Note that pending members are not counted.",
147
+ resolve(connection) {
148
+ return connection.totalCount();
149
+ }
150
+ }) };
151
+ } }, { fields(fb) {
152
+ return {
153
+ created: fb.expose("created", {
154
+ type: "DateTime",
155
+ description: "The date/time when the `Account` was added to the `Instance`."
156
+ }),
157
+ accepted: fb.expose("accepted", {
158
+ type: "DateTime",
159
+ nullable: true,
160
+ description: "The date/time when the `Account` accepted membership in the `Instance`."
161
+ }),
162
+ admin: fb.exposeBoolean("admin", { description: "Whether the `Account` has administrator privileges in the `Instance`." })
163
+ };
164
+ } }));
165
+ //#endregion
166
+ export { Account };
167
+
168
+ //# sourceMappingURL=account.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.mjs","names":[],"sources":["../src/account.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 { instanceMembers } from \"@drfed/models/schema\";\nimport type { Uuid } from \"@drfed/models/uuid\";\nimport { drizzleConnectionHelpers } from \"@pothos/plugin-drizzle\";\nimport { and, eq, isNotNull } from \"drizzle-orm/sql/expressions\";\n\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\nimport { Instance } from \"./instance.ts\";\n\n/**\n * The auth scopes for `Account` fields that only the `Account` itself and\n * site administrators may read.\n *\n * @param account The `Account` the field belongs to.\n * @returns A scope map granting access to the account itself or a site\n * administrator.\n */\nfunction selfOrSiteAdmin(account: { readonly id: Uuid }) {\n return {\n $any: {\n admin: true,\n accountSelf: account.id,\n // Granted by `Session.account`, whose account is always the viewer's own\n // but which is resolved on a request that carries no session yet.\n $granted: \"ownAccount\",\n },\n };\n}\n\nconst AccountRef = builder.drizzleNode(\"accounts\", {\n name: \"Account\",\n description:\n \"Represents an `Account` in the DrFed platform. \" +\n \"Note that it differs from the ActivityPub `Actor`s that belong to `Instance`s.\",\n id: {\n column(account) {\n return account.id;\n },\n description: \"The unique identifier of the `Account`.\",\n },\n fields: (t) => ({\n uuid: t.expose(\"id\", {\n type: \"UUID\",\n description: \"The UUID of the `Account`.\",\n }),\n email: t.expose(\"email\", {\n type: \"Email\",\n nullable: true,\n description:\n \"The email address of the `Account`. `null` unless the viewer is \" +\n \"the `Account` itself or a site administrator.\",\n authScopes: selfOrSiteAdmin,\n }),\n name: t.exposeString(\"name\", {\n description: \"The display name of the `Account`.\",\n }),\n admin: t.exposeBoolean(\"admin\", {\n nullable: true,\n description:\n \"Whether the `Account` has administrator privileges. `null` unless \" +\n \"the viewer is the `Account` itself or a site administrator.\",\n authScopes: selfOrSiteAdmin,\n }),\n created: t.expose(\"created\", {\n type: \"DateTime\",\n description: \"The date/time when the `Account` was created.\",\n }),\n }),\n});\n\nexport const Account: DrFedObjectRef = AccountRef;\n\nconst accountInstancesConnection = drizzleConnectionHelpers(\n builder,\n \"instanceMembers\",\n {\n query: {\n orderBy: { created: \"desc\", instanceId: \"desc\" },\n },\n select(nestedSelection) {\n return {\n with: {\n instance: nestedSelection(),\n },\n };\n },\n resolveNode(instanceMember) {\n return instanceMember.instance!;\n },\n },\n);\n\nbuilder.drizzleObjectField(AccountRef, \"instances\", (t) =>\n t.connection(\n {\n type: Instance,\n nullable: true,\n description:\n \"The `Instance`s that the `Account` belongs to. `null` unless the \" +\n \"viewer is the `Account` itself or a site administrator; an empty \" +\n \"connection means the `Account` belongs to no `Instance`.\",\n authScopes: selfOrSiteAdmin,\n select(args, ctx, nestedSelection) {\n return {\n with: {\n instanceMembers: accountInstancesConnection.getQuery(\n args,\n ctx,\n nestedSelection,\n ),\n },\n };\n },\n resolve(account, args, ctx) {\n return {\n ...accountInstancesConnection.resolve(\n account.instanceMembers,\n args,\n ctx,\n account,\n ),\n totalCount() {\n return ctx.db.$count(\n instanceMembers,\n and(\n eq(instanceMembers.accountId, account.id),\n isNotNull(instanceMembers.accepted),\n ),\n );\n },\n };\n },\n },\n {\n fields(fb) {\n return {\n totalCount: fb.int({\n description:\n \"The total number of `Instance`s that the `Account` belongs to.\" +\n \"Note that pending memberships are not counted.\",\n resolve(connection) {\n return connection.totalCount();\n },\n }),\n };\n },\n },\n {\n fields(fb) {\n return {\n created: fb.expose(\"created\", {\n type: \"DateTime\",\n description:\n \"The date/time when the `Account` was added to the `Instance`.\",\n }),\n accepted: fb.expose(\"accepted\", {\n type: \"DateTime\",\n nullable: true,\n description:\n \"The date/time when the `Account` accepted membership in the `Instance`.\",\n }),\n admin: fb.exposeBoolean(\"admin\", {\n description:\n \"Whether the `Account` has administrator privileges in the `Instance`.\",\n }),\n };\n },\n },\n ),\n);\n\nbuilder.queryFields((t) => ({\n accountByUuid: t.drizzleField({\n args: {\n uuid: t.arg({\n description: \"The UUID of the `Account` to retrieve.\",\n required: true,\n type: \"UUID\",\n }),\n },\n description: \"Get an `Account` by its UUID.\",\n nullable: true,\n authScopes: { authenticated: true },\n resolve(query, _, { uuid }, ctx) {\n return ctx.db.query.accounts.findFirst(query({ where: { id: uuid } }));\n },\n type: AccountRef,\n }),\n}));\n\nconst instanceMembersConnection = drizzleConnectionHelpers(\n builder,\n \"instanceMembers\",\n {\n query: {\n orderBy: { created: \"desc\", accountId: \"desc\" },\n },\n select(nestedSelection) {\n return {\n with: {\n account: nestedSelection(),\n },\n };\n },\n resolveNode(instanceMember) {\n return instanceMember.account;\n },\n },\n);\n\nbuilder.drizzleObjectField(\"instances\", \"members\", (t) =>\n t.connection(\n {\n type: Account,\n description: \"The `Account`s that belong to the `Instance`.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n instanceMembers: instanceMembersConnection.getQuery(\n args,\n ctx,\n nestedSelection,\n ),\n },\n };\n },\n resolve(instance, args, ctx) {\n return {\n ...instanceMembersConnection.resolve(\n instance.instanceMembers,\n args,\n ctx,\n instance,\n ),\n totalCount() {\n return ctx.db.$count(\n instanceMembers,\n and(\n eq(instanceMembers.instanceId, instance.id),\n isNotNull(instanceMembers.accepted),\n ),\n );\n },\n };\n },\n },\n {\n fields(fb) {\n return {\n totalCount: fb.int({\n description:\n \"The total number of `Account`s that belong to the `Instance`. \" +\n \"Note that pending members are not counted.\",\n resolve(connection) {\n return connection.totalCount();\n },\n }),\n };\n },\n },\n {\n fields(fb) {\n return {\n created: fb.expose(\"created\", {\n type: \"DateTime\",\n description:\n \"The date/time when the `Account` was added to the `Instance`.\",\n }),\n accepted: fb.expose(\"accepted\", {\n type: \"DateTime\",\n nullable: true,\n description:\n \"The date/time when the `Account` accepted membership in the `Instance`.\",\n }),\n admin: fb.exposeBoolean(\"admin\", {\n description:\n \"Whether the `Account` has administrator privileges in the `Instance`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AAO,EACL,MAAM,EACJ,iBAAiB,0BAA0B,SACzC,MACA,KACA,eACF,EACF,EACF;CACF;CACA,QAAQ,UAAU,MAAM,KAAK;EAC3B,OAAO;GACL,GAAG,0BAA0B,QAC3B,SAAS,iBACT,MACA,KACA,QACF;GACA,aAAa;IACX,OAAO,IAAI,GAAG,OACZ,iBACA,IACE,GAAG,gBAAgB,YAAY,SAAS,EAAE,GAC1C,UAAU,gBAAgB,QAAQ,CACpC,CACF;GACF;EACF;CACF;AACF,GACA,EACE,OAAO,IAAI;CACT,OAAO,EACL,YAAY,GAAG,IAAI;EACjB,aACE;EAEF,QAAQ,YAAY;GAClB,OAAO,WAAW,WAAW;EAC/B;CACF,CAAC,EACH;AACF,EACF,GACA,EACE,OAAO,IAAI;CACT,OAAO;EACL,SAAS,GAAG,OAAO,WAAW;GAC5B,MAAM;GACN,aACE;EACJ,CAAC;EACD,UAAU,GAAG,OAAO,YAAY;GAC9B,MAAM;GACN,UAAU;GACV,aACE;EACJ,CAAC;EACD,OAAO,GAAG,cAAc,SAAS,EAC/B,aACE,wEACJ,CAAC;CACH;AACF,EACF,CACF,CACF"}
@@ -0,0 +1,6 @@
1
+ import { t as DrFedObjectRef } from "../builder-CSxRffRp.mjs";
2
+ //#region src/activity-delivery/entry.d.ts
3
+ declare const ActivityDelivery: DrFedObjectRef;
4
+ //#endregion
5
+ export { ActivityDelivery };
6
+ //# sourceMappingURL=entry.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.d.mts","names":[],"sources":["../../src/activity-delivery/entry.ts"],"mappings":";;cAkWa,kBAAkB"}