@drfed/models 0.2.0-dev.714 → 0.2.0-dev.716

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/activity-delivery.d.mts +1 -1
  2. package/dist/{db-BBw4F4HU.d.mts → db-CcbUSnp2.d.mts} +84 -3
  3. package/dist/{db-BBw4F4HU.d.mts.map → db-CcbUSnp2.d.mts.map} +1 -1
  4. package/dist/db.d.mts +1 -1
  5. package/dist/document.d.mts +10 -0
  6. package/dist/document.d.mts.map +1 -1
  7. package/dist/document.mjs +6 -1
  8. package/dist/document.mjs.map +1 -1
  9. package/dist/index.d.mts +4 -4
  10. package/dist/index.mjs +3 -3
  11. package/dist/instance.d.mts +1 -1
  12. package/dist/key.d.mts +1 -1
  13. package/dist/login.d.mts +8 -2
  14. package/dist/login.d.mts.map +1 -1
  15. package/dist/login.mjs +8 -1
  16. package/dist/login.mjs.map +1 -1
  17. package/dist/migrations-manifest.json +8 -0
  18. package/dist/relations.d.mts +1 -1
  19. package/dist/relations.mjs +19 -2
  20. package/dist/relations.mjs.map +1 -1
  21. package/dist/{resource-revision-iQ8HZ699.mjs → resource-revision-bTQyJ7aw.mjs} +28 -3
  22. package/dist/resource-revision-bTQyJ7aw.mjs.map +1 -0
  23. package/dist/{resource-revision-BauDwFIn.d.mts → resource-revision-rDmHhNCj.d.mts} +19 -3
  24. package/dist/resource-revision-rDmHhNCj.d.mts.map +1 -0
  25. package/dist/resource-revision.d.mts +2 -2
  26. package/dist/resource-revision.mjs +1 -1
  27. package/dist/resource.d.mts +1 -1
  28. package/dist/schema.d.mts +2 -2
  29. package/dist/schema.mjs +27 -1
  30. package/dist/schema.mjs.map +1 -1
  31. package/drizzle/20261113080536_revision_embeddings/migration.sql +14 -0
  32. package/drizzle/20261113080536_revision_embeddings/snapshot.json +4634 -0
  33. package/drizzle/20261113080537_guard_revision_embeddings/migration.sql +42 -0
  34. package/drizzle/20261113080537_guard_revision_embeddings/snapshot.json +4634 -0
  35. package/package.json +6 -6
  36. package/dist/resource-revision-BauDwFIn.d.mts.map +0 -1
  37. package/dist/resource-revision-iQ8HZ699.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drfed/models",
3
- "version": "0.2.0-dev.714",
3
+ "version": "0.2.0-dev.716",
4
4
  "description": "Database models for DrFed.",
5
5
  "keywords": [
6
6
  "ActivityPub",
@@ -191,13 +191,13 @@
191
191
  },
