@drfed/graphql 0.2.0-dev.716 → 0.2.0-dev.717
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/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as hashSecret, t as schema } from "./schema-
|
|
1
|
+
import { n as hashSecret, t as schema } from "./schema-DRjGCIYI.mjs";
|
|
2
2
|
import { canonicalHostname } from "@drfed/federation/origin";
|
|
3
3
|
import { getYogaLogger } from "@logtape/graphql-yoga";
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -323,6 +323,7 @@ const DocumentSourceStatus = builder.enumType("DocumentSourceStatus", {
|
|
|
323
323
|
});
|
|
324
324
|
const DocumentSource = builder.objectRef("DocumentSource");
|
|
325
325
|
const DocumentNode = builder.objectRef("DocumentNode");
|
|
326
|
+
const DocumentPollChoice = builder.objectRef("DocumentPollChoice");
|
|
326
327
|
const DocumentRelation = builder.objectRef("DocumentRelation");
|
|
327
328
|
const DocumentRecipient = builder.objectRef("DocumentRecipient");
|
|
328
329
|
const resourceLookups = /* @__PURE__ */ new WeakMap();
|
|
@@ -480,6 +481,58 @@ DocumentRecipient.implement({
|
|
|
480
481
|
})
|
|
481
482
|
})
|
|
482
483
|
});
|
|
484
|
+
const PollChoiceMode = builder.enumType("PollChoiceMode", {
|
|
485
|
+
description: "How a Question's choices may be answered.",
|
|
486
|
+
values: {
|
|
487
|
+
exclusive: { description: "A single-choice poll, from `oneOf`." },
|
|
488
|
+
inclusive: { description: "A multiple-choice poll, from `anyOf`." }
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
DocumentPollChoice.implement({
|
|
492
|
+
description: "One of a Question's choices as saved in this revision.",
|
|
493
|
+
fields: (t) => ({
|
|
494
|
+
path: t.expose("path", {
|
|
495
|
+
type: "JSON",
|
|
496
|
+
description: "The choice's source path from the root of the revision."
|
|
497
|
+
}),
|
|
498
|
+
iri: t.expose("iri", {
|
|
499
|
+
type: "URL",
|
|
500
|
+
nullable: true,
|
|
501
|
+
description: "The choice's IRI, or null for an anonymous embedded choice."
|
|
502
|
+
}),
|
|
503
|
+
node: t.expose("node", {
|
|
504
|
+
type: DocumentNode,
|
|
505
|
+
nullable: true,
|
|
506
|
+
description: "The choice's saved document, or null for an IRI reference."
|
|
507
|
+
})
|
|
508
|
+
})
|
|
509
|
+
});
|
|
510
|
+
const DocumentPoll = builder.objectRef("DocumentPoll");
|
|
511
|
+
DocumentPoll.implement({
|
|
512
|
+
description: "The poll fields of a saved Question.",
|
|
513
|
+
fields: (t) => ({
|
|
514
|
+
mode: t.expose("mode", {
|
|
515
|
+
type: PollChoiceMode,
|
|
516
|
+
nullable: true,
|
|
517
|
+
description: "The choice mode, or null for a Question without choices."
|
|
518
|
+
}),
|
|
519
|
+
choices: t.expose("choices", {
|
|
520
|
+
type: [DocumentPollChoice],
|
|
521
|
+
description: "Choices sorted by source key, then by list position, including duplicates."
|
|
522
|
+
}),
|
|
523
|
+
closed: t.boolean({
|
|
524
|
+
nullable: true,
|
|
525
|
+
description: "The saved boolean closing value, or null if there is none.",
|
|
526
|
+
resolve: ({ closed }) => typeof closed === "boolean" ? closed : null
|
|
527
|
+
}),
|
|
528
|
+
closedTime: t.field({
|
|
529
|
+
type: "DateTime",
|
|
530
|
+
nullable: true,
|
|
531
|
+
description: "The saved closing instant, or null if there is none.",
|
|
532
|
+
resolve: ({ closed }) => typeof closed === "string" ? Temporal.Instant.from(closed) : null
|
|
533
|
+
})
|
|
534
|
+
})
|
|
535
|
+
});
|
|
483
536
|
DocumentNode.implement({
|
|
484
537
|
description: "A vocabulary document of a saved revision, the root or one embedded in it at any depth, read by meaning, whatever keys spell its properties. It may be anonymous.",
|
|
485
538
|
fields: (t) => ({
|
|
@@ -505,6 +558,11 @@ DocumentNode.implement({
|
|
|
505
558
|
type: "JSON",
|
|
506
559
|
description: "Its JSON as saved, with everything it embeds."
|
|
507
560
|
}),
|
|
561
|
+
poll: t.expose("poll", {
|
|
562
|
+
type: DocumentPoll,
|
|
563
|
+
nullable: true,
|
|
564
|
+
description: "The saved poll fields, or null for a type other than Question."
|
|
565
|
+
}),
|
|
508
566
|
relations: t.field({
|
|
509
567
|
type: [DocumentRelation],
|
|
510
568
|
args: { property: t.arg({ type: RelationProperty }) },
|
|
@@ -704,4 +762,4 @@ const schema$1 = builder.toSchema();
|
|
|
704
762
|
//#endregion
|
|
705
763
|
export { hashSecret as n, schema$1 as t };
|
|
706
764
|
|
|
707
|
-
//# sourceMappingURL=schema-
|
|
765
|
+
//# sourceMappingURL=schema-DRjGCIYI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-DRjGCIYI.mjs","names":["eq","and","schema"],"sources":["../src/auth/hash.ts","../src/auth/expand.ts","../src/auth/mail.ts","../src/auth/magic-link.ts","../src/auth/challenge.ts","../src/auth/revoke.ts","../src/auth/entry.ts","../src/revision.ts","../src/key.ts","../src/schema.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// oxlint-disable func-names func-style id-length\n\nexport const hashSecret = async (raw: string): Promise<string> =>\n new Uint8Array(\n await crypto.subtle.digest(\"SHA-256\", textEncoder.encode(raw)),\n ).toHex();\n\nconst textEncoder = new TextEncoder();\n\nconst ACCESS_TOKEN_BYTES = 32;\n\nexport const generateAccessToken = (): string =>\n crypto.getRandomValues(new Uint8Array(ACCESS_TOKEN_BYTES)).toBase64({\n alphabet: \"base64url\",\n omitPadding: true,\n });\n","// 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 { Template } from \"@fedify/uri-template\";\nimport { GraphQLError } from \"graphql\";\n\nexport interface ExpandVerifyUrlParams {\n template: Template;\n challengeId: `${string}-${string}-${string}-${string}-${string}`;\n code: string;\n loginOrigins: ReadonlySet<string>;\n}\n\nexport default function expandVerifyUrl({\n template,\n challengeId,\n code,\n loginOrigins,\n}: ExpandVerifyUrlParams): string {\n assertVariable(template, \"challengeId\");\n assertVariable(template, \"code\");\n\n let url: URL;\n try {\n url = new URL(template.expand({ challengeId, code }));\n } catch {\n throw invalidVerifyUrl(\n \"Verify URL template must expand to an absolute URL.\",\n );\n }\n\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n throw invalidVerifyUrl(\"Verify URL must use HTTP or HTTPS.\");\n }\n if (!loginOrigins.has(url.origin)) {\n throw invalidVerifyUrl(`Verify URL origin is not allowed: ${url.origin}.`);\n }\n return url.href;\n}\n\nfunction assertVariable(template: Template, name: string): void {\n const found = template.tokens.some(\n (token) =>\n token.kind === \"expression\" &&\n token.vars.some(\n (variable) => variable.name === name && variable.prefix == null,\n ),\n );\n if (!found) {\n throw invalidVerifyUrl(`Verify URL template must include {${name}}.`);\n }\n}\n\nconst invalidVerifyUrl = (message: string) =>\n new GraphQLError(message, { extensions: { code: \"BAD_USER_INPUT\" } });\n","// 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 { getLogger } from \"@logtape/logtape\";\nimport { type MessageContent, type Receipt, createMessage } from \"@upyo/core\";\n\nimport type { UserContext } from \"../builder.ts\";\n\n/** Send login mail without exposing non-cancellation provider failures. */\nexport async function sendMail(\n to: string,\n loginUrl: string,\n ctx: UserContext,\n): Promise<void> {\n const signal = ctx.operationSignal ?? ctx.request.signal;\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n try {\n const receipt = await ctx.mailer.send(\n createMessage({\n from: ctx.emailFrom,\n to,\n // FIXME: https://github.com/fedify-dev/drfed/issues/35\n subject: \"Sign in to DrFed\",\n content: renderLoginEmail(loginUrl),\n }),\n { signal },\n );\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n logReceipt(receipt);\n } catch {\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n logger.warn(\"Login mail delivery failed.\", { outcome: \"exception\" });\n }\n}\n\nconst renderLoginEmail = (loginUrl: string): MessageContent => ({\n // FIXME: https://github.com/fedify-dev/drfed/issues/35\n // oxlint-disable no-inline-comments\n text: `Hello, Welcome to DrFed! If you request to login to DrFed, please visit:\n\nopen ${loginUrl}${/* Split between the link and the last `\\n` */ \" \"}\n\nOtherwise, please just ignore this mail.`,\n});\n// oxlint-enable no-inline-comments\n\nexport function logReceipt(receipt: Receipt<string>): void {\n if (receipt.successful) {\n logger.debug(\"Login mail delivery succeeded.\", { outcome: \"sent\" });\n return;\n }\n logger.warn(\"Login mail delivery failed.\", { outcome: \"failed\" });\n}\n\nconst logger = getLogger([\"drfed\", \"graphql\", \"auth\"]);\n","// 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\n// oxlint-disable no-magic-numbers\n\nimport { schema } from \"@drfed/models\";\nimport { generateLoginChallengeCode } from \"@drfed/models/login\";\nimport { type Uuid, uuidV7 } from \"@drfed/models/uuid\";\n\nimport builder, { type UserContext } from \"../builder.ts\";\nimport expandVerifyUrl from \"./expand.ts\";\nimport { sendMail } from \"./mail.ts\";\n\ninterface LoginChallengeShape {\n readonly challengeId: Uuid;\n}\n\nconst LoginChallengeRef = builder\n .objectRef<LoginChallengeShape>(\"LoginChallenge\")\n .implement({\n description: \"An email login challenge.\",\n fields: (t) => ({\n challengeId: t.expose(\"challengeId\", {\n type: \"UUID\",\n description: \"The public identifier of the login challenge.\",\n }),\n }),\n });\n\nbuilder.mutationFields((t) => ({\n loginByEmail: t.field({\n type: LoginChallengeRef,\n description:\n \"Send a magic link without revealing whether the account exists.\",\n args: {\n email: t.arg({\n type: \"Email\",\n required: true,\n description: \"The email address of the `Account`.\",\n }),\n verifyUrl: t.arg({\n type: \"URITemplate\",\n required: true,\n description:\n \"Use {challengeId} and {code} variables. \" +\n \"The URL's origin must be in the server's login allowlist.\",\n }),\n },\n async resolve(_root, { email, verifyUrl }, ctx) {\n const challengeId = uuidV7();\n const code = generateLoginChallengeCode();\n const loginUrl = expandVerifyUrl({\n challengeId,\n code,\n loginOrigins: ctx.loginOrigins,\n template: verifyUrl,\n });\n const account = await findAccount(email, ctx);\n if (account == null) {\n // Return an ID even for an unknown account to prevent account\n // enumeration. Consider mailing in a worker to prevent timing attacks.\n return { challengeId };\n }\n const verifier = {\n challengeId,\n code,\n };\n\n await insertChallenge(account.id, verifier, ctx);\n // Do not check the email was sent. Instructs users to request a resend if\n // the email does not arrive after a few minutes at the web page.\n await sendMail(account.email, loginUrl, ctx);\n\n return { challengeId };\n },\n }),\n}));\n\nconst findAccount = async (email: string, ctx: UserContext) =>\n await ctx.db.query.accounts.findFirst({\n where: { email },\n });\n\nconst insertChallenge = async (\n accountId: Uuid,\n { challengeId, code }: { challengeId: Uuid; code: string },\n ctx: UserContext,\n) =>\n await ctx.db.insert(schema.loginChallenges).values({\n id: challengeId,\n accountId,\n code,\n });\n","// 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\n// oxlint-disable no-magic-numbers\n\nimport { Buffer } from \"node:buffer\";\nimport { timingSafeEqual } from \"node:crypto\";\n\nimport type { Database } from \"@drfed/models\";\nimport {\n LoginChallengeError,\n consumeLoginChallenge,\n findLoginChallenge,\n} from \"@drfed/models/login\";\nimport { sessions } from \"@drfed/models/schema\";\nimport type { Uuid } from \"@drfed/models/uuid\";\n\nimport builder from \"../builder.ts\";\nimport { generateAccessToken, hashSecret } from \"./hash.ts\";\n\nconst SessionRef = builder.drizzleObject(\"sessions\", {\n name: \"Session\",\n fields: (t) => ({\n id: t.expose(\"id\", { type: \"UUID\" }),\n accessToken: t.string({\n nullable: true,\n resolve(session) {\n const accessToken =\n \"accessToken\" in session ? session.accessToken : null;\n return typeof accessToken === \"string\" ? accessToken : null;\n },\n }),\n // The only `Session` a client can obtain is the one `completeLoginChallenge`\n // just created for it, and `Session` is not a `Node`, so the account behind\n // a session is always the viewer's own. Granting `ownAccount` here lets\n // the login response carry the viewer's private fields even though the\n // request that produced it had no session yet.\n account: t.relation(\"account\", { grantScopes: [\"ownAccount\"] }),\n created: t.expose(\"created\", { type: \"DateTime\" }),\n expires: t.expose(\"expires\", { type: \"DateTime\" }),\n }),\n});\n\nbuilder.mutationFields((t) => ({\n completeLoginChallenge: t.drizzleField({\n type: SessionRef,\n nullable: true,\n description: \"Complete login challenge.\",\n args: {\n challengeId: t.arg({ type: \"UUID\", required: true }),\n code: t.arg({ type: \"String\", required: true }),\n },\n async resolve(query, _root, { challengeId, code }, ctx) {\n try {\n const now = Temporal.Now.instant();\n const row = await findLoginChallenge(ctx.db, challengeId, now);\n const id = crypto.randomUUID();\n const accessToken = generateAccessToken();\n const accessHash = await hashSecret(accessToken);\n\n const providedCode = Buffer.from(code.toLowerCase());\n const expectedCode = Buffer.from(row.code);\n if (\n providedCode.length !== expectedCode.length ||\n !timingSafeEqual(providedCode, expectedCode)\n ) {\n throw new LoginChallengeError(\"The provided code does not match.\");\n }\n await ctx.db.transaction(async (tx) => {\n await consumeLoginChallenge(tx, row.id, now);\n await insertSession(id, row.accountId, accessHash, tx);\n });\n\n const session = await ctx.db.query.sessions.findFirst(\n query({ where: { id } }),\n );\n return session == null ? null : { ...session, accessToken };\n } catch (error) {\n if (error instanceof LoginChallengeError) {\n return null;\n }\n throw error;\n }\n },\n }),\n}));\n\nconst insertSession = async (\n id: Uuid,\n accountId: Uuid,\n tokenHash: string,\n tx: Database,\n) => await tx.insert(sessions).values({ id, accountId, tokenHash });\n","// 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\n// oxlint-disable no-magic-numbers\n\nimport { sessions } from \"@drfed/models/schema\";\nimport { eq } from \"drizzle-orm/sql/expressions\";\n\nimport builder, { type UserContext } from \"../builder.ts\";\n\nbuilder.mutationFields((t) => ({\n revokeSession: t.field({\n type: LogoutSuccessRef,\n description: \"Revokes a session. Return always `revoke: true`.\",\n authScopes: {\n authenticated: true,\n },\n async resolve(_query, _, ctx) {\n const sessionId = ctx.session?.id;\n if (sessionId) {\n await deleteSession(ctx);\n }\n // Return always true to prevent brute-force attack.\n return { revoke: true };\n },\n }),\n}));\n\ninterface LogoutSuccessShape {\n revoke: boolean;\n}\n\nconst LogoutSuccessRef = builder\n .objectRef<LogoutSuccessShape>(\"LogoutSuccess\")\n .implement({\n description: \"The session revoked.\",\n fields: (t) => ({\n revoke: t.expose(\"revoke\", {\n type: \"Boolean\",\n description: \"Revoking status.\",\n }),\n }),\n });\n\nconst deleteSession = (ctx: UserContext) =>\n ctx.db.delete(sessions).where(eq(sessions.id, ctx.session!.id));\n","// 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\n// oxlint-disable import/no-unassigned-import\nimport \"./magic-link.ts\";\nimport \"./challenge.ts\";\nimport \"./revoke.ts\";\nimport builder from \"../builder.ts\";\n\nbuilder.queryFields((t) => ({\n viewer: t.drizzleField({\n type: \"accounts\",\n nullable: true,\n description: \"`Account` if authorized, else `null`\",\n resolve: (query, _root, _args, ctx) =>\n ctx.session == null\n ? null\n : ctx.db.query.accounts.findFirst(\n query({ where: { id: ctx.session.accountId } }),\n ),\n }),\n}));\n","// 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 type InterpretedNode,\n type InterpretedPoll,\n type PollChoice,\n RELATION_PROPERTIES,\n type RecipientOccurrence,\n type RelationOccurrence,\n interpretDocument,\n} from \"@drfed/federation/document\";\nimport { schema } from \"@drfed/models\";\nimport {\n type Diagnostic,\n type DiagnosticCategory,\n type DiagnosticSeverity,\n type DocumentNodeKind,\n validateDocument,\n} from \"@drfed/models/document\";\nimport type {\n ResourceRevision as ResourceRevisionRow,\n Resource as ResourceRow,\n RevisionEmbedding,\n} from \"@drfed/models/schema\";\nimport type { Uuid } from \"@drfed/models/uuid\";\nimport { and, eq, inArray } from \"drizzle-orm\";\n\nimport builder, { type DrFedObjectRef, type UserContext } from \"./builder.ts\";\nimport { readableResourceNode, readableRevision } from \"./readable.ts\";\nimport { Resource } from \"./resource.ts\";\n\nconst ACTIVITY_STREAMS = \"https://www.w3.org/ns/activitystreams#\";\n\nconst ResourceRevisionKind = builder.enumType(\"ResourceRevisionKind\", {\n description: \"What a revision records.\",\n values: {\n snapshot: { description: \"A saved document.\" },\n unavailable: {\n description:\n \"A legacy typed row that had no retained document; nothing replaces it.\",\n },\n whiteout: {\n description:\n \"A deletion: its time and the types the resource had, but no document.\",\n },\n } satisfies Record<ResourceRevisionRow[\"kind\"], object>,\n});\nconst ResourceRevisionCapture = builder.enumType(\"ResourceRevisionCapture\", {\n description:\n \"How DrFed came to store a revision. Neither proves ownership nor \" +\n \"grants access.\",\n values: {\n local: { description: \"Saved by DrFed for a local actor.\" },\n received: { description: \"Received in an inbound activity.\" },\n embedded: { description: \"Embedded in another received document.\" },\n fetched: {\n description:\n \"Fetched apart from an activity. For legacy data, a conservative \" +\n \"flag that is no proof an HTTP fetch occurred.\",\n },\n } satisfies Record<ResourceRevisionRow[\"capture\"], object>,\n});\nconst DocumentNodeKindEnum = builder.enumType(\"DocumentNodeKind\", {\n description: \"The vocabulary category of a document's type.\",\n values: {\n activity: {},\n actor: {},\n collection: {},\n link: {},\n object: {},\n } satisfies Record<DocumentNodeKind, object>,\n});\nconst RelationProperty = builder.enumType(\"RelationProperty\", {\n description: \"A property that relates a document to another resource.\",\n values: RELATION_PROPERTIES,\n});\nconst AddressingProperty = builder.enumType(\"AddressingProperty\", {\n description: \"A property that addresses a document's recipients.\",\n values: schema.addressingPropertyEnum.enumValues,\n});\nconst RelationRepresentation = builder.enumType(\"RelationRepresentation\", {\n description: \"How a value names what it stands for.\",\n values: {\n reference: { description: \"An IRI.\" },\n embedded: { description: \"An embedded document.\" },\n link: { description: \"An embedded `Link`, which names it by `href`.\" },\n } satisfies Record<RelationOccurrence[\"representation\"], object>,\n});\nconst DiagnosticCategoryEnum = builder.enumType(\"DiagnosticCategory\", {\n values: {\n vocabulary: {\n description: \"The document breaks a vocabulary or JSON-LD rule.\",\n },\n authority: { description: \"The document claims what it may not.\" },\n support: { description: \"DrFed's validator cannot check it.\" },\n compatibility: {\n description: \"Valid, but other implementations may read it otherwise.\",\n },\n } satisfies Record<DiagnosticCategory, object>,\n});\nconst DiagnosticSeverityEnum = builder.enumType(\"DiagnosticSeverity\", {\n values: {\n error: {},\n warning: {},\n } satisfies Record<DiagnosticSeverity, object>,\n});\n\nconst DocumentExtension = builder.objectRef<{\n readonly key: string;\n readonly value: unknown;\n}>(\"DocumentExtension\");\nDocumentExtension.implement({\n description: \"A custom extension property, preserved as opaque JSON.\",\n fields: (t) => ({\n key: t.exposeString(\"key\", {\n description: \"The key in its source spelling.\",\n }),\n value: t.expose(\"value\", { type: \"JSON\", description: \"As saved.\" }),\n }),\n});\n\nconst DocumentDiagnostic = builder.objectRef<Diagnostic>(\"DocumentDiagnostic\");\nDocumentDiagnostic.implement({\n description: \"A finding of the document validator.\",\n fields: (t) => ({\n reason: t.exposeString(\"reason\", {\n description:\n \"A stable classification, such as `unsupported_property`. Use it \" +\n \"for decisions rather than `message`.\",\n }),\n category: t.expose(\"category\", { type: DiagnosticCategoryEnum }),\n severity: t.expose(\"severity\", { type: DiagnosticSeverityEnum }),\n path: t.expose(\"path\", {\n type: \"JSON\",\n description:\n \"The source keys and list indexes leading to the finding; `[]` is \" +\n \"the root.\",\n }),\n message: t.exposeString(\"message\", {\n description: \"For people; it may change.\",\n }),\n }),\n});\n\nconst DocumentSourceRelation = builder.enumType(\"DocumentSourceRelation\", {\n description:\n \"How an embedded document relates to the revision it came from, as \" +\n \"recorded when the document embedding it was saved.\",\n values: {\n snapshot: {\n description:\n \"It keeps the source revision's contents, apart from the context \" +\n \"it inherits from the document embedding it.\",\n },\n derived: {\n description:\n \"It started from the source revision and was changed, as a test \" +\n \"input with other addressing or an altered property.\",\n },\n } satisfies Record<RevisionEmbedding[\"relation\"], object>,\n});\nconst DocumentSourceStatus = builder.enumType(\"DocumentSourceStatus\", {\n description:\n \"Where the source revision stands in its resource's history. It \" +\n \"compares revisions, not contents.\",\n values: {\n current: { description: \"It is the resource's current revision.\" },\n superseded: {\n description:\n \"A later revision is current, which may have the same contents.\",\n },\n deleted: { description: \"The resource's current revision is a whiteout.\" },\n },\n});\n\ntype SourceStatus = \"current\" | \"superseded\" | \"deleted\";\n\n/** A recorded embedding whose source revision the viewer may read. */\ninterface Source {\n readonly relation: RevisionEmbedding[\"relation\"];\n readonly revision: ResourceRevisionRow;\n /** Null when the viewer may not read the resource's current revision. */\n readonly status: SourceStatus | null;\n}\nconst DocumentSource = builder.objectRef<Source>(\"DocumentSource\");\n\nconst DocumentNode = builder.objectRef<InterpretedNode>(\"DocumentNode\");\nconst DocumentPollChoice = builder.objectRef<PollChoice>(\"DocumentPollChoice\");\nconst DocumentRelation =\n builder.objectRef<RelationOccurrence>(\"DocumentRelation\");\nconst DocumentRecipient =\n builder.objectRef<RecipientOccurrence>(\"DocumentRecipient\");\n\nconst resourceLookups = new WeakMap<\n UserContext,\n Map<string, Promise<ResourceRow | null>>\n>();\n\n/**\n * Finds the resource registered under an IRI, as `Activity.object` opens\n * it: only when the viewer may read it or one of its revisions. A deleted\n * one is found too, since its revisions stay readable. Lookups are shared within a request, since\n * a document may name one IRI many times.\n * @returns The resource, or null.\n */\nfunction registeredResource(\n ctx: UserContext,\n iri: string | null,\n): Promise<ResourceRow | null> {\n if (iri == null) return Promise.resolve(null);\n let lookups = resourceLookups.get(ctx);\n if (lookups == null) {\n lookups = new Map();\n resourceLookups.set(ctx, lookups);\n }\n let lookup = lookups.get(iri);\n if (lookup == null) {\n lookup = (async () =>\n (await ctx.db.query.resources.findFirst({\n where: {\n iri,\n RAW: (table) => readableResourceNode(ctx, table.id),\n },\n })) ?? null)();\n lookups.set(iri, lookup);\n }\n return lookup;\n}\n\n// The revision each interpreted node belongs to.\nconst nodeRevisions = new WeakMap<InterpretedNode, Uuid>();\n\nconst sourceLookups = new WeakMap<\n UserContext,\n Map<Uuid, Promise<ReadonlyMap<string, Source>>>\n>();\n\n/**\n * Tells where a source revision stands against its resource's current\n * revision. An `unavailable` current revision, a legacy typed row without a\n * retained document, is a later revision like any other.\n * @param revision The source revision.\n * @param current The current revision of its resource, when the viewer may\n * read it.\n * @returns The status, or null without a readable current revision.\n */\nconst statusOf = (\n revision: ResourceRevisionRow,\n current: Pick<ResourceRevisionRow, \"id\" | \"kind\"> | undefined,\n): SourceStatus | null =>\n current == null\n ? null\n : current.id === revision.id\n ? \"current\"\n : current.kind === \"whiteout\"\n ? \"deleted\"\n : \"superseded\";\n\n/**\n * Loads the recorded sources of a revision's embedded documents that the\n * viewer may read, with where each stands, in two queries per revision\n * whatever the number of documents it embeds. Lookups are shared within a\n * request.\n * @returns The sources, keyed by the JSON of the embedded documents' paths.\n */\nfunction sourcesOf(\n ctx: UserContext,\n revisionId: Uuid,\n): Promise<ReadonlyMap<string, Source>> {\n let lookups = sourceLookups.get(ctx);\n if (lookups == null) {\n lookups = new Map();\n sourceLookups.set(ctx, lookups);\n }\n let lookup = lookups.get(revisionId);\n if (lookup == null) {\n lookup = (async () => {\n const embeddings = await ctx.db\n .select({\n path: schema.revisionEmbeddings.path,\n relation: schema.revisionEmbeddings.relation,\n revision: schema.resourceRevisions,\n })\n .from(schema.revisionEmbeddings)\n .innerJoin(\n schema.resourceRevisions,\n eq(\n schema.resourceRevisions.id,\n schema.revisionEmbeddings.sourceRevisionId,\n ),\n )\n .where(\n and(\n eq(schema.revisionEmbeddings.revisionId, revisionId),\n readableRevision(ctx, schema.resourceRevisions.id),\n ),\n );\n const resourceIds = [\n ...new Set(embeddings.map(({ revision }) => revision.resourceId)),\n ];\n const heads =\n resourceIds.length === 0\n ? []\n : await ctx.db\n .select({\n resourceId: schema.resourceHeads.resourceId,\n id: schema.resourceRevisions.id,\n kind: schema.resourceRevisions.kind,\n })\n .from(schema.resourceHeads)\n .innerJoin(\n schema.resourceRevisions,\n eq(\n schema.resourceRevisions.id,\n schema.resourceHeads.revisionId,\n ),\n )\n .where(\n and(\n inArray(schema.resourceHeads.resourceId, resourceIds),\n readableRevision(ctx, schema.resourceRevisions.id),\n ),\n );\n const current = new Map(\n heads.map((head) => [head.resourceId, head] as const),\n );\n return new Map(\n embeddings.map(({ path, relation, revision }) => [\n JSON.stringify(path),\n {\n relation,\n revision,\n status: statusOf(revision, current.get(revision.resourceId)),\n },\n ]),\n );\n })();\n lookups.set(revisionId, lookup);\n }\n return lookup;\n}\n\n/**\n * Finds the recorded source of an embedded document, when the viewer may\n * read the source revision. Whatever it finds, the document itself reads\n * as the revision embedding it does.\n * @returns The source, or null for the root, for a document whose source is\n * unknown, and for a source the viewer may not read, which are not\n * told apart.\n */\nasync function sourceOf(\n ctx: UserContext,\n node: InterpretedNode,\n): Promise<Source | null> {\n const revisionId = nodeRevisions.get(node);\n if (revisionId == null || node.path.length === 0) return null;\n return (\n (await sourcesOf(ctx, revisionId)).get(JSON.stringify(node.path)) ?? null\n );\n}\n\nconst occurrenceFields = {\n representation: {\n description:\n \"Whether the value is an IRI, an embedded document or a `Link`.\",\n },\n iri:\n \"A reference's IRI, an embedded document's `id`, or a `Link`'s `href`, \" +\n \"with a compact IRI expanded; null for an anonymous embedded value.\",\n node:\n \"The embedded document or `Link` as the saved document embeds it, \" +\n \"which may differ from the resource's current revision; null for a \" +\n \"reference.\",\n resource:\n \"The resource currently registered under `iri`, or null when there is \" +\n \"none, or when the viewer may read neither it nor any of its \" +\n \"revisions. A deleted resource is returned too, since its revisions \" +\n \"stay readable. It is never fetched.\",\n} as const;\n\nDocumentRelation.implement({\n description:\n \"One value of a relation property, in source order including duplicates.\",\n fields: (t) => ({\n property: t.expose(\"property\", { type: RelationProperty }),\n path: t.expose(\"path\", {\n type: \"JSON\",\n description:\n \"The source path of the value from the root of the saved document, \" +\n 'such as `[\"object\", 0]`.',\n }),\n representation: t.expose(\"representation\", {\n type: RelationRepresentation,\n ...occurrenceFields.representation,\n }),\n iri: t.expose(\"iri\", {\n type: \"URL\",\n nullable: true,\n description: occurrenceFields.iri,\n }),\n node: t.expose(\"node\", {\n type: DocumentNode,\n nullable: true,\n description: occurrenceFields.node,\n }),\n resource: t.field({\n type: Resource,\n nullable: true,\n description: occurrenceFields.resource,\n resolve: (occurrence, _, ctx) => registeredResource(ctx, occurrence.iri),\n }),\n }),\n});\n\nDocumentRecipient.implement({\n description:\n \"One value of an addressing property, in source order including \" +\n \"duplicates and anonymous embedded recipients.\",\n fields: (t) => ({\n property: t.expose(\"property\", { type: AddressingProperty }),\n position: t.exposeInt(\"position\", {\n description:\n \"The index of the value in its property's list, or 0 for a value \" +\n \"written alone.\",\n }),\n path: t.expose(\"path\", {\n type: \"JSON\",\n description:\n \"The source path of the value from the root of the saved document.\",\n }),\n representation: t.expose(\"representation\", {\n type: RelationRepresentation,\n ...occurrenceFields.representation,\n }),\n iri: t.expose(\"iri\", {\n type: \"URL\",\n nullable: true,\n description: occurrenceFields.iri,\n }),\n node: t.expose(\"node\", {\n type: DocumentNode,\n nullable: true,\n description: occurrenceFields.node,\n }),\n resource: t.field({\n type: Resource,\n nullable: true,\n description: occurrenceFields.resource,\n resolve: (occurrence, _, ctx) => registeredResource(ctx, occurrence.iri),\n }),\n }),\n});\n\nconst PollChoiceMode = builder.enumType(\"PollChoiceMode\", {\n description: \"How a Question's choices may be answered.\",\n values: {\n exclusive: { description: \"A single-choice poll, from `oneOf`.\" },\n inclusive: { description: \"A multiple-choice poll, from `anyOf`.\" },\n } satisfies Record<NonNullable<InterpretedPoll[\"mode\"]>, object>,\n});\n\nDocumentPollChoice.implement({\n description: \"One of a Question's choices as saved in this revision.\",\n fields: (t) => ({\n path: t.expose(\"path\", {\n type: \"JSON\",\n description: \"The choice's source path from the root of the revision.\",\n }),\n iri: t.expose(\"iri\", {\n type: \"URL\",\n nullable: true,\n description:\n \"The choice's IRI, or null for an anonymous embedded choice.\",\n }),\n node: t.expose(\"node\", {\n type: DocumentNode,\n nullable: true,\n description: \"The choice's saved document, or null for an IRI reference.\",\n }),\n }),\n});\n\nconst DocumentPoll = builder.objectRef<InterpretedPoll>(\"DocumentPoll\");\nDocumentPoll.implement({\n description: \"The poll fields of a saved Question.\",\n fields: (t) => ({\n mode: t.expose(\"mode\", {\n type: PollChoiceMode,\n nullable: true,\n description: \"The choice mode, or null for a Question without choices.\",\n }),\n choices: t.expose(\"choices\", {\n type: [DocumentPollChoice],\n description:\n \"Choices sorted by source key, then by list position, including duplicates.\",\n }),\n closed: t.boolean({\n nullable: true,\n description: \"The saved boolean closing value, or null if there is none.\",\n resolve: ({ closed }) => (typeof closed === \"boolean\" ? closed : null),\n }),\n closedTime: t.field({\n type: \"DateTime\",\n nullable: true,\n description: \"The saved closing instant, or null if there is none.\",\n resolve: ({ closed }) =>\n typeof closed === \"string\" ? Temporal.Instant.from(closed) : null,\n }),\n }),\n});\n\nDocumentNode.implement({\n description:\n \"A vocabulary document of a saved revision, the root or one embedded in \" +\n \"it at any depth, read by meaning, whatever keys spell its properties. \" +\n \"It may be anonymous.\",\n fields: (t) => ({\n path: t.expose(\"path\", {\n type: \"JSON\",\n description:\n 'The source path from the root, such as `[\"object\", 0]`; `[]` is ' +\n \"the root.\",\n }),\n property: t.exposeString(\"property\", {\n nullable: true,\n description:\n \"The standard name of the property that embeds it, whatever its \" +\n \"source spelling; null for the root.\",\n }),\n type: t.expose(\"type\", {\n type: \"URL\",\n description: \"The type IRI, such as `…/activitystreams#Note`.\",\n }),\n kind: t.expose(\"kind\", { type: DocumentNodeKindEnum }),\n iri: t.expose(\"iri\", {\n type: \"URL\",\n nullable: true,\n description:\n \"Its `id`, or the `href` of a `Link`, with a compact IRI expanded; \" +\n \"null when it has none.\",\n }),\n document: t.expose(\"value\", {\n type: \"JSON\",\n description: \"Its JSON as saved, with everything it embeds.\",\n }),\n poll: t.expose(\"poll\", {\n type: DocumentPoll,\n nullable: true,\n description:\n \"The saved poll fields, or null for a type other than Question.\",\n }),\n relations: t.field({\n type: [DocumentRelation],\n args: { property: t.arg({ type: RelationProperty }) },\n description:\n \"Its own `actor`, `object`, `target`, `origin`, `result`, \" +\n \"`instrument` and `attributedTo` values, or those of one property, \" +\n \"in that order, then in source order including duplicates. Empty \" +\n \"for a property it does not have.\",\n resolve: (node, { property }) =>\n property == null\n ? node.relations\n : node.relations.filter((entry) => entry.property === property),\n }),\n addressing: t.field({\n type: [DocumentRecipient],\n args: { property: t.arg({ type: AddressingProperty }) },\n description:\n \"Its own `to`, `cc`, `bto`, `bcc` and `audience` values, or those \" +\n \"of one property, in that order, then in source order including \" +\n \"duplicates.\",\n resolve: (node, { property }) =>\n property == null\n ? node.addressing\n : node.addressing.filter((entry) => entry.property === property),\n }),\n extensions: t.expose(\"extensions\", {\n type: [DocumentExtension],\n description:\n \"Its own custom extension properties, by their source keys, sorted.\",\n }),\n source: t.field({\n type: DocumentSource,\n nullable: true,\n description:\n \"The revision this embedded document came from, as recorded when \" +\n \"the document embedding it was saved. Null for the root, for an \" +\n \"embedded document whose source is unknown, such as one saved \" +\n \"before sources were recorded or pasted without one, and when the \" +\n \"viewer may not read the source revision, which are not told \" +\n \"apart. It hides nothing else: the document reads as the revision \" +\n \"embedding it does, whatever its source.\",\n resolve: (node, _, ctx) => sourceOf(ctx, node),\n }),\n }),\n});\n\nDocumentSource.implement({\n description:\n \"The revision an embedded document came from, which the viewer may \" +\n \"read.\",\n fields: (t) => ({\n relation: t.expose(\"relation\", { type: DocumentSourceRelation }),\n revision: t.field({\n type: ResourceRevisionRef,\n description: \"The source revision, of the resource the document names.\",\n resolve: (source) => source.revision,\n }),\n status: t.field({\n type: DocumentSourceStatus,\n nullable: true,\n description:\n \"Whether the source revision is still current, or a later revision \" +\n \"or a deletion followed it; null when the viewer may not read the \" +\n \"resource's current revision.\",\n resolve: (source) => source.status,\n }),\n }),\n});\n\ntype Content = Pick<ResourceRevisionRow, \"id\" | \"kind\" | \"document\">;\n\nconst interpretations = new WeakMap<Content, InterpretedNode | null>();\nconst validations = new WeakMap<Content, readonly Diagnostic[]>();\n\n/**\n * Interprets a revision's document once per loaded row.\n * @returns The root, or null unless the revision is a snapshot whose\n * document the validator reads without errors.\n */\nfunction rootOf(revision: Content): InterpretedNode | null {\n if (!interpretations.has(revision)) {\n const nodes =\n revision.kind === \"snapshot\"\n ? interpretDocument(revision.document)\n : null;\n for (const node of nodes ?? []) nodeRevisions.set(node, revision.id);\n interpretations.set(revision, nodes?.[0] ?? null);\n }\n return interpretations.get(revision)!;\n}\n\nfunction diagnosticsOf(revision: Content): readonly Diagnostic[] {\n let diagnostics = validations.get(revision);\n if (diagnostics == null) {\n diagnostics =\n revision.kind === \"snapshot\"\n ? validateDocument(revision.document).diagnostics\n : [];\n validations.set(revision, diagnostics);\n }\n return diagnostics;\n}\n\nconst content = { columns: { id: true, kind: true, document: true } } as const;\n\nconst ResourceRevisionRef = builder.drizzleNode(\"resourceRevisions\", {\n name: \"ResourceRevision\",\n description:\n \"An immutable revision of a resource. Each revision, past ones \" +\n \"included, is readable by evidence of its own, not by the current \" +\n \"state of its resource: one saved by DrFed for a local actor by anyone, \" +\n \"blind recipients and unpublished activities included; one addressed \" +\n \"to the public by anyone; one a receipt links to a delivery to a local \" +\n \"instance the viewer is a member of by its members; and the current \" +\n \"revision of a resource with a legacy typed row as `Activity` and \" +\n \"`Object` tell. Where its embedded documents came from never hides \" +\n \"it. Administrators read every revision. A later \" +\n \"restriction or deletion of the resource hides no earlier revision. A \" +\n \"revision the viewer may not read is left out as if it did not exist.\",\n // A node lookup checks the revision by its own ID.\n select: { columns: { id: true, resourceId: true } },\n id: { column: (revision) => revision.id },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n sequence: t.exposeInt(\"sequence\", {\n description: \"Increases with each revision of the resource.\",\n }),\n kind: t.expose(\"kind\", { type: ResourceRevisionKind }),\n capture: t.expose(\"capture\", { type: ResourceRevisionCapture }),\n backfilled: t.exposeBoolean(\"backfilled\", {\n description: \"Whether the migration from legacy typed rows created it.\",\n }),\n created: t.expose(\"created\", {\n type: \"DateTime\",\n description: \"When DrFed stored the revision.\",\n }),\n document: t.expose(\"document\", {\n type: \"JSON\",\n nullable: true,\n description:\n \"The saved JSON as is, `bto` and `bcc` included for local \" +\n \"resources. Read `root` instead of parsing it by keys, which \" +\n \"aliases and contexts may spell otherwise. Null unless `kind` is \" +\n \"`snapshot`, or for a snapshot of JSON null.\",\n }),\n interpreted: t.boolean({\n description:\n \"Whether `root` could be derived from `document`. When false, \" +\n \"`root` is null and, for a snapshot, `diagnostics` explain why.\",\n select: content,\n resolve: (revision) => rootOf(revision) != null,\n }),\n root: t.field({\n type: DocumentNode,\n nullable: true,\n description:\n \"The root document read by meaning; null unless `interpreted`.\",\n select: content,\n resolve: (revision) => rootOf(revision),\n }),\n diagnostics: t.field({\n type: [DocumentDiagnostic],\n description:\n \"What the current validator finds in the saved document, which may \" +\n \"differ from what it found when the revision was stored. Empty \" +\n \"unless `kind` is `snapshot`.\",\n select: content,\n resolve: (revision) => diagnosticsOf(revision),\n }),\n deleted: t.expose(\"deleted\", {\n type: \"DateTime\",\n nullable: true,\n description: \"The deletion time of a whiteout; null otherwise.\",\n }),\n formerTypes: t.field({\n type: [\"URL\"],\n nullable: true,\n description:\n \"The type IRIs the resource had, for a whiteout; null otherwise. \" +\n 'Stored ActivityStreams names, such as `\"Note\"`, are expanded with ' +\n \"`https://www.w3.org/ns/activitystreams#`.\",\n select: { columns: { formerTypes: true } },\n resolve: (revision) =>\n revision.formerTypes?.map((type) =>\n type.includes(\":\") ? type : `${ACTIVITY_STREAMS}${type}`,\n ) ?? null,\n }),\n }),\n});\nexport const ResourceRevision: DrFedObjectRef = ResourceRevisionRef;\n\nbuilder.drizzleObjectField(\"resources\", \"currentRevision\", (t) =>\n t.field({\n type: ResourceRevisionRef,\n nullable: true,\n description:\n \"The current revision; null for a resource without revisions, or when \" +\n \"the viewer may not read the current revision.\",\n select: { columns: { id: true } },\n resolve: async (resource, _, ctx) =>\n (await ctx.db.query.resourceRevisions.findFirst({\n where: {\n RAW: (table) =>\n and(\n inArray(\n table.id,\n ctx.db\n .select({ id: schema.resourceHeads.revisionId })\n .from(schema.resourceHeads)\n .where(eq(schema.resourceHeads.resourceId, resource.id)),\n ),\n readableRevision(ctx, table.id),\n )!,\n },\n })) ?? null,\n }),\n);\n\nbuilder.drizzleObjectField(\"resources\", \"revision\", (t) =>\n t.field({\n type: ResourceRevisionRef,\n nullable: true,\n args: { sequence: t.arg.int({ required: true }) },\n description:\n \"The revision with the given sequence; null when there is none, or \" +\n \"when the viewer may not read it, which are not told apart.\",\n select: { columns: { id: true } },\n resolve: async (resource, { sequence }, ctx) =>\n (await ctx.db.query.resourceRevisions.findFirst({\n where: {\n resourceId: resource.id,\n sequence,\n RAW: (table) => readableRevision(ctx, table.id),\n },\n })) ?? null,\n }),\n);\n\nbuilder.drizzleObjectField(\"resources\", \"revisions\", (t) =>\n t.relatedConnection(\n \"revisions\",\n {\n description:\n \"The revisions the viewer may read, newest first. Others are left \" +\n \"out, so sequences may skip.\",\n query: (_, ctx) => ({\n where: { RAW: (table) => readableRevision(ctx, table.id) },\n orderBy: { sequence: \"desc\" },\n }),\n },\n { name: \"ResourceRevisionConnection\" },\n { name: \"ResourceRevisionEdge\" },\n ),\n);\n","// 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 builder, { type DrFedObjectRef } from \"./builder.ts\";\n\nconst KeyRef = builder.drizzleNode(\"keys\", {\n name: \"Key\",\n description:\n \"A remote public key, identified by its IRI. Readable by any \" +\n \"authenticated viewer, since it holds public material only.\",\n authScopes: { authenticated: true },\n runScopesOnType: true,\n id: { column: (key) => key.id },\n fields: (t) => ({\n uuid: t.expose(\"id\", { type: \"UUID\" }),\n iri: t.expose(\"iri\", { type: \"URL\" }),\n created: t.expose(\"created\", { type: \"DateTime\" }),\n versions: t.relatedConnection(\"versions\", {\n description: \"The observed versions of the key, oldest first.\",\n query: { orderBy: { firstSeen: \"asc\", id: \"asc\" } },\n }),\n }),\n});\nexport const Key: DrFedObjectRef = KeyRef;\nconst observationDescription =\n \"DrFed observation time, not the remote key rotation time; \" +\n \"does not imply continuous use between observations.\";\nconst KeyVersionRef = builder.drizzleNode(\"keyVersions\", {\n name: \"KeyVersion\",\n description:\n \"Immutable public key material observed under a `Key`. Readable by \" +\n \"any authenticated viewer.\",\n authScopes: { authenticated: true },\n runScopesOnType: true,\n id: { column: (version) => version.id },\n fields: (t) => ({\n uuid: t.expose(\"id\", { type: \"UUID\" }),\n key: t.relation(\"key\"),\n publicKey: t.expose(\"publicKey\", { type: \"JSON\" }),\n fingerprint: t.exposeString(\"fingerprint\"),\n firstSeen: t.expose(\"firstSeen\", {\n type: \"DateTime\",\n description: `First ${observationDescription}`,\n }),\n lastSeen: t.expose(\"lastSeen\", {\n type: \"DateTime\",\n description: `Last ${observationDescription}`,\n }),\n }),\n});\nexport const KeyVersion: DrFedObjectRef = KeyVersionRef;\n","// 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// oxlint-disable import/no-unassigned-import\nimport \"./account.ts\";\nimport \"./instance.ts\";\nimport \"./auth/entry.ts\";\nimport \"./actor.ts\";\nimport \"./object.ts\";\nimport \"./revision.ts\";\nimport \"./activity-delivery/entry.ts\";\nimport \"./key.ts\";\nimport builder from \"./builder.ts\";\n\nbuilder.queryType({});\nbuilder.mutationType({});\n\nexport const schema = builder.toSchema();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAa,aAAa,OAAO,QAC/B,IAAI,WACF,MAAM,OAAO,OAAO,OAAO,WAAW,YAAY,OAAO,GAAG,CAAC,CAC/D,CAAC,CAAC,MAAM;AAEV,MAAM,cAAc,IAAI,YAAY;AAEpC,MAAM,qBAAqB;AAE3B,MAAa,4BACX,OAAO,gBAAgB,IAAI,WAAW,kBAAkB,CAAC,CAAC,CAAC,SAAS;CAClE,UAAU;CACV,aAAa;AACf,CAAC;;;ACJH,SAAwB,gBAAgB,EACtC,UACA,aACA,MACA,gBACgC;CAChC,eAAe,UAAU,aAAa;CACtC,eAAe,UAAU,MAAM;CAE/B,IAAI;CACJ,IAAI;EACF,MAAM,IAAI,IAAI,SAAS,OAAO;GAAE;GAAa;EAAK,CAAC,CAAC;CACtD,QAAQ;EACN,MAAM,iBACJ,qDACF;CACF;CAEA,IAAI,IAAI,aAAa,YAAY,IAAI,aAAa,SAChD,MAAM,iBAAiB,oCAAoC;CAE7D,IAAI,CAAC,aAAa,IAAI,IAAI,MAAM,GAC9B,MAAM,iBAAiB,qCAAqC,IAAI,OAAO,EAAE;CAE3E,OAAO,IAAI;AACb;AAEA,SAAS,eAAe,UAAoB,MAAoB;CAQ9D,IAAI,CAPU,SAAS,OAAO,MAC3B,UACC,MAAM,SAAS,gBACf,MAAM,KAAK,MACR,aAAa,SAAS,SAAS,QAAQ,SAAS,UAAU,IAC7D,CAEK,GACP,MAAM,iBAAiB,qCAAqC,KAAK,GAAG;AAExE;AAEA,MAAM,oBAAoB,YACxB,IAAI,aAAa,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,EAAE,CAAC;;;;AC7CtE,eAAsB,SACpB,IACA,UACA,KACe;CACf,MAAM,SAAS,IAAI,mBAAmB,IAAI,QAAQ;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AI;GAAM,EAAE;EACpD,CAAC;CACH;AACF,CAAC;AAED,MAAM,yBACJ;AAEoB,QAAQ,YAAY,eAAe;CACvD,MAAM;CACN,aACE;CAEF,YAAY,EAAE,eAAe,KAAK;CAClC,iBAAiB;CACjB,IAAI,EAAE,SAAS,YAAY,QAAQ,GAAG;CACtC,SAAS,OAAO;EACd,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,OAAO,CAAC;EACrC,KAAK,EAAE,SAAS,KAAK;EACrB,WAAW,EAAE,OAAO,aAAa,EAAE,MAAM,OAAO,CAAC;EACjD,aAAa,EAAE,aAAa,aAAa;EACzC,WAAW,EAAE,OAAO,aAAa;GAC/B,MAAM;GACN,aAAa,SAAS;EACxB,CAAC;EACD,UAAU,EAAE,OAAO,YAAY;GAC7B,MAAM;GACN,aAAa,QAAQ;EACvB,CAAC;CACH;AACF,CAAC;;;ACpCD,QAAQ,UAAU,CAAC,CAAC;AACpB,QAAQ,aAAa,CAAC,CAAC;AAEvB,MAAaE,WAAS,QAAQ,SAAS"}
|
package/dist/schema.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schema } from "./schema-
|
|
1
|
+
export { t as schema } from "./schema-DRjGCIYI.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drfed/graphql",
|
|
3
|
-
"version": "0.2.0-dev.
|
|
3
|
+
"version": "0.2.0-dev.717",
|
|
4
4
|
"description": "A GraphQL server for DrFed.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ActivityPub",
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
"typescript": "^7.0.2"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@drfed/federation": "0.2.0-dev.
|
|
118
|
-
"@drfed/models": "0.2.0-dev.
|
|
117
|
+
"@drfed/federation": "0.2.0-dev.717",
|
|
118
|
+
"@drfed/models": "0.2.0-dev.717",
|
|
119
119
|
"@faker-js/faker": "^10.5.0",
|
|
120
120
|
"@fedify/uri-template": "^2.3.1",
|
|
121
121
|
"@fedify/fedify": "2.4.3",
|
|
@@ -145,13 +145,13 @@
|
|
|
145
145
|
},
|
|
146
146
|
"drfedBuild": {
|
|
147
147
|
"enabled": true,
|
|
148
|
-
"version": "0.2.0-dev.
|
|
149
|
-
"fullVersion": "0.2.0-dev.
|
|
148
|
+
"version": "0.2.0-dev.717",
|
|
149
|
+
"fullVersion": "0.2.0-dev.717+8cdaaac8",
|
|
150
150
|
"baseVersion": "0.2.0",
|
|
151
151
|
"channel": "dev",
|
|
152
|
-
"sha": "
|
|
153
|
-
"runNumber": "
|
|
154
|
-
"runId": "
|
|
152
|
+
"sha": "8cdaaac8aa197260cb2d68ced23f17109cbb258e",
|
|
153
|
+
"runNumber": "717",
|
|
154
|
+
"runId": "45350451649",
|
|
155
155
|
"ref": "refs/heads/main",
|
|
156
156
|
"workflow": ".github/workflows/main.yaml"
|
|
157
157
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-eJO_-DWq.mjs","names":["eq","and","schema"],"sources":["../src/auth/hash.ts","../src/auth/expand.ts","../src/auth/mail.ts","../src/auth/magic-link.ts","../src/auth/challenge.ts","../src/auth/revoke.ts","../src/auth/entry.ts","../src/revision.ts","../src/key.ts","../src/schema.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// oxlint-disable func-names func-style id-length\n\nexport const hashSecret = async (raw: string): Promise<string> =>\n new Uint8Array(\n await crypto.subtle.digest(\"SHA-256\", textEncoder.encode(raw)),\n ).toHex();\n\nconst textEncoder = new TextEncoder();\n\nconst ACCESS_TOKEN_BYTES = 32;\n\nexport const generateAccessToken = (): string =>\n crypto.getRandomValues(new Uint8Array(ACCESS_TOKEN_BYTES)).toBase64({\n alphabet: \"base64url\",\n omitPadding: true,\n });\n","// 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 { Template } from \"@fedify/uri-template\";\nimport { GraphQLError } from \"graphql\";\n\nexport interface ExpandVerifyUrlParams {\n template: Template;\n challengeId: `${string}-${string}-${string}-${string}-${string}`;\n code: string;\n loginOrigins: ReadonlySet<string>;\n}\n\nexport default function expandVerifyUrl({\n template,\n challengeId,\n code,\n loginOrigins,\n}: ExpandVerifyUrlParams): string {\n assertVariable(template, \"challengeId\");\n assertVariable(template, \"code\");\n\n let url: URL;\n try {\n url = new URL(template.expand({ challengeId, code }));\n } catch {\n throw invalidVerifyUrl(\n \"Verify URL template must expand to an absolute URL.\",\n );\n }\n\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n throw invalidVerifyUrl(\"Verify URL must use HTTP or HTTPS.\");\n }\n if (!loginOrigins.has(url.origin)) {\n throw invalidVerifyUrl(`Verify URL origin is not allowed: ${url.origin}.`);\n }\n return url.href;\n}\n\nfunction assertVariable(template: Template, name: string): void {\n const found = template.tokens.some(\n (token) =>\n token.kind === \"expression\" &&\n token.vars.some(\n (variable) => variable.name === name && variable.prefix == null,\n ),\n );\n if (!found) {\n throw invalidVerifyUrl(`Verify URL template must include {${name}}.`);\n }\n}\n\nconst invalidVerifyUrl = (message: string) =>\n new GraphQLError(message, { extensions: { code: \"BAD_USER_INPUT\" } });\n","// 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 { getLogger } from \"@logtape/logtape\";\nimport { type MessageContent, type Receipt, createMessage } from \"@upyo/core\";\n\nimport type { UserContext } from \"../builder.ts\";\n\n/** Send login mail without exposing non-cancellation provider failures. */\nexport async function sendMail(\n to: string,\n loginUrl: string,\n ctx: UserContext,\n): Promise<void> {\n const signal = ctx.operationSignal ?? ctx.request.signal;\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n try {\n const receipt = await ctx.mailer.send(\n createMessage({\n from: ctx.emailFrom,\n to,\n // FIXME: https://github.com/fedify-dev/drfed/issues/35\n subject: \"Sign in to DrFed\",\n content: renderLoginEmail(loginUrl),\n }),\n { signal },\n );\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n logReceipt(receipt);\n } catch {\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n logger.warn(\"Login mail delivery failed.\", { outcome: \"exception\" });\n }\n}\n\nconst renderLoginEmail = (loginUrl: string): MessageContent => ({\n // FIXME: https://github.com/fedify-dev/drfed/issues/35\n // oxlint-disable no-inline-comments\n text: `Hello, Welcome to DrFed! If you request to login to DrFed, please visit:\n\nopen ${loginUrl}${/* Split between the link and the last `\\n` */ \" \"}\n\nOtherwise, please just ignore this mail.`,\n});\n// oxlint-enable no-inline-comments\n\nexport function logReceipt(receipt: Receipt<string>): void {\n if (receipt.successful) {\n logger.debug(\"Login mail delivery succeeded.\", { outcome: \"sent\" });\n return;\n }\n logger.warn(\"Login mail delivery failed.\", { outcome: \"failed\" });\n}\n\nconst logger = getLogger([\"drfed\", \"graphql\", \"auth\"]);\n","// 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\n// oxlint-disable no-magic-numbers\n\nimport { schema } from \"@drfed/models\";\nimport { generateLoginChallengeCode } from \"@drfed/models/login\";\nimport { type Uuid, uuidV7 } from \"@drfed/models/uuid\";\n\nimport builder, { type UserContext } from \"../builder.ts\";\nimport expandVerifyUrl from \"./expand.ts\";\nimport { sendMail } from \"./mail.ts\";\n\ninterface LoginChallengeShape {\n readonly challengeId: Uuid;\n}\n\nconst LoginChallengeRef = builder\n .objectRef<LoginChallengeShape>(\"LoginChallenge\")\n .implement({\n description: \"An email login challenge.\",\n fields: (t) => ({\n challengeId: t.expose(\"challengeId\", {\n type: \"UUID\",\n description: \"The public identifier of the login challenge.\",\n }),\n }),\n });\n\nbuilder.mutationFields((t) => ({\n loginByEmail: t.field({\n type: LoginChallengeRef,\n description:\n \"Send a magic link without revealing whether the account exists.\",\n args: {\n email: t.arg({\n type: \"Email\",\n required: true,\n description: \"The email address of the `Account`.\",\n }),\n verifyUrl: t.arg({\n type: \"URITemplate\",\n required: true,\n description:\n \"Use {challengeId} and {code} variables. \" +\n \"The URL's origin must be in the server's login allowlist.\",\n }),\n },\n async resolve(_root, { email, verifyUrl }, ctx) {\n const challengeId = uuidV7();\n const code = generateLoginChallengeCode();\n const loginUrl = expandVerifyUrl({\n challengeId,\n code,\n loginOrigins: ctx.loginOrigins,\n template: verifyUrl,\n });\n const account = await findAccount(email, ctx);\n if (account == null) {\n // Return an ID even for an unknown account to prevent account\n // enumeration. Consider mailing in a worker to prevent timing attacks.\n return { challengeId };\n }\n const verifier = {\n challengeId,\n code,\n };\n\n await insertChallenge(account.id, verifier, ctx);\n // Do not check the email was sent. Instructs users to request a resend if\n // the email does not arrive after a few minutes at the web page.\n await sendMail(account.email, loginUrl, ctx);\n\n return { challengeId };\n },\n }),\n}));\n\nconst findAccount = async (email: string, ctx: UserContext) =>\n await ctx.db.query.accounts.findFirst({\n where: { email },\n });\n\nconst insertChallenge = async (\n accountId: Uuid,\n { challengeId, code }: { challengeId: Uuid; code: string },\n ctx: UserContext,\n) =>\n await ctx.db.insert(schema.loginChallenges).values({\n id: challengeId,\n accountId,\n code,\n });\n","// 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\n// oxlint-disable no-magic-numbers\n\nimport { Buffer } from \"node:buffer\";\nimport { timingSafeEqual } from \"node:crypto\";\n\nimport type { Database } from \"@drfed/models\";\nimport {\n LoginChallengeError,\n consumeLoginChallenge,\n findLoginChallenge,\n} from \"@drfed/models/login\";\nimport { sessions } from \"@drfed/models/schema\";\nimport type { Uuid } from \"@drfed/models/uuid\";\n\nimport builder from \"../builder.ts\";\nimport { generateAccessToken, hashSecret } from \"./hash.ts\";\n\nconst SessionRef = builder.drizzleObject(\"sessions\", {\n name: \"Session\",\n fields: (t) => ({\n id: t.expose(\"id\", { type: \"UUID\" }),\n accessToken: t.string({\n nullable: true,\n resolve(session) {\n const accessToken =\n \"accessToken\" in session ? session.accessToken : null;\n return typeof accessToken === \"string\" ? accessToken : null;\n },\n }),\n // The only `Session` a client can obtain is the one `completeLoginChallenge`\n // just created for it, and `Session` is not a `Node`, so the account behind\n // a session is always the viewer's own. Granting `ownAccount` here lets\n // the login response carry the viewer's private fields even though the\n // request that produced it had no session yet.\n account: t.relation(\"account\", { grantScopes: [\"ownAccount\"] }),\n created: t.expose(\"created\", { type: \"DateTime\" }),\n expires: t.expose(\"expires\", { type: \"DateTime\" }),\n }),\n});\n\nbuilder.mutationFields((t) => ({\n completeLoginChallenge: t.drizzleField({\n type: SessionRef,\n nullable: true,\n description: \"Complete login challenge.\",\n args: {\n challengeId: t.arg({ type: \"UUID\", required: true }),\n code: t.arg({ type: \"String\", required: true }),\n },\n async resolve(query, _root, { challengeId, code }, ctx) {\n try {\n const now = Temporal.Now.instant();\n const row = await findLoginChallenge(ctx.db, challengeId, now);\n const id = crypto.randomUUID();\n const accessToken = generateAccessToken();\n const accessHash = await hashSecret(accessToken);\n\n const providedCode = Buffer.from(code.toLowerCase());\n const expectedCode = Buffer.from(row.code);\n if (\n providedCode.length !== expectedCode.length ||\n !timingSafeEqual(providedCode, expectedCode)\n ) {\n throw new LoginChallengeError(\"The provided code does not match.\");\n }\n await ctx.db.transaction(async (tx) => {\n await consumeLoginChallenge(tx, row.id, now);\n await insertSession(id, row.accountId, accessHash, tx);\n });\n\n const session = await ctx.db.query.sessions.findFirst(\n query({ where: { id } }),\n );\n return session == null ? null : { ...session, accessToken };\n } catch (error) {\n if (error instanceof LoginChallengeError) {\n return null;\n }\n throw error;\n }\n },\n }),\n}));\n\nconst insertSession = async (\n id: Uuid,\n accountId: Uuid,\n tokenHash: string,\n tx: Database,\n) => await tx.insert(sessions).values({ id, accountId, tokenHash });\n","// 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\n// oxlint-disable no-magic-numbers\n\nimport { sessions } from \"@drfed/models/schema\";\nimport { eq } from \"drizzle-orm/sql/expressions\";\n\nimport builder, { type UserContext } from \"../builder.ts\";\n\nbuilder.mutationFields((t) => ({\n revokeSession: t.field({\n type: LogoutSuccessRef,\n description: \"Revokes a session. Return always `revoke: true`.\",\n authScopes: {\n authenticated: true,\n },\n async resolve(_query, _, ctx) {\n const sessionId = ctx.session?.id;\n if (sessionId) {\n await deleteSession(ctx);\n }\n // Return always true to prevent brute-force attack.\n return { revoke: true };\n },\n }),\n}));\n\ninterface LogoutSuccessShape {\n revoke: boolean;\n}\n\nconst LogoutSuccessRef = builder\n .objectRef<LogoutSuccessShape>(\"LogoutSuccess\")\n .implement({\n description: \"The session revoked.\",\n fields: (t) => ({\n revoke: t.expose(\"revoke\", {\n type: \"Boolean\",\n description: \"Revoking status.\",\n }),\n }),\n });\n\nconst deleteSession = (ctx: UserContext) =>\n ctx.db.delete(sessions).where(eq(sessions.id, ctx.session!.id));\n","// 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\n// oxlint-disable import/no-unassigned-import\nimport \"./magic-link.ts\";\nimport \"./challenge.ts\";\nimport \"./revoke.ts\";\nimport builder from \"../builder.ts\";\n\nbuilder.queryFields((t) => ({\n viewer: t.drizzleField({\n type: \"accounts\",\n nullable: true,\n description: \"`Account` if authorized, else `null`\",\n resolve: (query, _root, _args, ctx) =>\n ctx.session == null\n ? null\n : ctx.db.query.accounts.findFirst(\n query({ where: { id: ctx.session.accountId } }),\n ),\n }),\n}));\n","// 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 type InterpretedNode,\n RELATION_PROPERTIES,\n type RecipientOccurrence,\n type RelationOccurrence,\n interpretDocument,\n} from \"@drfed/federation/document\";\nimport { schema } from \"@drfed/models\";\nimport {\n type Diagnostic,\n type DiagnosticCategory,\n type DiagnosticSeverity,\n type DocumentNodeKind,\n validateDocument,\n} from \"@drfed/models/document\";\nimport type {\n ResourceRevision as ResourceRevisionRow,\n Resource as ResourceRow,\n RevisionEmbedding,\n} from \"@drfed/models/schema\";\nimport type { Uuid } from \"@drfed/models/uuid\";\nimport { and, eq, inArray } from \"drizzle-orm\";\n\nimport builder, { type DrFedObjectRef, type UserContext } from \"./builder.ts\";\nimport { readableResourceNode, readableRevision } from \"./readable.ts\";\nimport { Resource } from \"./resource.ts\";\n\nconst ACTIVITY_STREAMS = \"https://www.w3.org/ns/activitystreams#\";\n\nconst ResourceRevisionKind = builder.enumType(\"ResourceRevisionKind\", {\n description: \"What a revision records.\",\n values: {\n snapshot: { description: \"A saved document.\" },\n unavailable: {\n description:\n \"A legacy typed row that had no retained document; nothing replaces it.\",\n },\n whiteout: {\n description:\n \"A deletion: its time and the types the resource had, but no document.\",\n },\n } satisfies Record<ResourceRevisionRow[\"kind\"], object>,\n});\nconst ResourceRevisionCapture = builder.enumType(\"ResourceRevisionCapture\", {\n description:\n \"How DrFed came to store a revision. Neither proves ownership nor \" +\n \"grants access.\",\n values: {\n local: { description: \"Saved by DrFed for a local actor.\" },\n received: { description: \"Received in an inbound activity.\" },\n embedded: { description: \"Embedded in another received document.\" },\n fetched: {\n description:\n \"Fetched apart from an activity. For legacy data, a conservative \" +\n \"flag that is no proof an HTTP fetch occurred.\",\n },\n } satisfies Record<ResourceRevisionRow[\"capture\"], object>,\n});\nconst DocumentNodeKindEnum = builder.enumType(\"DocumentNodeKind\", {\n description: \"The vocabulary category of a document's type.\",\n values: {\n activity: {},\n actor: {},\n collection: {},\n link: {},\n object: {},\n } satisfies Record<DocumentNodeKind, object>,\n});\nconst RelationProperty = builder.enumType(\"RelationProperty\", {\n description: \"A property that relates a document to another resource.\",\n values: RELATION_PROPERTIES,\n});\nconst AddressingProperty = builder.enumType(\"AddressingProperty\", {\n description: \"A property that addresses a document's recipients.\",\n values: schema.addressingPropertyEnum.enumValues,\n});\nconst RelationRepresentation = builder.enumType(\"RelationRepresentation\", {\n description: \"How a value names what it stands for.\",\n values: {\n reference: { description: \"An IRI.\" },\n embedded: { description: \"An embedded document.\" },\n link: { description: \"An embedded `Link`, which names it by `href`.\" },\n } satisfies Record<RelationOccurrence[\"representation\"], object>,\n});\nconst DiagnosticCategoryEnum = builder.enumType(\"DiagnosticCategory\", {\n values: {\n vocabulary: {\n description: \"The document breaks a vocabulary or JSON-LD rule.\",\n },\n authority: { description: \"The document claims what it may not.\" },\n support: { description: \"DrFed's validator cannot check it.\" },\n compatibility: {\n description: \"Valid, but other implementations may read it otherwise.\",\n },\n } satisfies Record<DiagnosticCategory, object>,\n});\nconst DiagnosticSeverityEnum = builder.enumType(\"DiagnosticSeverity\", {\n values: {\n error: {},\n warning: {},\n } satisfies Record<DiagnosticSeverity, object>,\n});\n\nconst DocumentExtension = builder.objectRef<{\n readonly key: string;\n readonly value: unknown;\n}>(\"DocumentExtension\");\nDocumentExtension.implement({\n description: \"A custom extension property, preserved as opaque JSON.\",\n fields: (t) => ({\n key: t.exposeString(\"key\", {\n description: \"The key in its source spelling.\",\n }),\n value: t.expose(\"value\", { type: \"JSON\", description: \"As saved.\" }),\n }),\n});\n\nconst DocumentDiagnostic = builder.objectRef<Diagnostic>(\"DocumentDiagnostic\");\nDocumentDiagnostic.implement({\n description: \"A finding of the document validator.\",\n fields: (t) => ({\n reason: t.exposeString(\"reason\", {\n description:\n \"A stable classification, such as `unsupported_property`. Use it \" +\n \"for decisions rather than `message`.\",\n }),\n category: t.expose(\"category\", { type: DiagnosticCategoryEnum }),\n severity: t.expose(\"severity\", { type: DiagnosticSeverityEnum }),\n path: t.expose(\"path\", {\n type: \"JSON\",\n description:\n \"The source keys and list indexes leading to the finding; `[]` is \" +\n \"the root.\",\n }),\n message: t.exposeString(\"message\", {\n description: \"For people; it may change.\",\n }),\n }),\n});\n\nconst DocumentSourceRelation = builder.enumType(\"DocumentSourceRelation\", {\n description:\n \"How an embedded document relates to the revision it came from, as \" +\n \"recorded when the document embedding it was saved.\",\n values: {\n snapshot: {\n description:\n \"It keeps the source revision's contents, apart from the context \" +\n \"it inherits from the document embedding it.\",\n },\n derived: {\n description:\n \"It started from the source revision and was changed, as a test \" +\n \"input with other addressing or an altered property.\",\n },\n } satisfies Record<RevisionEmbedding[\"relation\"], object>,\n});\nconst DocumentSourceStatus = builder.enumType(\"DocumentSourceStatus\", {\n description:\n \"Where the source revision stands in its resource's history. It \" +\n \"compares revisions, not contents.\",\n values: {\n current: { description: \"It is the resource's current revision.\" },\n superseded: {\n description:\n \"A later revision is current, which may have the same contents.\",\n },\n deleted: { description: \"The resource's current revision is a whiteout.\" },\n },\n});\n\ntype SourceStatus = \"current\" | \"superseded\" | \"deleted\";\n\n/** A recorded embedding whose source revision the viewer may read. */\ninterface Source {\n readonly relation: RevisionEmbedding[\"relation\"];\n readonly revision: ResourceRevisionRow;\n /** Null when the viewer may not read the resource's current revision. */\n readonly status: SourceStatus | null;\n}\nconst DocumentSource = builder.objectRef<Source>(\"DocumentSource\");\n\nconst DocumentNode = builder.objectRef<InterpretedNode>(\"DocumentNode\");\nconst DocumentRelation =\n builder.objectRef<RelationOccurrence>(\"DocumentRelation\");\nconst DocumentRecipient =\n builder.objectRef<RecipientOccurrence>(\"DocumentRecipient\");\n\nconst resourceLookups = new WeakMap<\n UserContext,\n Map<string, Promise<ResourceRow | null>>\n>();\n\n/**\n * Finds the resource registered under an IRI, as `Activity.object` opens\n * it: only when the viewer may read it or one of its revisions. A deleted\n * one is found too, since its revisions stay readable. Lookups are shared within a request, since\n * a document may name one IRI many times.\n * @returns The resource, or null.\n */\nfunction registeredResource(\n ctx: UserContext,\n iri: string | null,\n): Promise<ResourceRow | null> {\n if (iri == null) return Promise.resolve(null);\n let lookups = resourceLookups.get(ctx);\n if (lookups == null) {\n lookups = new Map();\n resourceLookups.set(ctx, lookups);\n }\n let lookup = lookups.get(iri);\n if (lookup == null) {\n lookup = (async () =>\n (await ctx.db.query.resources.findFirst({\n where: {\n iri,\n RAW: (table) => readableResourceNode(ctx, table.id),\n },\n })) ?? null)();\n lookups.set(iri, lookup);\n }\n return lookup;\n}\n\n// The revision each interpreted node belongs to.\nconst nodeRevisions = new WeakMap<InterpretedNode, Uuid>();\n\nconst sourceLookups = new WeakMap<\n UserContext,\n Map<Uuid, Promise<ReadonlyMap<string, Source>>>\n>();\n\n/**\n * Tells where a source revision stands against its resource's current\n * revision. An `unavailable` current revision, a legacy typed row without a\n * retained document, is a later revision like any other.\n * @param revision The source revision.\n * @param current The current revision of its resource, when the viewer may\n * read it.\n * @returns The status, or null without a readable current revision.\n */\nconst statusOf = (\n revision: ResourceRevisionRow,\n current: Pick<ResourceRevisionRow, \"id\" | \"kind\"> | undefined,\n): SourceStatus | null =>\n current == null\n ? null\n : current.id === revision.id\n ? \"current\"\n : current.kind === \"whiteout\"\n ? \"deleted\"\n : \"superseded\";\n\n/**\n * Loads the recorded sources of a revision's embedded documents that the\n * viewer may read, with where each stands, in two queries per revision\n * whatever the number of documents it embeds. Lookups are shared within a\n * request.\n * @returns The sources, keyed by the JSON of the embedded documents' paths.\n */\nfunction sourcesOf(\n ctx: UserContext,\n revisionId: Uuid,\n): Promise<ReadonlyMap<string, Source>> {\n let lookups = sourceLookups.get(ctx);\n if (lookups == null) {\n lookups = new Map();\n sourceLookups.set(ctx, lookups);\n }\n let lookup = lookups.get(revisionId);\n if (lookup == null) {\n lookup = (async () => {\n const embeddings = await ctx.db\n .select({\n path: schema.revisionEmbeddings.path,\n relation: schema.revisionEmbeddings.relation,\n revision: schema.resourceRevisions,\n })\n .from(schema.revisionEmbeddings)\n .innerJoin(\n schema.resourceRevisions,\n eq(\n schema.resourceRevisions.id,\n schema.revisionEmbeddings.sourceRevisionId,\n ),\n )\n .where(\n and(\n eq(schema.revisionEmbeddings.revisionId, revisionId),\n readableRevision(ctx, schema.resourceRevisions.id),\n ),\n );\n const resourceIds = [\n ...new Set(embeddings.map(({ revision }) => revision.resourceId)),\n ];\n const heads =\n resourceIds.length === 0\n ? []\n : await ctx.db\n .select({\n resourceId: schema.resourceHeads.resourceId,\n id: schema.resourceRevisions.id,\n kind: schema.resourceRevisions.kind,\n })\n .from(schema.resourceHeads)\n .innerJoin(\n schema.resourceRevisions,\n eq(\n schema.resourceRevisions.id,\n schema.resourceHeads.revisionId,\n ),\n )\n .where(\n and(\n inArray(schema.resourceHeads.resourceId, resourceIds),\n readableRevision(ctx, schema.resourceRevisions.id),\n ),\n );\n const current = new Map(\n heads.map((head) => [head.resourceId, head] as const),\n );\n return new Map(\n embeddings.map(({ path, relation, revision }) => [\n JSON.stringify(path),\n {\n relation,\n revision,\n status: statusOf(revision, current.get(revision.resourceId)),\n },\n ]),\n );\n })();\n lookups.set(revisionId, lookup);\n }\n return lookup;\n}\n\n/**\n * Finds the recorded source of an embedded document, when the viewer may\n * read the source revision. Whatever it finds, the document itself reads\n * as the revision embedding it does.\n * @returns The source, or null for the root, for a document whose source is\n * unknown, and for a source the viewer may not read, which are not\n * told apart.\n */\nasync function sourceOf(\n ctx: UserContext,\n node: InterpretedNode,\n): Promise<Source | null> {\n const revisionId = nodeRevisions.get(node);\n if (revisionId == null || node.path.length === 0) return null;\n return (\n (await sourcesOf(ctx, revisionId)).get(JSON.stringify(node.path)) ?? null\n );\n}\n\nconst occurrenceFields = {\n representation: {\n description:\n \"Whether the value is an IRI, an embedded document or a `Link`.\",\n },\n iri:\n \"A reference's IRI, an embedded document's `id`, or a `Link`'s `href`, \" +\n \"with a compact IRI expanded; null for an anonymous embedded value.\",\n node:\n \"The embedded document or `Link` as the saved document embeds it, \" +\n \"which may differ from the resource's current revision; null for a \" +\n \"reference.\",\n resource:\n \"The resource currently registered under `iri`, or null when there is \" +\n \"none, or when the viewer may read neither it nor any of its \" +\n \"revisions. A deleted resource is returned too, since its revisions \" +\n \"stay readable. It is never fetched.\",\n} as const;\n\nDocumentRelation.implement({\n description:\n \"One value of a relation property, in source order including duplicates.\",\n fields: (t) => ({\n property: t.expose(\"property\", { type: RelationProperty }),\n path: t.expose(\"path\", {\n type: \"JSON\",\n description:\n \"The source path of the value from the root of the saved document, \" +\n 'such as `[\"object\", 0]`.',\n }),\n representation: t.expose(\"representation\", {\n type: RelationRepresentation,\n ...occurrenceFields.representation,\n }),\n iri: t.expose(\"iri\", {\n type: \"URL\",\n nullable: true,\n description: occurrenceFields.iri,\n }),\n node: t.expose(\"node\", {\n type: DocumentNode,\n nullable: true,\n description: occurrenceFields.node,\n }),\n resource: t.field({\n type: Resource,\n nullable: true,\n description: occurrenceFields.resource,\n resolve: (occurrence, _, ctx) => registeredResource(ctx, occurrence.iri),\n }),\n }),\n});\n\nDocumentRecipient.implement({\n description:\n \"One value of an addressing property, in source order including \" +\n \"duplicates and anonymous embedded recipients.\",\n fields: (t) => ({\n property: t.expose(\"property\", { type: AddressingProperty }),\n position: t.exposeInt(\"position\", {\n description:\n \"The index of the value in its property's list, or 0 for a value \" +\n \"written alone.\",\n }),\n path: t.expose(\"path\", {\n type: \"JSON\",\n description:\n \"The source path of the value from the root of the saved document.\",\n }),\n representation: t.expose(\"representation\", {\n type: RelationRepresentation,\n ...occurrenceFields.representation,\n }),\n iri: t.expose(\"iri\", {\n type: \"URL\",\n nullable: true,\n description: occurrenceFields.iri,\n }),\n node: t.expose(\"node\", {\n type: DocumentNode,\n nullable: true,\n description: occurrenceFields.node,\n }),\n resource: t.field({\n type: Resource,\n nullable: true,\n description: occurrenceFields.resource,\n resolve: (occurrence, _, ctx) => registeredResource(ctx, occurrence.iri),\n }),\n }),\n});\n\nDocumentNode.implement({\n description:\n \"A vocabulary document of a saved revision, the root or one embedded in \" +\n \"it at any depth, read by meaning, whatever keys spell its properties. \" +\n \"It may be anonymous.\",\n fields: (t) => ({\n path: t.expose(\"path\", {\n type: \"JSON\",\n description:\n 'The source path from the root, such as `[\"object\", 0]`; `[]` is ' +\n \"the root.\",\n }),\n property: t.exposeString(\"property\", {\n nullable: true,\n description:\n \"The standard name of the property that embeds it, whatever its \" +\n \"source spelling; null for the root.\",\n }),\n type: t.expose(\"type\", {\n type: \"URL\",\n description: \"The type IRI, such as `…/activitystreams#Note`.\",\n }),\n kind: t.expose(\"kind\", { type: DocumentNodeKindEnum }),\n iri: t.expose(\"iri\", {\n type: \"URL\",\n nullable: true,\n description:\n \"Its `id`, or the `href` of a `Link`, with a compact IRI expanded; \" +\n \"null when it has none.\",\n }),\n document: t.expose(\"value\", {\n type: \"JSON\",\n description: \"Its JSON as saved, with everything it embeds.\",\n }),\n relations: t.field({\n type: [DocumentRelation],\n args: { property: t.arg({ type: RelationProperty }) },\n description:\n \"Its own `actor`, `object`, `target`, `origin`, `result`, \" +\n \"`instrument` and `attributedTo` values, or those of one property, \" +\n \"in that order, then in source order including duplicates. Empty \" +\n \"for a property it does not have.\",\n resolve: (node, { property }) =>\n property == null\n ? node.relations\n : node.relations.filter((entry) => entry.property === property),\n }),\n addressing: t.field({\n type: [DocumentRecipient],\n args: { property: t.arg({ type: AddressingProperty }) },\n description:\n \"Its own `to`, `cc`, `bto`, `bcc` and `audience` values, or those \" +\n \"of one property, in that order, then in source order including \" +\n \"duplicates.\",\n resolve: (node, { property }) =>\n property == null\n ? node.addressing\n : node.addressing.filter((entry) => entry.property === property),\n }),\n extensions: t.expose(\"extensions\", {\n type: [DocumentExtension],\n description:\n \"Its own custom extension properties, by their source keys, sorted.\",\n }),\n source: t.field({\n type: DocumentSource,\n nullable: true,\n description:\n \"The revision this embedded document came from, as recorded when \" +\n \"the document embedding it was saved. Null for the root, for an \" +\n \"embedded document whose source is unknown, such as one saved \" +\n \"before sources were recorded or pasted without one, and when the \" +\n \"viewer may not read the source revision, which are not told \" +\n \"apart. It hides nothing else: the document reads as the revision \" +\n \"embedding it does, whatever its source.\",\n resolve: (node, _, ctx) => sourceOf(ctx, node),\n }),\n }),\n});\n\nDocumentSource.implement({\n description:\n \"The revision an embedded document came from, which the viewer may \" +\n \"read.\",\n fields: (t) => ({\n relation: t.expose(\"relation\", { type: DocumentSourceRelation }),\n revision: t.field({\n type: ResourceRevisionRef,\n description: \"The source revision, of the resource the document names.\",\n resolve: (source) => source.revision,\n }),\n status: t.field({\n type: DocumentSourceStatus,\n nullable: true,\n description:\n \"Whether the source revision is still current, or a later revision \" +\n \"or a deletion followed it; null when the viewer may not read the \" +\n \"resource's current revision.\",\n resolve: (source) => source.status,\n }),\n }),\n});\n\ntype Content = Pick<ResourceRevisionRow, \"id\" | \"kind\" | \"document\">;\n\nconst interpretations = new WeakMap<Content, InterpretedNode | null>();\nconst validations = new WeakMap<Content, readonly Diagnostic[]>();\n\n/**\n * Interprets a revision's document once per loaded row.\n * @returns The root, or null unless the revision is a snapshot whose\n * document the validator reads without errors.\n */\nfunction rootOf(revision: Content): InterpretedNode | null {\n if (!interpretations.has(revision)) {\n const nodes =\n revision.kind === \"snapshot\"\n ? interpretDocument(revision.document)\n : null;\n for (const node of nodes ?? []) nodeRevisions.set(node, revision.id);\n interpretations.set(revision, nodes?.[0] ?? null);\n }\n return interpretations.get(revision)!;\n}\n\nfunction diagnosticsOf(revision: Content): readonly Diagnostic[] {\n let diagnostics = validations.get(revision);\n if (diagnostics == null) {\n diagnostics =\n revision.kind === \"snapshot\"\n ? validateDocument(revision.document).diagnostics\n : [];\n validations.set(revision, diagnostics);\n }\n return diagnostics;\n}\n\nconst content = { columns: { id: true, kind: true, document: true } } as const;\n\nconst ResourceRevisionRef = builder.drizzleNode(\"resourceRevisions\", {\n name: \"ResourceRevision\",\n description:\n \"An immutable revision of a resource. Each revision, past ones \" +\n \"included, is readable by evidence of its own, not by the current \" +\n \"state of its resource: one saved by DrFed for a local actor by anyone, \" +\n \"blind recipients and unpublished activities included; one addressed \" +\n \"to the public by anyone; one a receipt links to a delivery to a local \" +\n \"instance the viewer is a member of by its members; and the current \" +\n \"revision of a resource with a legacy typed row as `Activity` and \" +\n \"`Object` tell. Where its embedded documents came from never hides \" +\n \"it. Administrators read every revision. A later \" +\n \"restriction or deletion of the resource hides no earlier revision. A \" +\n \"revision the viewer may not read is left out as if it did not exist.\",\n // A node lookup checks the revision by its own ID.\n select: { columns: { id: true, resourceId: true } },\n id: { column: (revision) => revision.id },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n sequence: t.exposeInt(\"sequence\", {\n description: \"Increases with each revision of the resource.\",\n }),\n kind: t.expose(\"kind\", { type: ResourceRevisionKind }),\n capture: t.expose(\"capture\", { type: ResourceRevisionCapture }),\n backfilled: t.exposeBoolean(\"backfilled\", {\n description: \"Whether the migration from legacy typed rows created it.\",\n }),\n created: t.expose(\"created\", {\n type: \"DateTime\",\n description: \"When DrFed stored the revision.\",\n }),\n document: t.expose(\"document\", {\n type: \"JSON\",\n nullable: true,\n description:\n \"The saved JSON as is, `bto` and `bcc` included for local \" +\n \"resources. Read `root` instead of parsing it by keys, which \" +\n \"aliases and contexts may spell otherwise. Null unless `kind` is \" +\n \"`snapshot`, or for a snapshot of JSON null.\",\n }),\n interpreted: t.boolean({\n description:\n \"Whether `root` could be derived from `document`. When false, \" +\n \"`root` is null and, for a snapshot, `diagnostics` explain why.\",\n select: content,\n resolve: (revision) => rootOf(revision) != null,\n }),\n root: t.field({\n type: DocumentNode,\n nullable: true,\n description:\n \"The root document read by meaning; null unless `interpreted`.\",\n select: content,\n resolve: (revision) => rootOf(revision),\n }),\n diagnostics: t.field({\n type: [DocumentDiagnostic],\n description:\n \"What the current validator finds in the saved document, which may \" +\n \"differ from what it found when the revision was stored. Empty \" +\n \"unless `kind` is `snapshot`.\",\n select: content,\n resolve: (revision) => diagnosticsOf(revision),\n }),\n deleted: t.expose(\"deleted\", {\n type: \"DateTime\",\n nullable: true,\n description: \"The deletion time of a whiteout; null otherwise.\",\n }),\n formerTypes: t.field({\n type: [\"URL\"],\n nullable: true,\n description:\n \"The type IRIs the resource had, for a whiteout; null otherwise. \" +\n 'Stored ActivityStreams names, such as `\"Note\"`, are expanded with ' +\n \"`https://www.w3.org/ns/activitystreams#`.\",\n select: { columns: { formerTypes: true } },\n resolve: (revision) =>\n revision.formerTypes?.map((type) =>\n type.includes(\":\") ? type : `${ACTIVITY_STREAMS}${type}`,\n ) ?? null,\n }),\n }),\n});\nexport const ResourceRevision: DrFedObjectRef = ResourceRevisionRef;\n\nbuilder.drizzleObjectField(\"resources\", \"currentRevision\", (t) =>\n t.field({\n type: ResourceRevisionRef,\n nullable: true,\n description:\n \"The current revision; null for a resource without revisions, or when \" +\n \"the viewer may not read the current revision.\",\n select: { columns: { id: true } },\n resolve: async (resource, _, ctx) =>\n (await ctx.db.query.resourceRevisions.findFirst({\n where: {\n RAW: (table) =>\n and(\n inArray(\n table.id,\n ctx.db\n .select({ id: schema.resourceHeads.revisionId })\n .from(schema.resourceHeads)\n .where(eq(schema.resourceHeads.resourceId, resource.id)),\n ),\n readableRevision(ctx, table.id),\n )!,\n },\n })) ?? null,\n }),\n);\n\nbuilder.drizzleObjectField(\"resources\", \"revision\", (t) =>\n t.field({\n type: ResourceRevisionRef,\n nullable: true,\n args: { sequence: t.arg.int({ required: true }) },\n description:\n \"The revision with the given sequence; null when there is none, or \" +\n \"when the viewer may not read it, which are not told apart.\",\n select: { columns: { id: true } },\n resolve: async (resource, { sequence }, ctx) =>\n (await ctx.db.query.resourceRevisions.findFirst({\n where: {\n resourceId: resource.id,\n sequence,\n RAW: (table) => readableRevision(ctx, table.id),\n },\n })) ?? null,\n }),\n);\n\nbuilder.drizzleObjectField(\"resources\", \"revisions\", (t) =>\n t.relatedConnection(\n \"revisions\",\n {\n description:\n \"The revisions the viewer may read, newest first. Others are left \" +\n \"out, so sequences may skip.\",\n query: (_, ctx) => ({\n where: { RAW: (table) => readableRevision(ctx, table.id) },\n orderBy: { sequence: \"desc\" },\n }),\n },\n { name: \"ResourceRevisionConnection\" },\n { name: \"ResourceRevisionEdge\" },\n ),\n);\n","// 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 builder, { type DrFedObjectRef } from \"./builder.ts\";\n\nconst KeyRef = builder.drizzleNode(\"keys\", {\n name: \"Key\",\n description:\n \"A remote public key, identified by its IRI. Readable by any \" +\n \"authenticated viewer, since it holds public material only.\",\n authScopes: { authenticated: true },\n runScopesOnType: true,\n id: { column: (key) => key.id },\n fields: (t) => ({\n uuid: t.expose(\"id\", { type: \"UUID\" }),\n iri: t.expose(\"iri\", { type: \"URL\" }),\n created: t.expose(\"created\", { type: \"DateTime\" }),\n versions: t.relatedConnection(\"versions\", {\n description: \"The observed versions of the key, oldest first.\",\n query: { orderBy: { firstSeen: \"asc\", id: \"asc\" } },\n }),\n }),\n});\nexport const Key: DrFedObjectRef = KeyRef;\nconst observationDescription =\n \"DrFed observation time, not the remote key rotation time; \" +\n \"does not imply continuous use between observations.\";\nconst KeyVersionRef = builder.drizzleNode(\"keyVersions\", {\n name: \"KeyVersion\",\n description:\n \"Immutable public key material observed under a `Key`. Readable by \" +\n \"any authenticated viewer.\",\n authScopes: { authenticated: true },\n runScopesOnType: true,\n id: { column: (version) => version.id },\n fields: (t) => ({\n uuid: t.expose(\"id\", { type: \"UUID\" }),\n key: t.relation(\"key\"),\n publicKey: t.expose(\"publicKey\", { type: \"JSON\" }),\n fingerprint: t.exposeString(\"fingerprint\"),\n firstSeen: t.expose(\"firstSeen\", {\n type: \"DateTime\",\n description: `First ${observationDescription}`,\n }),\n lastSeen: t.expose(\"lastSeen\", {\n type: \"DateTime\",\n description: `Last ${observationDescription}`,\n }),\n }),\n});\nexport const KeyVersion: DrFedObjectRef = KeyVersionRef;\n","// 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// oxlint-disable import/no-unassigned-import\nimport \"./account.ts\";\nimport \"./instance.ts\";\nimport \"./auth/entry.ts\";\nimport \"./actor.ts\";\nimport \"./object.ts\";\nimport \"./revision.ts\";\nimport \"./activity-delivery/entry.ts\";\nimport \"./key.ts\";\nimport builder from \"./builder.ts\";\n\nbuilder.queryType({});\nbuilder.mutationType({});\n\nexport const schema = builder.toSchema();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAa,aAAa,OAAO,QAC/B,IAAI,WACF,MAAM,OAAO,OAAO,OAAO,WAAW,YAAY,OAAO,GAAG,CAAC,CAC/D,CAAC,CAAC,MAAM;AAEV,MAAM,cAAc,IAAI,YAAY;AAEpC,MAAM,qBAAqB;AAE3B,MAAa,4BACX,OAAO,gBAAgB,IAAI,WAAW,kBAAkB,CAAC,CAAC,CAAC,SAAS;CAClE,UAAU;CACV,aAAa;AACf,CAAC;;;ACJH,SAAwB,gBAAgB,EACtC,UACA,aACA,MACA,gBACgC;CAChC,eAAe,UAAU,aAAa;CACtC,eAAe,UAAU,MAAM;CAE/B,IAAI;CACJ,IAAI;EACF,MAAM,IAAI,IAAI,SAAS,OAAO;GAAE;GAAa;EAAK,CAAC,CAAC;CACtD,QAAQ;EACN,MAAM,iBACJ,qDACF;CACF;CAEA,IAAI,IAAI,aAAa,YAAY,IAAI,aAAa,SAChD,MAAM,iBAAiB,oCAAoC;CAE7D,IAAI,CAAC,aAAa,IAAI,IAAI,MAAM,GAC9B,MAAM,iBAAiB,qCAAqC,IAAI,OAAO,EAAE;CAE3E,OAAO,IAAI;AACb;AAEA,SAAS,eAAe,UAAoB,MAAoB;CAQ9D,IAAI,CAPU,SAAS,OAAO,MAC3B,UACC,MA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