192
192
  "drfedBuild": {
193
193
  "enabled": true,
194
- "version": "0.2.0-dev.714",
195
- "fullVersion": "0.2.0-dev.714+e47e1fdb",
194
+ "version": "0.2.0-dev.716",
195
+ "fullVersion": "0.2.0-dev.716+c33e1199",
196
196
  "baseVersion": "0.2.0",
197
197
  "channel": "dev",
198
- "sha": "e47e1fdb2e61a9834dec777197dab12afb09395c",
199
- "runNumber": "714",
200
- "runId": "44693378404",
198
+ "sha": "c33e11999ed51c7b2c86e33f66440196c7863f50",
199
+ "runNumber": "716",
200
+ "runId": "45125661114",
201
201
  "ref": "refs/heads/main",
202
202
  "workflow": ".github/workflows/main.yaml"
203
203
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"resource-revision-BauDwFIn.d.mts","names":[],"sources":["../src/revision-conflict-error.ts","../src/legacy-resource-revision-error.ts","../src/resource-revision-state-error.ts","../src/legacy-resource-revision.ts","../src/resource-revision.ts"],"mappings":";;;;;cAmBa,8BAA8B;WAE9B,YAAY;WACZ,oBAAoB;WACpB,kBAAkB;EAH7B,YACW,YAAY,MACZ,oBAAoB,aACpB,kBAAkB;;;;;cCJlB,oCAAoC;WAC1B,YAAY;EAAjC,YAAqB,YAAY;;;;;cCHtB,mCAAmC;WAEnC;EADX,YACW;;;;;;;;;;;iBCUS,8BACpB,IAAI,aACJ,YAAY,OACX,QAAQ;;;;KCkBC,wDAKC;YAEG,mBAAmB;;KAEvB;YAAyB,mBAAmB;;;UAGvC;WACN;WACA;WACA,gBAAgB;WAChB;;UAGD;WACC,YAAY;WACZ;;WAEA,oBAAoB;;KAEnB,8BAA8B;WAGzB;WACA,UAAU;WACV,SAAS;WACT,aAAa;;;;;WAKb,iCAAiC;WACjC,qBAAqB;WACrB,aAAa;;WAGb;WACA,SAAS,SAAS;WAClB;;;UAKA,+BAA+B;WACrC,qBAAqB;WACrB,oBAAoB;;;;;;;;;iBA+aT,uBACpB,IAAI,WAAW,aACf,OAAO,8BACN,QAAQ;;;;;iBASW,qBACpB,IAAI,WAAW,aACf,YAAY,OACX,QAAQ;;;;;iBAaW,4BACpB,IAAI,WAAW,aACf,YAAY,OACX,QAAQ;;;;;iBAWW,sBACpB,IAAI,WAAW,aACf,YAAY,MACZ;WAAoB;WAAkC;IACrD,QAAQ;;KA0DC,qBAAqB,KAC/B;UAYQ;WACC,YAAY;;WAEZ,oBAAoB;;KAEnB,6BAA6B;WAGxB;WACA,UAAU;;WAEV,SAAS,SAAS,KAAK,+BAC9B,QAAQ,KAAK;WACN,gCAAgC;WAChC,qBAAqB;WACrB,aAAa;;WAGb;WACA,SAAS,SAAS;WAClB;;;;;;;;;;;;;;;;;;;iBAyDK,2BACpB,IAAI,WAAW,aACf,OAAO,6BACN,QAAQ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"resource-revision-iQ8HZ699.mjs","names":["addressingTable"],"sources":["../src/legacy-resource-revision-error.ts","../src/resource-revision-state-error.ts","../src/revision-conflict-error.ts","../src/legacy-resource-revision.ts","../src/resource-revision.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport type { Uuid } from \"./uuid.ts\";\n\n/** Legacy typed rows require the coordinated application adapter in #152. */\nexport class LegacyResourceRevisionError extends Error {\n constructor(readonly resourceId: Uuid) {\n super(\n \"Legacy typed state requires coordinated capture and must agree with retained history.\",\n );\n this.name = \"LegacyResourceRevisionError\";\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\n/** A requested state transition would change a saved activity or revive a deletion. */\nexport class ResourceRevisionStateError extends Error {\n constructor(\n readonly code: \"activity-immutable\" | \"deleted\" | \"initial-whiteout\",\n ) {\n super(`Unsupported resource revision transition: ${code}.`);\n this.name = \"ResourceRevisionStateError\";\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 type { Uuid } from \"./uuid.ts\";\n\n/** The caller's expected current revision no longer matches the database. */\nexport class RevisionConflictError extends Error {\n constructor(\n readonly resourceId: Uuid,\n readonly expectedRevisionId: Uuid | null,\n readonly actualRevisionId: Uuid | null,\n ) {\n super(\"The resource's current revision has changed.\");\n this.name = \"RevisionConflictError\";\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 { sql } from \"drizzle-orm\";\n\nimport type { Transaction } from \"./db.ts\";\nimport { LegacyResourceRevisionError } from \"./legacy-resource-revision-error.ts\";\nimport type { Uuid } from \"./uuid.ts\";\n\n/**\n * Captures fully written legacy typed state within its creating transaction.\n * This trusted compatibility operation performs no authorization or fetching.\n * Repeated calls return the original revision only when the typed state agrees.\n * @returns The first retained revision ID, including an unavailable snapshot.\n * @throws {LegacyResourceRevisionError} When typed state cannot be captured.\n */\nexport async function captureLegacyResourceRevision(\n tx: Transaction,\n resourceId: Uuid,\n): Promise<Uuid> {\n try {\n const [row] = await tx\n .select({\n id: sql<Uuid>`drfed_capture_legacy_resource(${resourceId}::uuid, false)`,\n })\n .from(sql`(VALUES (1)) AS capture_input(value)`);\n if (row === undefined) {\n throw new Error(\"Legacy capture returned no revision.\");\n }\n return row.id;\n } catch (error) {\n let detail: unknown = error;\n while (detail instanceof Error) {\n if (\n (\"constraint\" in detail &&\n detail.constraint === \"resource_revisions_legacy_guard\") ||\n (\"constraint_name\" in detail &&\n detail.constraint_name === \"resource_revisions_legacy_guard\")\n ) {\n throw new LegacyResourceRevisionError(resourceId);\n }\n detail = detail.cause;\n }\n throw error;\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 { and, desc, eq, inArray, isNull, lt, sql } from \"drizzle-orm\";\n\nimport type { Database, Transaction } from \"./db.ts\";\nimport { LegacyResourceRevisionError } from \"./legacy-resource-revision-error.ts\";\nimport { ResourceRevisionStateError } from \"./resource-revision-state-error.ts\";\nimport {\n type AddressingInput,\n type AddressingOccurrence,\n ResourceKindConflictError,\n checkAddressingOccurrences,\n replaceAddressing,\n} from \"./resource.ts\";\nimport { RevisionConflictError } from \"./revision-conflict-error.ts\";\nimport {\n type NewActivityPubObject,\n type ResourceRevision,\n type RevisionAddressing,\n type RevisionRelation,\n activities,\n addressingPropertyEnum,\n addressing as addressingTable,\n objects,\n resourceHeads,\n resourceRevisionCaptureEnum,\n resourceRevisionProjectionEnum,\n resourceRevisions,\n resources,\n revisionAddressing,\n revisionRelations,\n} from \"./schema.ts\";\nimport { storableText } from \"./text.ts\";\nimport { type Uuid, areUuidsEqual, uuidV7, validateUuid } from \"./uuid.ts\";\n\n/** A value representable by JSON, without implicit coercion. */\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | readonly JsonValue[]\n | {\n readonly [property: string]: JsonValue;\n };\nexport type JsonObject = { readonly [property: string]: JsonValue };\n\n/** A semantic adapter's relation projection; no JSON-LD interpretation occurs here. */\nexport interface RevisionRelationInput {\n readonly property: string;\n readonly path?: readonly (string | number)[] | null;\n readonly representation: RevisionRelation[\"representation\"];\n readonly targetIri?: string | null;\n}\n\ninterface AppendBase {\n readonly resourceId: Uuid;\n readonly resourceKind: \"object\" | \"activity\";\n /** Null requires that the resource has no current revision. */\n readonly expectedRevisionId: Uuid | null;\n}\nexport type AppendResourceRevisionInput = AppendBase &\n (\n | {\n readonly kind: \"snapshot\";\n readonly document: JsonObject;\n readonly capture: ResourceRevision[\"capture\"];\n readonly addressing?: AddressingInput;\n /**\n * Explicit occurrences at their source positions, instead of\n * `addressing`; positions of unindexed values stay unused.\n */\n readonly addressingOccurrences?: readonly AddressingOccurrence[];\n readonly relations?: readonly RevisionRelationInput[];\n readonly projection?: ResourceRevision[\"projection\"];\n }\n | {\n readonly kind: \"whiteout\";\n readonly deleted: Temporal.Instant;\n readonly formerTypes: readonly string[];\n }\n );\n\n/** Protected local JSON and projections, not an authorized or wire representation. */\nexport interface StoredResourceRevision extends ResourceRevision {\n readonly addressing: readonly RevisionAddressing[];\n readonly relations: readonly RevisionRelation[];\n}\n\nexport { RevisionConflictError } from \"./revision-conflict-error.ts\";\nexport { LegacyResourceRevisionError } from \"./legacy-resource-revision-error.ts\";\nexport { ResourceRevisionStateError } from \"./resource-revision-state-error.ts\";\n\nfunction text(value: unknown): asserts value is string {\n if (typeof value !== \"string\" || !storableText(value)) {\n throw new TypeError(\"A projection must contain losslessly storable text.\");\n }\n}\n\nfunction jsonKeys(value: object): string[] {\n const prototype: unknown = Object.getPrototypeOf(value);\n if (\n Array.isArray(value)\n ? prototype !== Array.prototype\n : prototype !== Object.prototype && prototype !== null\n ) {\n throw new TypeError(\"JSON objects must be plain records.\");\n }\n const result: string[] = [];\n for (const key of Reflect.ownKeys(value)) {\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (\n typeof key !== \"string\" ||\n descriptor === undefined ||\n !(\"value\" in descriptor)\n ) {\n throw new TypeError(\n \"JSON values cannot contain symbol keys or accessors.\",\n );\n }\n if (Array.isArray(value) && key === \"length\") continue;\n if (!descriptor.enumerable) {\n throw new TypeError(\"JSON members must be enumerable.\");\n }\n if (\n Array.isArray(value) &&\n (!/^(?:0|[1-9][0-9]*)$/u.test(key) || Number(key) >= value.length)\n ) {\n throw new TypeError(\"JSON arrays cannot contain named properties.\");\n }\n result.push(key);\n }\n return result;\n}\n\n// Produce JSON directly so negative zero and escaped Unicode are retained.\nfunction json(value: unknown, ancestors = new Set<object>()): string {\n if (value === null) return \"null\";\n if (typeof value === \"string\" || typeof value === \"boolean\") {\n return JSON.stringify(value);\n }\n if (typeof value === \"number\") {\n if (!Number.isFinite(value)) {\n throw new TypeError(\"JSON numbers must be finite.\");\n }\n return Object.is(value, -0) ? \"-0\" : JSON.stringify(value);\n }\n if (typeof value !== \"object\" || ancestors.has(value)) {\n throw new TypeError(\"Expected an acyclic JSON value without coercion.\");\n }\n const keys = jsonKeys(value);\n ancestors.add(value);\n try {\n if (Array.isArray(value)) {\n return `[${Array.from(value, (entry: unknown) => json(entry, ancestors)).join(\",\")}]`;\n }\n return `{${keys.map((key) => `${JSON.stringify(key)}:${json(Object.getOwnPropertyDescriptor(value, key)!.value, ancestors)}`).join(\",\")}}`;\n } finally {\n ancestors.delete(value);\n }\n}\n\nfunction projectionRows(\n input: AddressingInput = {},\n): Omit<RevisionAddressing, \"revisionId\">[] {\n const rows: Omit<RevisionAddressing, \"revisionId\">[] = [];\n for (const property of Object.keys(input)) {\n if (\n !addressingPropertyEnum.enumValues.includes(\n property as RevisionAddressing[\"property\"],\n )\n ) {\n throw new TypeError(\"Unknown addressing projection property.\");\n }\n }\n for (const property of addressingPropertyEnum.enumValues) {\n const values = input[property];\n if (values === undefined) continue;\n if (!Array.isArray(values)) {\n throw new TypeError(\"Addressing projections must be arrays.\");\n }\n for (const [position, iri] of values.entries()) {\n text(iri);\n rows.push({ property, position, iri });\n }\n }\n return rows;\n}\n\nfunction relationRows(\n input: readonly RevisionRelationInput[] = [],\n): Omit<RevisionRelation, \"revisionId\">[] {\n if (!Array.isArray(input)) {\n throw new TypeError(\"Relation projections must be arrays.\");\n }\n return input.map((relation, occurrence) => {\n text(relation.property);\n const targetIri = relation.targetIri ?? null;\n if (targetIri !== null) text(targetIri);\n if (\n ![\"reference\", \"embedded\", \"link\"].includes(relation.representation) ||\n (relation.representation === \"reference\" && targetIri === null)\n ) {\n throw new TypeError(\"Invalid relation representation.\");\n }\n const path = relation.path ?? null;\n if (\n path !== null &&\n (!Array.isArray(path) ||\n Array.from(path).some(\n (part) =>\n typeof part !== \"string\" &&\n !(Number.isSafeInteger(part) && part >= 0),\n ))\n ) {\n throw new TypeError(\n \"A relation path must contain field names and nonnegative indexes.\",\n );\n }\n return {\n occurrence,\n property: relation.property,\n representation: relation.representation,\n targetIri,\n path: path === null ? null : [...path],\n };\n });\n}\n\nasync function current(\n db: Database | Transaction,\n resourceId: Uuid,\n): Promise<ResourceRevision | null> {\n const [row] = await db\n .select({ revision: resourceRevisions })\n .from(resourceHeads)\n .innerJoin(\n resourceRevisions,\n and(\n eq(resourceHeads.resourceId, resourceRevisions.resourceId),\n eq(resourceHeads.revisionId, resourceRevisions.id),\n ),\n )\n .where(eq(resourceHeads.resourceId, resourceId))\n .limit(1);\n return row?.revision ?? null;\n}\n\nasync function hydrate(\n db: Database | Transaction,\n revision: ResourceRevision,\n): Promise<StoredResourceRevision> {\n const [addressing, relations] = await Promise.all([\n db\n .select()\n .from(revisionAddressing)\n .where(eq(revisionAddressing.revisionId, revision.id))\n .orderBy(revisionAddressing.property, revisionAddressing.position),\n db\n .select()\n .from(revisionRelations)\n .where(eq(revisionRelations.revisionId, revision.id))\n .orderBy(revisionRelations.occurrence),\n ]);\n return { ...revision, addressing, relations };\n}\n\ninterface PreparedRevision extends AppendBase {\n readonly kind: \"snapshot\" | \"whiteout\";\n readonly serialized: string | null;\n readonly capture: ResourceRevision[\"capture\"] | undefined;\n readonly projection: ResourceRevision[\"projection\"] | undefined;\n readonly addressing: Omit<RevisionAddressing, \"revisionId\">[];\n readonly relations: Omit<RevisionRelation, \"revisionId\">[];\n readonly deleted: Temporal.Instant | null;\n readonly formerTypes: string[] | null;\n}\n\ntype PreparedValue = Omit<PreparedRevision, keyof AppendBase>;\nfunction prepareSnapshot(\n input: Extract<AppendResourceRevisionInput, { kind: \"snapshot\" }>,\n): PreparedValue {\n if (\n input.document === null ||\n typeof input.document !== \"object\" ||\n Array.isArray(input.document)\n ) {\n throw new TypeError(\"A new resource document must be a JSON object.\");\n }\n const projection = input.projection ?? \"partial\";\n if (\n !resourceRevisionCaptureEnum.enumValues.includes(input.capture) ||\n !resourceRevisionProjectionEnum.enumValues.includes(projection)\n ) {\n throw new TypeError(\"Invalid capture or projection category.\");\n }\n let addressing: Omit<RevisionAddressing, \"revisionId\">[];\n if (input.addressingOccurrences === undefined) {\n addressing = projectionRows(input.addressing);\n } else {\n if (input.addressing !== undefined) {\n throw new TypeError(\"Pass addressing or its occurrences, not both.\");\n }\n checkAddressingOccurrences(input.addressingOccurrences);\n addressing = input.addressingOccurrences.map(\n ({ property, position, iri }) => {\n text(iri);\n return { property, position, iri };\n },\n );\n }\n return {\n kind: \"snapshot\",\n serialized: json(input.document),\n capture: input.capture,\n projection,\n addressing,\n relations: relationRows(input.relations),\n deleted: null,\n formerTypes: null,\n };\n}\n\nfunction prepareWhiteout(\n input: Extract<AppendResourceRevisionInput, { kind: \"whiteout\" }>,\n): PreparedValue {\n if (\n !(input.deleted instanceof Temporal.Instant) ||\n !Array.isArray(input.formerTypes)\n ) {\n throw new TypeError(\"Expected a deletion instant and former type array.\");\n }\n const formerTypes = [...input.formerTypes];\n for (const type of formerTypes) text(type);\n return {\n kind: \"whiteout\",\n serialized: null,\n capture: undefined,\n projection: undefined,\n addressing: [],\n relations: [],\n deleted: input.deleted,\n formerTypes,\n };\n}\n\nfunction prepareRevision(input: AppendResourceRevisionInput): PreparedRevision {\n const { resourceId, resourceKind, expectedRevisionId } = input;\n if (\n !validateUuid(resourceId) ||\n (expectedRevisionId !== null && !validateUuid(expectedRevisionId))\n ) {\n throw new TypeError(\"Expected canonical resource and revision UUIDs.\");\n }\n if (resourceKind !== \"object\" && resourceKind !== \"activity\") {\n throw new TypeError(\"Unsupported resource kind.\");\n }\n if (input.kind === \"snapshot\") {\n return {\n resourceId,\n resourceKind,\n expectedRevisionId,\n ...prepareSnapshot(input),\n };\n }\n if (input.kind === \"whiteout\") {\n return {\n resourceId,\n resourceKind,\n expectedRevisionId,\n ...prepareWhiteout(input),\n };\n }\n throw new TypeError(\"Unsupported revision kind.\");\n}\n\nasync function lockRevisionTarget(\n tx: Transaction,\n input: PreparedRevision,\n typed = false,\n): Promise<ResourceRevision | null> {\n const { resourceId, resourceKind, expectedRevisionId, kind } = input;\n const [resource] = await tx\n .select()\n .from(resources)\n .where(eq(resources.id, resourceId))\n .for(\"no key update\");\n if (resource === undefined) {\n throw new Error(\"The canonical resource is not registered.\");\n }\n // Read the head separately after the resource lock, including after a wait.\n const previous = await current(tx, resourceId);\n const matches =\n previous === null\n ? expectedRevisionId === null\n : expectedRevisionId !== null &&\n areUuidsEqual(previous.id, expectedRevisionId);\n if (!matches) {\n throw new RevisionConflictError(\n resourceId,\n expectedRevisionId,\n previous?.id ?? null,\n );\n }\n const [legacyObject, legacyActivity] = await Promise.all([\n tx\n .select({ id: objects.id })\n .from(objects)\n .where(eq(objects.id, resourceId))\n .limit(1),\n tx\n .select({ id: activities.id })\n .from(activities)\n .where(eq(activities.id, resourceId))\n .limit(1),\n ]);\n // A typed append has verified and changes the typed row itself.\n if (!typed && (legacyObject.length > 0 || legacyActivity.length > 0)) {\n throw new LegacyResourceRevisionError(resourceId);\n }\n if (resource.kind !== \"unknown\" && resource.kind !== resourceKind) {\n throw new ResourceKindConflictError(\n resource.iri,\n resource.kind,\n resourceKind,\n );\n }\n if (previous !== null && resourceKind === \"activity\") {\n throw new ResourceRevisionStateError(\"activity-immutable\");\n }\n if (previous?.kind === \"whiteout\") {\n throw new ResourceRevisionStateError(\"deleted\");\n }\n if (kind === \"whiteout\" && previous === null) {\n throw new ResourceRevisionStateError(\"initial-whiteout\");\n }\n if (resource.kind === \"unknown\") {\n await tx\n .update(resources)\n .set({ kind: resourceKind })\n .where(eq(resources.id, resourceId));\n }\n return previous;\n}\n\nasync function appendPrepared(\n tx: Transaction,\n input: PreparedRevision,\n typed = false,\n): Promise<StoredResourceRevision> {\n const previous = await lockRevisionTarget(tx, input, typed);\n const {\n resourceId,\n kind,\n serialized,\n capture,\n projection,\n deleted,\n formerTypes,\n addressing,\n relations,\n } = input;\n const id = uuidV7();\n const [revision] = await tx\n .insert(resourceRevisions)\n .values({\n id,\n resourceId,\n sequence: (previous?.sequence ?? 0) + 1,\n kind,\n capture: capture ?? previous!.capture,\n projection: projection ?? previous!.projection,\n document: serialized === null ? null : sql`${serialized}::json`,\n deleted,\n formerTypes,\n })\n .returning();\n if (revision === undefined) {\n throw new Error(\"Revision insertion returned no row.\");\n }\n if (kind === \"whiteout\") {\n const inherited = await hydrate(tx, previous!);\n addressing.push(\n ...inherited.addressing.map(({ revisionId: _revisionId, ...row }) => row),\n );\n relations.push(\n ...inherited.relations.map(({ revisionId: _revisionId, ...row }) => row),\n );\n }\n if (addressing.length > 0) {\n await tx\n .insert(revisionAddressing)\n .values(addressing.map((row) => ({ ...row, revisionId: id })));\n }\n if (relations.length > 0) {\n await tx\n .insert(revisionRelations)\n .values(relations.map((row) => ({ ...row, revisionId: id })));\n }\n if (previous === null) {\n await tx.insert(resourceHeads).values({ resourceId, revisionId: id });\n } else {\n await tx\n .update(resourceHeads)\n .set({ revisionId: id })\n .where(eq(resourceHeads.resourceId, resourceId));\n }\n return await hydrate(tx, revision);\n}\n\n/**\n * Appends one current object version or saved activity, atomically with projections.\n * The caller must validate the document and authorize the write. Lock multiple\n * canonical IRIs in sorted order before composing several appends in one transaction.\n * This does not publish, change collection membership, or reserve delivery.\n * @returns The stored revision, including protected blind addressing.\n */\nexport async function appendResourceRevision(\n db: Database | Transaction,\n input: AppendResourceRevisionInput,\n): Promise<StoredResourceRevision> {\n const prepared = prepareRevision(input);\n return await db.transaction((tx) => appendPrepared(tx, prepared));\n}\n\n/**\n * Loads protected local JSON without applying authorization or stripping bto/bcc.\n * @returns The immutable revision and projections, or null if not found.\n */\nexport async function loadResourceRevision(\n db: Database | Transaction,\n revisionId: Uuid,\n): Promise<StoredResourceRevision | null> {\n const [revision] = await db\n .select()\n .from(resourceRevisions)\n .where(eq(resourceRevisions.id, revisionId))\n .limit(1);\n return revision === undefined ? null : await hydrate(db, revision);\n}\n\n/**\n * Loads current protected local state without dereferencing any document target.\n * @returns A snapshot, unavailable record or whiteout, or null when unversioned.\n */\nexport async function loadCurrentResourceRevision(\n db: Database | Transaction,\n resourceId: Uuid,\n): Promise<StoredResourceRevision | null> {\n const revision = await current(db, resourceId);\n return revision === null ? null : await hydrate(db, revision);\n}\n\nconst MAX_HISTORY_LIMIT = 100;\nconst DEFAULT_HISTORY_LIMIT = 20;\n/**\n * Lists protected history in descending sequence order; authorization belongs to callers.\n * @returns Up to limit revisions strictly before beforeSequence, when supplied.\n */\nexport async function listResourceRevisions(\n db: Database | Transaction,\n resourceId: Uuid,\n options: { readonly beforeSequence?: number; readonly limit?: number } = {},\n): Promise<StoredResourceRevision[]> {\n const { beforeSequence, limit = DEFAULT_HISTORY_LIMIT } = options;\n if (\n !Number.isInteger(limit) ||\n limit < 1 ||\n limit > MAX_HISTORY_LIMIT ||\n (beforeSequence !== undefined &&\n (!Number.isSafeInteger(beforeSequence) || beforeSequence < 1))\n ) {\n throw new RangeError(\"Invalid history bounds.\");\n }\n const revisions = await db\n .select()\n .from(resourceRevisions)\n .where(\n and(\n eq(resourceRevisions.resourceId, resourceId),\n beforeSequence === undefined\n ? undefined\n : lt(resourceRevisions.sequence, beforeSequence),\n ),\n )\n .orderBy(desc(resourceRevisions.sequence))\n .limit(limit);\n if (revisions.length === 0) return [];\n const revisionIds = revisions.map(({ id }) => id);\n const [addressing, relations] = await Promise.all([\n db\n .select()\n .from(revisionAddressing)\n .where(inArray(revisionAddressing.revisionId, revisionIds))\n .orderBy(revisionAddressing.property, revisionAddressing.position),\n db\n .select()\n .from(revisionRelations)\n .where(inArray(revisionRelations.revisionId, revisionIds))\n .orderBy(revisionRelations.occurrence),\n ]);\n const addressingByRevision = new Map<Uuid, RevisionAddressing[]>();\n for (const row of addressing) {\n const rows = addressingByRevision.get(row.revisionId) ?? [];\n rows.push(row);\n addressingByRevision.set(row.revisionId, rows);\n }\n const relationsByRevision = new Map<Uuid, RevisionRelation[]>();\n for (const row of relations) {\n const rows = relationsByRevision.get(row.revisionId) ?? [];\n rows.push(row);\n relationsByRevision.set(row.revisionId, rows);\n }\n return revisions.map((revision) => ({\n ...revision,\n addressing: addressingByRevision.get(revision.id) ?? [],\n relations: relationsByRevision.get(revision.id) ?? [],\n }));\n}\n\n/** Typed object columns a coordinated edit may set, besides its document. */\nexport type TypedObjectColumns = Pick<\n NewActivityPubObject,\n | \"type\"\n | \"url\"\n | \"name\"\n | \"summary\"\n | \"contentHtml\"\n | \"language\"\n | \"sensitive\"\n | \"published\"\n | \"updated\"\n>;\n\ninterface TypedRevisionBase {\n readonly resourceId: Uuid;\n /** The current revision; a typed object always has one. */\n readonly expectedRevisionId: Uuid;\n}\nexport type TypedResourceRevisionInput = TypedRevisionBase &\n (\n | {\n readonly kind: \"snapshot\";\n readonly document: JsonObject;\n /** Every column the typed row serves; `updated` is not implied. */\n readonly columns: Required<Omit<TypedObjectColumns, \"type\">> &\n Partial<Pick<TypedObjectColumns, \"type\">>;\n readonly addressingOccurrences: readonly AddressingOccurrence[];\n readonly relations?: readonly RevisionRelationInput[];\n readonly projection?: ResourceRevision[\"projection\"];\n }\n | {\n readonly kind: \"whiteout\";\n readonly deleted: Temporal.Instant;\n readonly formerTypes: readonly string[];\n }\n );\n\nasync function sameTypedState(\n tx: Transaction,\n resourceId: Uuid,\n head: ResourceRevision,\n): Promise<boolean> {\n // Compare JSON text, as legacy capture does, rather than parsed values.\n const [row] = await tx\n .select({\n same: sql<boolean>`${objects.document}::text IS NOT DISTINCT FROM ${resourceRevisions.document}::text\n AND NOT EXISTS (\n (SELECT saved.property, saved.position, saved.iri\n FROM ${revisionAddressing} AS saved\n WHERE saved.revision_id = ${head.id})\n EXCEPT ALL\n (SELECT declared.property, declared.position, target.iri\n FROM ${addressingTable} AS declared\n JOIN ${resources} AS target ON target.id = declared.target_id\n WHERE declared.source_id = ${resourceId})\n )\n AND NOT EXISTS (\n (SELECT declared.property, declared.position, target.iri\n FROM ${addressingTable} AS declared\n JOIN ${resources} AS target ON target.id = declared.target_id\n WHERE declared.source_id = ${resourceId})\n EXCEPT ALL\n (SELECT saved.property, saved.position, saved.iri\n FROM ${revisionAddressing} AS saved\n WHERE saved.revision_id = ${head.id})\n )`,\n })\n .from(objects)\n .innerJoin(resourceRevisions, eq(resourceRevisions.id, head.id))\n .where(and(eq(objects.id, resourceId), isNull(objects.deleted)));\n return row?.same === true;\n}\n\n/**\n * Edits or deletes an object that has a legacy typed row, keeping the typed\n * row, its current addressing, and the revision history in step. Under the\n * canonical lock, the current revision must be the expected snapshot, and the\n * typed row's document and addressing must still equal it; otherwise nothing\n * changes. A snapshot sets the typed columns, the typed document to the same\n * JSON as the new revision, and the current addressing to the occurrences. A\n * whiteout soft-deletes the typed row and keeps its addressing, which\n * continues to describe the last content. The caller must validate and\n * authorize the change and check any served column against the old head.\n * The whole write runs in a savepoint, so a caught error leaves no part of it.\n * @returns The appended revision, including protected blind addressing.\n * @throws {RevisionConflictError} If the current revision is not the expected.\n * @throws {LegacyResourceRevisionError} If the resource has no live typed\n * object or the typed state differs from its current revision.\n * @throws {ResourceRevisionStateError} If the object is already deleted.\n */\nexport async function writeTypedResourceRevision(\n db: Database | Transaction,\n input: TypedResourceRevisionInput,\n): Promise<StoredResourceRevision> {\n const prepared = prepareRevision(\n input.kind === \"snapshot\"\n ? {\n resourceId: input.resourceId,\n resourceKind: \"object\",\n expectedRevisionId: input.expectedRevisionId,\n kind: \"snapshot\",\n document: input.document,\n capture: \"local\",\n addressingOccurrences: input.addressingOccurrences,\n ...(input.relations === undefined\n ? {}\n : { relations: input.relations }),\n ...(input.projection === undefined\n ? {}\n : { projection: input.projection }),\n }\n : {\n resourceId: input.resourceId,\n resourceKind: \"object\",\n expectedRevisionId: input.expectedRevisionId,\n kind: \"whiteout\",\n deleted: input.deleted,\n formerTypes: input.formerTypes,\n },\n );\n if (prepared.expectedRevisionId === null) {\n throw new TypeError(\"A typed object always has a current revision.\");\n }\n return await db.transaction(async (tx) => {\n const [resource] = await tx\n .select({ kind: resources.kind })\n .from(resources)\n .where(eq(resources.id, prepared.resourceId))\n .for(\"no key update\");\n const [typed] = await tx\n .select({ id: objects.id })\n .from(objects)\n .where(eq(objects.id, prepared.resourceId))\n .for(\"update\");\n if (resource?.kind !== \"object\" || typed === undefined) {\n throw new LegacyResourceRevisionError(prepared.resourceId);\n }\n const head = await current(tx, prepared.resourceId);\n if (\n head === null ||\n !areUuidsEqual(head.id, prepared.expectedRevisionId!)\n ) {\n throw new RevisionConflictError(\n prepared.resourceId,\n prepared.expectedRevisionId,\n head?.id ?? null,\n );\n }\n if (head.kind === \"whiteout\") {\n throw new ResourceRevisionStateError(\"deleted\");\n }\n if (\n head.kind !== \"snapshot\" ||\n !(await sameTypedState(tx, prepared.resourceId, head))\n ) {\n throw new LegacyResourceRevisionError(prepared.resourceId);\n }\n if (input.kind === \"snapshot\") {\n await tx\n .update(objects)\n .set({\n ...input.columns,\n // The edited document is local, not a copy fetched from its IRI.\n fetched: false,\n document: sql`${prepared.serialized}::json`,\n })\n .where(eq(objects.id, prepared.resourceId));\n await replaceAddressing(\n tx,\n prepared.resourceId,\n input.addressingOccurrences,\n );\n } else {\n // Keep the update hook from moving `updated` past the deletion.\n const [row] = await tx\n .select({ updated: objects.updated })\n .from(objects)\n .where(eq(objects.id, prepared.resourceId));\n await tx\n .update(objects)\n .set({ deleted: input.deleted, updated: row!.updated })\n .where(eq(objects.id, prepared.resourceId));\n }\n return await appendPrepared(tx, prepared, true);\n });\n}\n\nexport { captureLegacyResourceRevision } from \"./legacy-resource-revision.ts\";\n"],"mappings":";;;;;;;AAmBA,I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