@drfed/models 0.2.0-dev.639 → 0.2.0-dev.651

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 (34) hide show
  1. package/README.md +32 -188
  2. package/dist/activity-delivery.d.mts +1 -1
  3. package/dist/activity-delivery.d.mts.map +1 -1
  4. package/dist/activity-delivery.mjs +34 -9
  5. package/dist/activity-delivery.mjs.map +1 -1
  6. package/dist/{db-DtcLuISw.d.mts → db-BBw4F4HU.d.mts} +478 -6
  7. package/dist/{db-DtcLuISw.d.mts.map → db-BBw4F4HU.d.mts.map} +1 -1
  8. package/dist/db.d.mts +1 -1
  9. package/dist/index.d.mts +3 -2
  10. package/dist/index.mjs +2 -1
  11. package/dist/instance.d.mts +1 -1
  12. package/dist/key.d.mts +1 -1
  13. package/dist/login.d.mts +1 -1
  14. package/dist/migrations-manifest.json +12 -0
  15. package/dist/relations.d.mts +1 -1
  16. package/dist/relations.mjs +65 -0
  17. package/dist/relations.mjs.map +1 -1
  18. package/dist/resource-revision-BuG5kUlA.d.mts +103 -0
  19. package/dist/resource-revision-BuG5kUlA.d.mts.map +1 -0
  20. package/dist/resource-revision-DWg6et77.mjs +313 -0
  21. package/dist/resource-revision-DWg6et77.mjs.map +1 -0
  22. package/dist/resource-revision.d.mts +2 -0
  23. package/dist/resource-revision.mjs +3 -0
  24. package/dist/resource.d.mts +1 -1
  25. package/dist/schema.d.mts +2 -2
  26. package/dist/schema.mjs +104 -5
  27. package/dist/schema.mjs.map +1 -1
  28. package/drizzle/20261026181201_resource_revision_storage/migration.sql +72 -0
  29. package/drizzle/20261026181201_resource_revision_storage/snapshot.json +4501 -0
  30. package/drizzle/20261026181206_guard_resource_revisions/migration.sql +175 -0
  31. package/drizzle/20261026181206_guard_resource_revisions/snapshot.json +4501 -0
  32. package/drizzle/20261026192411_capture_legacy_resource_revisions/migration.sql +249 -0
  33. package/drizzle/20261026192411_capture_legacy_resource_revisions/snapshot.json +4501 -0
  34. package/package.json +12 -7
@@ -1,2 +1,2 @@
1
- import { i as relations } from "./db-DtcLuISw.mjs";
1
+ import { i as relations } from "./db-BBw4F4HU.mjs";
2
2
  export { relations as default, relations };
@@ -2,6 +2,59 @@ import { t as schema_exports } from "./schema.mjs";
2
2
  import { defineRelations } from "drizzle-orm";
3
3
  //#region src/relations.ts
4
4
  const relations = defineRelations(schema_exports, (r) => ({
5
+ resourceRevisions: {
6
+ resource: r.one.resources({
7
+ from: r.resourceRevisions.resourceId,
8
+ to: r.resources.id,
9
+ optional: false
10
+ }),
11
+ addressing: r.many.revisionAddressing({
12
+ from: r.resourceRevisions.id,
13
+ to: r.revisionAddressing.revisionId
14
+ }),
15
+ relations: r.many.revisionRelations({
16
+ from: r.resourceRevisions.id,
17
+ to: r.revisionRelations.revisionId
18
+ }),
19
+ receipts: r.many.revisionReceipts({
20
+ from: r.resourceRevisions.id,
21
+ to: r.revisionReceipts.revisionId
22
+ })
23
+ },
24
+ resourceHeads: {
25
+ resource: r.one.resources({
26
+ from: r.resourceHeads.resourceId,
27
+ to: r.resources.id,
28
+ optional: false
29
+ }),
30
+ revision: r.one.resourceRevisions({
31
+ from: [r.resourceHeads.resourceId, r.resourceHeads.revisionId],
32
+ to: [r.resourceRevisions.resourceId, r.resourceRevisions.id],
33
+ optional: false
34
+ })
35
+ },
36
+ revisionAddressing: { revision: r.one.resourceRevisions({
37
+ from: r.revisionAddressing.revisionId,
38
+ to: r.resourceRevisions.id,
39
+ optional: false
40
+ }) },
41
+ revisionRelations: { revision: r.one.resourceRevisions({
42
+ from: r.revisionRelations.revisionId,
43
+ to: r.resourceRevisions.id,
44
+ optional: false
45
+ }) },
46
+ revisionReceipts: {
47
+ revision: r.one.resourceRevisions({
48
+ from: r.revisionReceipts.revisionId,
49
+ to: r.resourceRevisions.id,
50
+ optional: false
51
+ }),
52
+ delivery: r.one.activityDeliveries({
53
+ from: r.revisionReceipts.deliveryId,
54
+ to: r.activityDeliveries.id,
55
+ optional: false
56
+ })
57
+ },
5
58
  keys: { versions: r.many.keyVersions({
6
59
  from: r.keys.id,
7
60
  to: r.keyVersions.keyId
@@ -18,6 +71,10 @@ const relations = defineRelations(schema_exports, (r) => ({
18
71
  })
19
72
  },
20
73
  activityDeliveries: {
74
+ revisionReceipts: r.many.revisionReceipts({
75
+ from: r.activityDeliveries.id,
76
+ to: r.revisionReceipts.deliveryId
77
+ }),
21
78
  instance: r.one.instances({
22
79
  from: r.activityDeliveries.instanceId,
23
80
  to: r.instances.id,
@@ -139,6 +196,14 @@ const relations = defineRelations(schema_exports, (r) => ({
139
196
  optional: false
140
197
  }) },
141
198
  resources: {
199
+ revisions: r.many.resourceRevisions({
200
+ from: r.resources.id,
201
+ to: r.resourceRevisions.resourceId
202
+ }),
203
+ head: r.one.resourceHeads({
204
+ from: r.resources.id,
205
+ to: r.resourceHeads.resourceId
206
+ }),
142
207
  actor: r.one.actors({
143
208
  from: r.resources.id,
144
209
  to: r.actors.id,
@@ -1 +1 @@
1
- {"version":3,"file":"relations.mjs","names":["schema"],"sources":["../src/relations.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 { defineRelations } from \"drizzle-orm\";\n\nimport * as schema from \"./schema.ts\";\n\nexport const relations = defineRelations(schema, (r) => ({\n keys: {\n versions: r.many.keyVersions({ from: r.keys.id, to: r.keyVersions.keyId }),\n },\n keyVersions: {\n key: r.one.keys({\n from: r.keyVersions.keyId,\n to: r.keys.id,\n optional: false,\n }),\n activityDeliveries: r.many.activityDeliveries({\n from: r.keyVersions.id,\n to: r.activityDeliveries.verificationKeyId,\n }),\n },\n activityDeliveries: {\n instance: r.one.instances({\n from: r.activityDeliveries.instanceId,\n to: r.instances.id,\n optional: false,\n }),\n actor: r.one.actors({\n from: r.activityDeliveries.actorId,\n to: r.actors.id,\n where: { deleted: { isNull: true } },\n }),\n actorLinks: r.many.activityDeliveryActors({\n from: r.activityDeliveries.id,\n to: r.activityDeliveryActors.deliveryId,\n }),\n verificationKey: r.one.keyVersions({\n from: r.activityDeliveries.verificationKeyId,\n to: r.keyVersions.id,\n }),\n attempts: r.many.activityDeliveryAttempts({\n from: r.activityDeliveries.id,\n to: r.activityDeliveryAttempts.deliveryId,\n }),\n activity: r.one.activities({\n from: r.activityDeliveries.activityId,\n to: r.activities.id,\n }),\n },\n activityDeliveryAttempts: {\n delivery: r.one.activityDeliveries({\n from: r.activityDeliveryAttempts.deliveryId,\n to: r.activityDeliveries.id,\n optional: false,\n }),\n },\n activityDeliveryActors: {\n delivery: r.one.activityDeliveries({\n from: r.activityDeliveryActors.deliveryId,\n to: r.activityDeliveries.id,\n optional: false,\n }),\n actor: r.one.actors({\n from: r.activityDeliveryActors.actorId,\n to: r.actors.id,\n optional: false,\n }),\n collections: r.many.activityDeliveryActorCollections({\n from: [\n r.activityDeliveryActors.deliveryId,\n r.activityDeliveryActors.actorId,\n ],\n to: [\n r.activityDeliveryActorCollections.deliveryId,\n r.activityDeliveryActorCollections.actorId,\n ],\n }),\n },\n activityDeliveryActorCollections: {\n actorLink: r.one.activityDeliveryActors({\n from: [\n r.activityDeliveryActorCollections.deliveryId,\n r.activityDeliveryActorCollections.actorId,\n ],\n to: [\n r.activityDeliveryActors.deliveryId,\n r.activityDeliveryActors.actorId,\n ],\n optional: false,\n }),\n },\n accounts: {\n instances: r.many.instances({\n from: r.accounts.id.through(r.instanceMembers.accountId),\n to: r.instances.id.through(r.instanceMembers.instanceId),\n // Drizzle ORM currently does not support many-to-many relationships with\n // additional filters on the junction table. So we need to specify\n // filter `accepted IS NOT NULL` everywhere we query for instances of\n // an account (sigh). See also the below issue:\n // https://github.com/drizzle-team/drizzle-orm/issues/5343\n }),\n instanceMembers: r.many.instanceMembers({\n from: r.accounts.id,\n to: r.instanceMembers.accountId,\n where: {\n accepted: { isNotNull: true },\n },\n }),\n sessions: r.many.sessions({\n from: r.accounts.id,\n to: r.sessions.accountId,\n }),\n loginChallenges: r.many.loginChallenges({\n from: r.accounts.id,\n to: r.loginChallenges.accountId,\n }),\n },\n instanceMembers: {\n account: r.one.accounts({\n from: r.instanceMembers.accountId,\n to: r.accounts.id,\n }),\n instance: r.one.instances({\n from: r.instanceMembers.instanceId,\n to: r.instances.id,\n }),\n },\n instances: {\n activityDeliveries: r.many.activityDeliveries({\n from: r.instances.id,\n to: r.activityDeliveries.instanceId,\n }),\n members: r.many.accounts({\n from: r.instances.id.through(r.instanceMembers.instanceId),\n to: r.accounts.id.through(r.instanceMembers.accountId),\n // Drizzle ORM currently does not support many-to-many relationships with\n // additional filters on the junction table. So we need to specify\n // filter `accepted IS NOT NULL` everywhere we query for members of\n // an instance (sigh). See also the below issue:\n // https://github.com/drizzle-team/drizzle-orm/issues/5343\n }),\n instanceMembers: r.many.instanceMembers({\n from: r.instances.id,\n to: r.instanceMembers.instanceId,\n where: {\n accepted: { isNotNull: true },\n },\n }),\n actors: r.many.actors({\n from: r.instances.id,\n to: r.actors.instanceId,\n where: { deleted: { isNull: true } },\n }),\n localInstance: r.one.localInstances({\n from: r.instances.localId,\n to: r.localInstances.id,\n }),\n },\n localInstances: {\n instance: r.one.instances({\n from: r.localInstances.id,\n to: r.instances.localId,\n }),\n },\n sessions: {\n account: r.one.accounts({\n from: r.sessions.accountId,\n to: r.accounts.id,\n optional: false,\n }),\n },\n loginChallenges: {\n account: r.one.accounts({\n from: r.loginChallenges.accountId,\n to: r.accounts.id,\n optional: false,\n }),\n },\n resources: {\n actor: r.one.actors({\n from: r.resources.id,\n to: r.actors.id,\n optional: true,\n }),\n object: r.one.objects({\n from: r.resources.id,\n to: r.objects.id,\n optional: true,\n }),\n activity: r.one.activities({\n from: r.resources.id,\n to: r.activities.id,\n optional: true,\n }),\n collection: r.one.collections({\n from: r.resources.id,\n to: r.collections.id,\n optional: true,\n }),\n addressedBy: r.many.addressing({\n from: r.resources.id,\n to: r.addressing.targetId,\n }),\n },\n addressing: {\n source: r.one.resources({\n from: r.addressing.sourceId,\n to: r.resources.id,\n optional: false,\n }),\n targetResource: r.one.resources({\n from: r.addressing.targetId,\n to: r.resources.id,\n optional: false,\n }),\n },\n actorCollectionReferences: {\n actor: r.one.actors({\n from: r.actorCollectionReferences.actorId,\n to: r.actors.id,\n optional: false,\n }),\n collection: r.one.collections({\n from: r.actorCollectionReferences.collectionId,\n to: r.collections.id,\n optional: false,\n }),\n },\n collections: {\n resource: r.one.resources({\n from: r.collections.id,\n to: r.resources.id,\n optional: false,\n }),\n ownerActor: r.one.actors({\n from: r.collections.ownerActorId,\n to: r.actors.id,\n }),\n items: r.many.collectionItems({\n from: r.collections.id,\n to: r.collectionItems.collectionId,\n }),\n },\n collectionItems: {\n collection: r.one.collections({\n from: r.collectionItems.collectionId,\n to: r.collections.id,\n optional: false,\n }),\n item: r.one.resources({\n from: r.collectionItems.itemId,\n to: r.resources.id,\n optional: false,\n }),\n },\n activities: {\n resource: r.one.resources({\n from: r.activities.id,\n to: r.resources.id,\n optional: false,\n }),\n actor: r.one.actors({\n from: r.activities.actorId,\n to: r.actors.id,\n optional: false,\n }),\n object: r.one.resources({\n from: r.activities.objectId,\n to: r.resources.id,\n }),\n addressing: r.many.addressing({\n from: r.activities.id,\n to: r.addressing.sourceId,\n }),\n deliveries: r.many.activityDeliveries({\n from: r.activities.id,\n to: r.activityDeliveries.activityId,\n }),\n },\n objects: {\n resource: r.one.resources({\n from: r.objects.id,\n to: r.resources.id,\n optional: false,\n }),\n addressing: r.many.addressing({\n from: r.objects.id,\n to: r.addressing.sourceId,\n }),\n activities: r.many.activities({\n from: r.objects.id,\n to: r.activities.objectId,\n }),\n actor: r.one.actors({\n from: r.objects.actorId,\n to: r.actors.id,\n optional: false,\n }),\n },\n actors: {\n activityDeliveryLinks: r.many.activityDeliveryActors({\n from: r.actors.id,\n to: r.activityDeliveryActors.actorId,\n }),\n collectionReferences: r.many.actorCollectionReferences({\n from: r.actors.id,\n to: r.actorCollectionReferences.actorId,\n }),\n resource: r.one.resources({\n from: r.actors.id,\n to: r.resources.id,\n optional: false,\n }),\n collections: r.many.collections({\n from: r.actors.id,\n to: r.collections.ownerActorId,\n }),\n activities: r.many.activities({\n from: r.actors.id,\n to: r.activities.actorId,\n }),\n objects: r.many.objects({\n from: r.actors.id,\n to: r.objects.actorId,\n where: { deleted: { isNull: true } },\n }),\n instance: r.one.instances({\n from: r.actors.instanceId,\n to: r.instances.id,\n optional: false,\n }),\n localActor: r.one.localActors({\n from: r.actors.localId,\n to: r.localActors.id,\n }),\n },\n localActors: {\n actor: r.one.actors({ from: r.localActors.id, to: r.actors.localId }),\n },\n}));\n\nexport default relations;\n"],"mappings":";;;AAoBA,MAAa,YAAY,gBAAgBA,iBAAS,OAAO;CACvD,MAAM,EACJ,UAAU,EAAE,KAAK,YAAY;EAAE,MAAM,EAAE,KAAK;EAAI,IAAI,EAAE,YAAY;CAAM,CAAC,EAC3E;CACA,aAAa;EACX,KAAK,EAAE,IAAI,KAAK;GACd,MAAM,EAAE,YAAY;GACpB,IAAI,EAAE,KAAK;GACX,UAAU;EACZ,CAAC;EACD,oBAAoB,EAAE,KAAK,mBAAmB;GAC5C,MAAM,EAAE,YAAY;GACpB,IAAI,EAAE,mBAAmB;EAC3B,CAAC;CACH;CACA,oBAAoB;EAClB,UAAU,EAAE,IAAI,UAAU;GACxB,MAAM,EAAE,mBAAmB;GAC3B,IAAI,EAAE,UAAU;GAChB,UAAU;EACZ,CAAC;EACD,OAAO,EAAE,IAAI,OAAO;GAClB,MAAM,EAAE,mBAAmB;GAC3B,IAAI,EAA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,EAAE"}
1
+ {"version":3,"file":"relations.mjs","names":["schema"],"sources":["../src/relations.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 { defineRelations } from \"drizzle-orm\";\n\nimport * as schema from \"./schema.ts\";\n\nexport const relations = defineRelations(schema, (r) => ({\n resourceRevisions: {\n resource: r.one.resources({\n from: r.resourceRevisions.resourceId,\n to: r.resources.id,\n optional: false,\n }),\n addressing: r.many.revisionAddressing({\n from: r.resourceRevisions.id,\n to: r.revisionAddressing.revisionId,\n }),\n relations: r.many.revisionRelations({\n from: r.resourceRevisions.id,\n to: r.revisionRelations.revisionId,\n }),\n receipts: r.many.revisionReceipts({\n from: r.resourceRevisions.id,\n to: r.revisionReceipts.revisionId,\n }),\n },\n resourceHeads: {\n resource: r.one.resources({\n from: r.resourceHeads.resourceId,\n to: r.resources.id,\n optional: false,\n }),\n revision: r.one.resourceRevisions({\n from: [r.resourceHeads.resourceId, r.resourceHeads.revisionId],\n to: [r.resourceRevisions.resourceId, r.resourceRevisions.id],\n optional: false,\n }),\n },\n revisionAddressing: {\n revision: r.one.resourceRevisions({\n from: r.revisionAddressing.revisionId,\n to: r.resourceRevisions.id,\n optional: false,\n }),\n },\n revisionRelations: {\n revision: r.one.resourceRevisions({\n from: r.revisionRelations.revisionId,\n to: r.resourceRevisions.id,\n optional: false,\n }),\n },\n revisionReceipts: {\n revision: r.one.resourceRevisions({\n from: r.revisionReceipts.revisionId,\n to: r.resourceRevisions.id,\n optional: false,\n }),\n delivery: r.one.activityDeliveries({\n from: r.revisionReceipts.deliveryId,\n to: r.activityDeliveries.id,\n optional: false,\n }),\n },\n keys: {\n versions: r.many.keyVersions({ from: r.keys.id, to: r.keyVersions.keyId }),\n },\n keyVersions: {\n key: r.one.keys({\n from: r.keyVersions.keyId,\n to: r.keys.id,\n optional: false,\n }),\n activityDeliveries: r.many.activityDeliveries({\n from: r.keyVersions.id,\n to: r.activityDeliveries.verificationKeyId,\n }),\n },\n activityDeliveries: {\n revisionReceipts: r.many.revisionReceipts({\n from: r.activityDeliveries.id,\n to: r.revisionReceipts.deliveryId,\n }),\n instance: r.one.instances({\n from: r.activityDeliveries.instanceId,\n to: r.instances.id,\n optional: false,\n }),\n actor: r.one.actors({\n from: r.activityDeliveries.actorId,\n to: r.actors.id,\n where: { deleted: { isNull: true } },\n }),\n actorLinks: r.many.activityDeliveryActors({\n from: r.activityDeliveries.id,\n to: r.activityDeliveryActors.deliveryId,\n }),\n verificationKey: r.one.keyVersions({\n from: r.activityDeliveries.verificationKeyId,\n to: r.keyVersions.id,\n }),\n attempts: r.many.activityDeliveryAttempts({\n from: r.activityDeliveries.id,\n to: r.activityDeliveryAttempts.deliveryId,\n }),\n activity: r.one.activities({\n from: r.activityDeliveries.activityId,\n to: r.activities.id,\n }),\n },\n activityDeliveryAttempts: {\n delivery: r.one.activityDeliveries({\n from: r.activityDeliveryAttempts.deliveryId,\n to: r.activityDeliveries.id,\n optional: false,\n }),\n },\n activityDeliveryActors: {\n delivery: r.one.activityDeliveries({\n from: r.activityDeliveryActors.deliveryId,\n to: r.activityDeliveries.id,\n optional: false,\n }),\n actor: r.one.actors({\n from: r.activityDeliveryActors.actorId,\n to: r.actors.id,\n optional: false,\n }),\n collections: r.many.activityDeliveryActorCollections({\n from: [\n r.activityDeliveryActors.deliveryId,\n r.activityDeliveryActors.actorId,\n ],\n to: [\n r.activityDeliveryActorCollections.deliveryId,\n r.activityDeliveryActorCollections.actorId,\n ],\n }),\n },\n activityDeliveryActorCollections: {\n actorLink: r.one.activityDeliveryActors({\n from: [\n r.activityDeliveryActorCollections.deliveryId,\n r.activityDeliveryActorCollections.actorId,\n ],\n to: [\n r.activityDeliveryActors.deliveryId,\n r.activityDeliveryActors.actorId,\n ],\n optional: false,\n }),\n },\n accounts: {\n instances: r.many.instances({\n from: r.accounts.id.through(r.instanceMembers.accountId),\n to: r.instances.id.through(r.instanceMembers.instanceId),\n // Drizzle ORM currently does not support many-to-many relationships with\n // additional filters on the junction table. So we need to specify\n // filter `accepted IS NOT NULL` everywhere we query for instances of\n // an account (sigh). See also the below issue:\n // https://github.com/drizzle-team/drizzle-orm/issues/5343\n }),\n instanceMembers: r.many.instanceMembers({\n from: r.accounts.id,\n to: r.instanceMembers.accountId,\n where: {\n accepted: { isNotNull: true },\n },\n }),\n sessions: r.many.sessions({\n from: r.accounts.id,\n to: r.sessions.accountId,\n }),\n loginChallenges: r.many.loginChallenges({\n from: r.accounts.id,\n to: r.loginChallenges.accountId,\n }),\n },\n instanceMembers: {\n account: r.one.accounts({\n from: r.instanceMembers.accountId,\n to: r.accounts.id,\n }),\n instance: r.one.instances({\n from: r.instanceMembers.instanceId,\n to: r.instances.id,\n }),\n },\n instances: {\n activityDeliveries: r.many.activityDeliveries({\n from: r.instances.id,\n to: r.activityDeliveries.instanceId,\n }),\n members: r.many.accounts({\n from: r.instances.id.through(r.instanceMembers.instanceId),\n to: r.accounts.id.through(r.instanceMembers.accountId),\n // Drizzle ORM currently does not support many-to-many relationships with\n // additional filters on the junction table. So we need to specify\n // filter `accepted IS NOT NULL` everywhere we query for members of\n // an instance (sigh). See also the below issue:\n // https://github.com/drizzle-team/drizzle-orm/issues/5343\n }),\n instanceMembers: r.many.instanceMembers({\n from: r.instances.id,\n to: r.instanceMembers.instanceId,\n where: {\n accepted: { isNotNull: true },\n },\n }),\n actors: r.many.actors({\n from: r.instances.id,\n to: r.actors.instanceId,\n where: { deleted: { isNull: true } },\n }),\n localInstance: r.one.localInstances({\n from: r.instances.localId,\n to: r.localInstances.id,\n }),\n },\n localInstances: {\n instance: r.one.instances({\n from: r.localInstances.id,\n to: r.instances.localId,\n }),\n },\n sessions: {\n account: r.one.accounts({\n from: r.sessions.accountId,\n to: r.accounts.id,\n optional: false,\n }),\n },\n loginChallenges: {\n account: r.one.accounts({\n from: r.loginChallenges.accountId,\n to: r.accounts.id,\n optional: false,\n }),\n },\n resources: {\n revisions: r.many.resourceRevisions({\n from: r.resources.id,\n to: r.resourceRevisions.resourceId,\n }),\n head: r.one.resourceHeads({\n from: r.resources.id,\n to: r.resourceHeads.resourceId,\n }),\n actor: r.one.actors({\n from: r.resources.id,\n to: r.actors.id,\n optional: true,\n }),\n object: r.one.objects({\n from: r.resources.id,\n to: r.objects.id,\n optional: true,\n }),\n activity: r.one.activities({\n from: r.resources.id,\n to: r.activities.id,\n optional: true,\n }),\n collection: r.one.collections({\n from: r.resources.id,\n to: r.collections.id,\n optional: true,\n }),\n addressedBy: r.many.addressing({\n from: r.resources.id,\n to: r.addressing.targetId,\n }),\n },\n addressing: {\n source: r.one.resources({\n from: r.addressing.sourceId,\n to: r.resources.id,\n optional: false,\n }),\n targetResource: r.one.resources({\n from: r.addressing.targetId,\n to: r.resources.id,\n optional: false,\n }),\n },\n actorCollectionReferences: {\n actor: r.one.actors({\n from: r.actorCollectionReferences.actorId,\n to: r.actors.id,\n optional: false,\n }),\n collection: r.one.collections({\n from: r.actorCollectionReferences.collectionId,\n to: r.collections.id,\n optional: false,\n }),\n },\n collections: {\n resource: r.one.resources({\n from: r.collections.id,\n to: r.resources.id,\n optional: false,\n }),\n ownerActor: r.one.actors({\n from: r.collections.ownerActorId,\n to: r.actors.id,\n }),\n items: r.many.collectionItems({\n from: r.collections.id,\n to: r.collectionItems.collectionId,\n }),\n },\n collectionItems: {\n collection: r.one.collections({\n from: r.collectionItems.collectionId,\n to: r.collections.id,\n optional: false,\n }),\n item: r.one.resources({\n from: r.collectionItems.itemId,\n to: r.resources.id,\n optional: false,\n }),\n },\n activities: {\n resource: r.one.resources({\n from: r.activities.id,\n to: r.resources.id,\n optional: false,\n }),\n actor: r.one.actors({\n from: r.activities.actorId,\n to: r.actors.id,\n optional: false,\n }),\n object: r.one.resources({\n from: r.activities.objectId,\n to: r.resources.id,\n }),\n addressing: r.many.addressing({\n from: r.activities.id,\n to: r.addressing.sourceId,\n }),\n deliveries: r.many.activityDeliveries({\n from: r.activities.id,\n to: r.activityDeliveries.activityId,\n }),\n },\n objects: {\n resource: r.one.resources({\n from: r.objects.id,\n to: r.resources.id,\n optional: false,\n }),\n addressing: r.many.addressing({\n from: r.objects.id,\n to: r.addressing.sourceId,\n }),\n activities: r.many.activities({\n from: r.objects.id,\n to: r.activities.objectId,\n }),\n actor: r.one.actors({\n from: r.objects.actorId,\n to: r.actors.id,\n optional: false,\n }),\n },\n actors: {\n activityDeliveryLinks: r.many.activityDeliveryActors({\n from: r.actors.id,\n to: r.activityDeliveryActors.actorId,\n }),\n collectionReferences: r.many.actorCollectionReferences({\n from: r.actors.id,\n to: r.actorCollectionReferences.actorId,\n }),\n resource: r.one.resources({\n from: r.actors.id,\n to: r.resources.id,\n optional: false,\n }),\n collections: r.many.collections({\n from: r.actors.id,\n to: r.collections.ownerActorId,\n }),\n activities: r.many.activities({\n from: r.actors.id,\n to: r.activities.actorId,\n }),\n objects: r.many.objects({\n from: r.actors.id,\n to: r.objects.actorId,\n where: { deleted: { isNull: true } },\n }),\n instance: r.one.instances({\n from: r.actors.instanceId,\n to: r.instances.id,\n optional: false,\n }),\n localActor: r.one.localActors({\n from: r.actors.localId,\n to: r.localActors.id,\n }),\n },\n localActors: {\n actor: r.one.actors({ from: r.localActors.id, to: r.actors.localId }),\n },\n}));\n\nexport default relations;\n"],"mappings":";;;AAoBA,MAAa,YAAY,gBAAgBA,iBAAS,OAAO;CACvD,mBAAmB;EACjB,UAAU,EAAE,IAAI,UAAU;GACxB,MAAM,EAAE,kBAAkB;GAC1B,IAAI,EAAE,UAAU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O;GACf,IAAI,EAAE,UAAU;GAChB,UAAU;EACZ,CAAC;EACD,aAAa,EAAE,KAAK,YAAY;GAC9B,MAAM,EAAE,OAAO;GACf,IAAI,EAAE,YAAY;EACpB,CAAC;EACD,YAAY,EAAE,KAAK,WAAW;GAC5B,MAAM,EAAE,OAAO;GACf,IAAI,EAAE,WAAW;EACnB,CAAC;EACD,SAAS,EAAE,KAAK,QAAQ;GACtB,MAAM,EAAE,OAAO;GACf,IAAI,EAAE,QAAQ;GACd,OAAO,EAAE,SAAS,EAAE,QAAQ,KAAK,EAAE;EACrC,CAAC;EACD,UAAU,EAAE,IAAI,UAAU;GACxB,MAAM,EAAE,OAAO;GACf,IAAI,EAAE,UAAU;GAChB,UAAU;EACZ,CAAC;EACD,YAAY,EAAE,IAAI,YAAY;GAC5B,MAAM,EAAE,OAAO;GACf,IAAI,EAAE,YAAY;EACpB,CAAC;CACH;CACA,aAAa,EACX,OAAO,EAAE,IAAI,OAAO;EAAE,MAAM,EAAE,YAAY;EAAI,IAAI,EAAE,OAAO;CAAQ,CAAC,EACtE;AACF,EAAE"}
@@ -0,0 +1,103 @@
1
+ import { J as RevisionAddressing, X as RevisionRelation, q as ResourceRevision, r as Transaction, t as Database } from "./db-BBw4F4HU.mjs";
2
+ import { t as Uuid } from "./uuid-CKMzlIND.mjs";
3
+ import { AddressingInput } from "./resource.mjs";
4
+ //#region src/revision-conflict-error.d.ts
5
+ /** The caller's expected current revision no longer matches the database. */
6
+ declare class RevisionConflictError extends Error {
7
+ readonly resourceId: Uuid;
8
+ readonly expectedRevisionId: Uuid | null;
9
+ readonly actualRevisionId: Uuid | null;
10
+ constructor(resourceId: Uuid, expectedRevisionId: Uuid | null, actualRevisionId: Uuid | null);
11
+ }
12
+ //#endregion
13
+ //#region src/legacy-resource-revision-error.d.ts
14
+ /** Legacy typed rows require the coordinated application adapter in #152. */
15
+ declare class LegacyResourceRevisionError extends Error {
16
+ readonly resourceId: Uuid;
17
+ constructor(resourceId: Uuid);
18
+ }
19
+ //#endregion
20
+ //#region src/resource-revision-state-error.d.ts
21
+ /** A requested state transition would change a saved activity or revive a deletion. */
22
+ declare class ResourceRevisionStateError extends Error {
23
+ readonly code: "activity-immutable" | "deleted" | "initial-whiteout";
24
+ constructor(code: "activity-immutable" | "deleted" | "initial-whiteout");
25
+ }
26
+ //#endregion
27
+ //#region src/legacy-resource-revision.d.ts
28
+ /**
29
+ * Captures fully written legacy typed state within its creating transaction.
30
+ * This trusted compatibility operation performs no authorization or fetching.
31
+ * Repeated calls return the original revision only when the typed state agrees.
32
+ * @returns The first retained revision ID, including an unavailable snapshot.
33
+ * @throws {LegacyResourceRevisionError} When typed state cannot be captured.
34
+ */
35
+ declare function captureLegacyResourceRevision(tx: Transaction, resourceId: Uuid): Promise<Uuid>;
36
+ //#endregion
37
+ //#region src/resource-revision.d.ts
38
+ /** A value representable by JSON, without implicit coercion. */
39
+ type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
40
+ readonly [property: string]: JsonValue;
41
+ };
42
+ type JsonObject = {
43
+ readonly [property: string]: JsonValue;
44
+ };
45
+ /** A semantic adapter's relation projection; no JSON-LD interpretation occurs here. */
46
+ interface RevisionRelationInput {
47
+ readonly property: string;
48
+ readonly path?: readonly (string | number)[] | null;
49
+ readonly representation: RevisionRelation["representation"];
50
+ readonly targetIri?: string | null;
51
+ }
52
+ interface AppendBase {
53
+ readonly resourceId: Uuid;
54
+ readonly resourceKind: "object" | "activity";
55
+ /** Null requires that the resource has no current revision. */
56
+ readonly expectedRevisionId: Uuid | null;
57
+ }
58
+ type AppendResourceRevisionInput = AppendBase & ({
59
+ readonly kind: "snapshot";
60
+ readonly document: JsonObject;
61
+ readonly capture: ResourceRevision["capture"];
62
+ readonly addressing?: AddressingInput;
63
+ readonly relations?: readonly RevisionRelationInput[];
64
+ readonly projection?: ResourceRevision["projection"];
65
+ } | {
66
+ readonly kind: "whiteout";
67
+ readonly deleted: Temporal.Instant;
68
+ readonly formerTypes: readonly string[];
69
+ });
70
+ /** Protected local JSON and projections, not an authorized or wire representation. */
71
+ interface StoredResourceRevision extends ResourceRevision {
72
+ readonly addressing: readonly RevisionAddressing[];
73
+ readonly relations: readonly RevisionRelation[];
74
+ }
75
+ /**
76
+ * Appends one current object version or saved activity, atomically with projections.
77
+ * The caller must validate the document and authorize the write. Lock multiple
78
+ * canonical IRIs in sorted order before composing several appends in one transaction.
79
+ * This does not publish, change collection membership, or reserve delivery.
80
+ * @returns The stored revision, including protected blind addressing.
81
+ */
82
+ declare function appendResourceRevision(db: Database | Transaction, input: AppendResourceRevisionInput): Promise<StoredResourceRevision>;
83
+ /**
84
+ * Loads protected local JSON without applying authorization or stripping bto/bcc.
85
+ * @returns The immutable revision and projections, or null if not found.
86
+ */
87
+ declare function loadResourceRevision(db: Database | Transaction, revisionId: Uuid): Promise<StoredResourceRevision | null>;
88
+ /**
89
+ * Loads current protected local state without dereferencing any document target.
90
+ * @returns A snapshot, unavailable record or whiteout, or null when unversioned.
91
+ */
92
+ declare function loadCurrentResourceRevision(db: Database | Transaction, resourceId: Uuid): Promise<StoredResourceRevision | null>;
93
+ /**
94
+ * Lists protected history in descending sequence order; authorization belongs to callers.
95
+ * @returns Up to limit revisions strictly before beforeSequence, when supplied.
96
+ */
97
+ declare function listResourceRevisions(db: Database | Transaction, resourceId: Uuid, options?: {
98
+ readonly beforeSequence?: number;
99
+ readonly limit?: number;
100
+ }): Promise<StoredResourceRevision[]>;
101
+ //#endregion
102
+ export { StoredResourceRevision as a, loadCurrentResourceRevision as c, ResourceRevisionStateError as d, LegacyResourceRevisionError as f, RevisionRelationInput as i, loadResourceRevision as l, JsonObject as n, appendResourceRevision as o, RevisionConflictError as p, JsonValue as r, listResourceRevisions as s, AppendResourceRevisionInput as t, captureLegacyResourceRevision as u };
103
+ //# sourceMappingURL=resource-revision-BuG5kUlA.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-revision-BuG5kUlA.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;;;;KCUC,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;WACb,qBAAqB;WACrB,aAAa;;WAGb;WACA,SAAS,SAAS;WAClB;;;UAKA,+BAA+B;WACrC,qBAAqB;WACrB,oBAAoB;;;;;;;;;iBA6ZT,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"}
@@ -0,0 +1,313 @@
1
+ import { activities, addressingPropertyEnum, objects, resourceHeads, resourceRevisionCaptureEnum, resourceRevisionProjectionEnum, resourceRevisions, resources, revisionAddressing, revisionRelations } from "./schema.mjs";
2
+ import { areUuidsEqual, uuidV7, validateUuid } from "./uuid.mjs";
3
+ import { ResourceKindConflictError } from "./resource.mjs";
4
+ import { storableText } from "./text.mjs";
5
+ import { and, desc, eq, inArray, lt, sql } from "drizzle-orm";
6
+ //#region src/legacy-resource-revision-error.ts
7
+ /** Legacy typed rows require the coordinated application adapter in #152. */
8
+ var LegacyResourceRevisionError = class extends Error {
9
+ resourceId;
10
+ constructor(resourceId) {
11
+ super("Legacy typed state requires coordinated capture and must agree with retained history.");
12
+ this.resourceId = resourceId;
13
+ this.name = "LegacyResourceRevisionError";
14
+ }
15
+ };
16
+ //#endregion
17
+ //#region src/resource-revision-state-error.ts
18
+ /** A requested state transition would change a saved activity or revive a deletion. */
19
+ var ResourceRevisionStateError = class extends Error {
20
+ code;
21
+ constructor(code) {
22
+ super(`Unsupported resource revision transition: ${code}.`);
23
+ this.code = code;
24
+ this.name = "ResourceRevisionStateError";
25
+ }
26
+ };
27
+ //#endregion
28
+ //#region src/revision-conflict-error.ts
29
+ /** The caller's expected current revision no longer matches the database. */
30
+ var RevisionConflictError = class extends Error {
31
+ resourceId;
32
+ expectedRevisionId;
33
+ actualRevisionId;
34
+ constructor(resourceId, expectedRevisionId, actualRevisionId) {
35
+ super("The resource's current revision has changed.");
36
+ this.resourceId = resourceId;
37
+ this.expectedRevisionId = expectedRevisionId;
38
+ this.actualRevisionId = actualRevisionId;
39
+ this.name = "RevisionConflictError";
40
+ }
41
+ };
42
+ //#endregion
43
+ //#region src/legacy-resource-revision.ts
44
+ /**
45
+ * Captures fully written legacy typed state within its creating transaction.
46
+ * This trusted compatibility operation performs no authorization or fetching.
47
+ * Repeated calls return the original revision only when the typed state agrees.
48
+ * @returns The first retained revision ID, including an unavailable snapshot.
49
+ * @throws {LegacyResourceRevisionError} When typed state cannot be captured.
50
+ */
51
+ async function captureLegacyResourceRevision(tx, resourceId) {
52
+ try {
53
+ const [row] = await tx.select({ id: sql`drfed_capture_legacy_resource(${resourceId}::uuid, false)` }).from(sql`(VALUES (1)) AS capture_input(value)`);
54
+ if (row === void 0) throw new Error("Legacy capture returned no revision.");
55
+ return row.id;
56
+ } catch (error) {
57
+ let detail = error;
58
+ while (detail instanceof Error) {
59
+ if ("constraint" in detail && detail.constraint === "resource_revisions_legacy_guard" || "constraint_name" in detail && detail.constraint_name === "resource_revisions_legacy_guard") throw new LegacyResourceRevisionError(resourceId);
60
+ detail = detail.cause;
61
+ }
62
+ throw error;
63
+ }
64
+ }
65
+ //#endregion
66
+ //#region src/resource-revision.ts
67
+ function text(value) {
68
+ if (typeof value !== "string" || !storableText(value)) throw new TypeError("A projection must contain losslessly storable text.");
69
+ }
70
+ function jsonKeys(value) {
71
+ const prototype = Object.getPrototypeOf(value);
72
+ if (Array.isArray(value) ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) throw new TypeError("JSON objects must be plain records.");
73
+ const result = [];
74
+ for (const key of Reflect.ownKeys(value)) {
75
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
76
+ if (typeof key !== "string" || descriptor === void 0 || !("value" in descriptor)) throw new TypeError("JSON values cannot contain symbol keys or accessors.");
77
+ if (Array.isArray(value) && key === "length") continue;
78
+ if (!descriptor.enumerable) throw new TypeError("JSON members must be enumerable.");
79
+ if (Array.isArray(value) && (!/^(?:0|[1-9][0-9]*)$/u.test(key) || Number(key) >= value.length)) throw new TypeError("JSON arrays cannot contain named properties.");
80
+ result.push(key);
81
+ }
82
+ return result;
83
+ }
84
+ function json(value, ancestors = /* @__PURE__ */ new Set()) {
85
+ if (value === null) return "null";
86
+ if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
87
+ if (typeof value === "number") {
88
+ if (!Number.isFinite(value)) throw new TypeError("JSON numbers must be finite.");
89
+ return Object.is(value, -0) ? "-0" : JSON.stringify(value);
90
+ }
91
+ if (typeof value !== "object" || ancestors.has(value)) throw new TypeError("Expected an acyclic JSON value without coercion.");
92
+ const keys = jsonKeys(value);
93
+ ancestors.add(value);
94
+ try {
95
+ if (Array.isArray(value)) return `[${Array.from(value, (entry) => json(entry, ancestors)).join(",")}]`;
96
+ return `{${keys.map((key) => `${JSON.stringify(key)}:${json(Object.getOwnPropertyDescriptor(value, key).value, ancestors)}`).join(",")}}`;
97
+ } finally {
98
+ ancestors.delete(value);
99
+ }
100
+ }
101
+ function projectionRows(input = {}) {
102
+ const rows = [];
103
+ for (const property of Object.keys(input)) if (!addressingPropertyEnum.enumValues.includes(property)) throw new TypeError("Unknown addressing projection property.");
104
+ for (const property of addressingPropertyEnum.enumValues) {
105
+ const values = input[property];
106
+ if (values === void 0) continue;
107
+ if (!Array.isArray(values)) throw new TypeError("Addressing projections must be arrays.");
108
+ for (const [position, iri] of values.entries()) {
109
+ text(iri);
110
+ rows.push({
111
+ property,
112
+ position,
113
+ iri
114
+ });
115
+ }
116
+ }
117
+ return rows;
118
+ }
119
+ function relationRows(input = []) {
120
+ if (!Array.isArray(input)) throw new TypeError("Relation projections must be arrays.");
121
+ return input.map((relation, occurrence) => {
122
+ text(relation.property);
123
+ const targetIri = relation.targetIri ?? null;
124
+ if (targetIri !== null) text(targetIri);
125
+ if (![
126
+ "reference",
127
+ "embedded",
128
+ "link"
129
+ ].includes(relation.representation) || relation.representation === "reference" && targetIri === null) throw new TypeError("Invalid relation representation.");
130
+ const path = relation.path ?? null;
131
+ if (path !== null && (!Array.isArray(path) || Array.from(path).some((part) => typeof part !== "string" && !(Number.isSafeInteger(part) && part >= 0)))) throw new TypeError("A relation path must contain field names and nonnegative indexes.");
132
+ return {
133
+ occurrence,
134
+ property: relation.property,
135
+ representation: relation.representation,
136
+ targetIri,
137
+ path: path === null ? null : [...path]
138
+ };
139
+ });
140
+ }
141
+ async function current(db, resourceId) {
142
+ const [row] = await db.select({ revision: resourceRevisions }).from(resourceHeads).innerJoin(resourceRevisions, and(eq(resourceHeads.resourceId, resourceRevisions.resourceId), eq(resourceHeads.revisionId, resourceRevisions.id))).where(eq(resourceHeads.resourceId, resourceId)).limit(1);
143
+ return row?.revision ?? null;
144
+ }
145
+ async function hydrate(db, revision) {
146
+ const [addressing, relations] = await Promise.all([db.select().from(revisionAddressing).where(eq(revisionAddressing.revisionId, revision.id)).orderBy(revisionAddressing.property, revisionAddressing.position), db.select().from(revisionRelations).where(eq(revisionRelations.revisionId, revision.id)).orderBy(revisionRelations.occurrence)]);
147
+ return {
148
+ ...revision,
149
+ addressing,
150
+ relations
151
+ };
152
+ }
153
+ function prepareSnapshot(input) {
154
+ if (input.document === null || typeof input.document !== "object" || Array.isArray(input.document)) throw new TypeError("A new resource document must be a JSON object.");
155
+ const projection = input.projection ?? "partial";
156
+ if (!resourceRevisionCaptureEnum.enumValues.includes(input.capture) || !resourceRevisionProjectionEnum.enumValues.includes(projection)) throw new TypeError("Invalid capture or projection category.");
157
+ return {
158
+ kind: "snapshot",
159
+ serialized: json(input.document),
160
+ capture: input.capture,
161
+ projection,
162
+ addressing: projectionRows(input.addressing),
163
+ relations: relationRows(input.relations),
164
+ deleted: null,
165
+ formerTypes: null
166
+ };
167
+ }
168
+ function prepareWhiteout(input) {
169
+ if (!(input.deleted instanceof Temporal.Instant) || !Array.isArray(input.formerTypes)) throw new TypeError("Expected a deletion instant and former type array.");
170
+ const formerTypes = [...input.formerTypes];
171
+ for (const type of formerTypes) text(type);
172
+ return {
173
+ kind: "whiteout",
174
+ serialized: null,
175
+ capture: void 0,
176
+ projection: void 0,
177
+ addressing: [],
178
+ relations: [],
179
+ deleted: input.deleted,
180
+ formerTypes
181
+ };
182
+ }
183
+ function prepareRevision(input) {
184
+ const { resourceId, resourceKind, expectedRevisionId } = input;
185
+ if (!validateUuid(resourceId) || expectedRevisionId !== null && !validateUuid(expectedRevisionId)) throw new TypeError("Expected canonical resource and revision UUIDs.");
186
+ if (resourceKind !== "object" && resourceKind !== "activity") throw new TypeError("Unsupported resource kind.");
187
+ if (input.kind === "snapshot") return {
188
+ resourceId,
189
+ resourceKind,
190
+ expectedRevisionId,
191
+ ...prepareSnapshot(input)
192
+ };
193
+ if (input.kind === "whiteout") return {
194
+ resourceId,
195
+ resourceKind,
196
+ expectedRevisionId,
197
+ ...prepareWhiteout(input)
198
+ };
199
+ throw new TypeError("Unsupported revision kind.");
200
+ }
201
+ async function lockRevisionTarget(tx, input) {
202
+ const { resourceId, resourceKind, expectedRevisionId, kind } = input;
203
+ const [resource] = await tx.select().from(resources).where(eq(resources.id, resourceId)).for("no key update");
204
+ if (resource === void 0) throw new Error("The canonical resource is not registered.");
205
+ const previous = await current(tx, resourceId);
206
+ if (!(previous === null ? expectedRevisionId === null : expectedRevisionId !== null && areUuidsEqual(previous.id, expectedRevisionId))) throw new RevisionConflictError(resourceId, expectedRevisionId, previous?.id ?? null);
207
+ const [legacyObject, legacyActivity] = await Promise.all([tx.select({ id: objects.id }).from(objects).where(eq(objects.id, resourceId)).limit(1), tx.select({ id: activities.id }).from(activities).where(eq(activities.id, resourceId)).limit(1)]);
208
+ if (legacyObject.length > 0 || legacyActivity.length > 0) throw new LegacyResourceRevisionError(resourceId);
209
+ if (resource.kind !== "unknown" && resource.kind !== resourceKind) throw new ResourceKindConflictError(resource.iri, resource.kind, resourceKind);
210
+ if (previous !== null && resourceKind === "activity") throw new ResourceRevisionStateError("activity-immutable");
211
+ if (previous?.kind === "whiteout") throw new ResourceRevisionStateError("deleted");
212
+ if (kind === "whiteout" && previous === null) throw new ResourceRevisionStateError("initial-whiteout");
213
+ if (resource.kind === "unknown") await tx.update(resources).set({ kind: resourceKind }).where(eq(resources.id, resourceId));
214
+ return previous;
215
+ }
216
+ async function appendPrepared(tx, input) {
217
+ const previous = await lockRevisionTarget(tx, input);
218
+ const { resourceId, kind, serialized, capture, projection, deleted, formerTypes, addressing, relations } = input;
219
+ const id = uuidV7();
220
+ const [revision] = await tx.insert(resourceRevisions).values({
221
+ id,
222
+ resourceId,
223
+ sequence: (previous?.sequence ?? 0) + 1,
224
+ kind,
225
+ capture: capture ?? previous.capture,
226
+ projection: projection ?? previous.projection,
227
+ document: serialized === null ? null : sql`${serialized}::json`,
228
+ deleted,
229
+ formerTypes
230
+ }).returning();
231
+ if (revision === void 0) throw new Error("Revision insertion returned no row.");
232
+ if (kind === "whiteout") {
233
+ const inherited = await hydrate(tx, previous);
234
+ addressing.push(...inherited.addressing.map(({ revisionId: _revisionId, ...row }) => row));
235
+ relations.push(...inherited.relations.map(({ revisionId: _revisionId, ...row }) => row));
236
+ }
237
+ if (addressing.length > 0) await tx.insert(revisionAddressing).values(addressing.map((row) => ({
238
+ ...row,
239
+ revisionId: id
240
+ })));
241
+ if (relations.length > 0) await tx.insert(revisionRelations).values(relations.map((row) => ({
242
+ ...row,
243
+ revisionId: id
244
+ })));
245
+ if (previous === null) await tx.insert(resourceHeads).values({
246
+ resourceId,
247
+ revisionId: id
248
+ });
249
+ else await tx.update(resourceHeads).set({ revisionId: id }).where(eq(resourceHeads.resourceId, resourceId));
250
+ return await hydrate(tx, revision);
251
+ }
252
+ /**
253
+ * Appends one current object version or saved activity, atomically with projections.
254
+ * The caller must validate the document and authorize the write. Lock multiple
255
+ * canonical IRIs in sorted order before composing several appends in one transaction.
256
+ * This does not publish, change collection membership, or reserve delivery.
257
+ * @returns The stored revision, including protected blind addressing.
258
+ */
259
+ async function appendResourceRevision(db, input) {
260
+ const prepared = prepareRevision(input);
261
+ return await db.transaction((tx) => appendPrepared(tx, prepared));
262
+ }
263
+ /**
264
+ * Loads protected local JSON without applying authorization or stripping bto/bcc.
265
+ * @returns The immutable revision and projections, or null if not found.
266
+ */
267
+ async function loadResourceRevision(db, revisionId) {
268
+ const [revision] = await db.select().from(resourceRevisions).where(eq(resourceRevisions.id, revisionId)).limit(1);
269
+ return revision === void 0 ? null : await hydrate(db, revision);
270
+ }
271
+ /**
272
+ * Loads current protected local state without dereferencing any document target.
273
+ * @returns A snapshot, unavailable record or whiteout, or null when unversioned.
274
+ */
275
+ async function loadCurrentResourceRevision(db, resourceId) {
276
+ const revision = await current(db, resourceId);
277
+ return revision === null ? null : await hydrate(db, revision);
278
+ }
279
+ const MAX_HISTORY_LIMIT = 100;
280
+ const DEFAULT_HISTORY_LIMIT = 20;
281
+ /**
282
+ * Lists protected history in descending sequence order; authorization belongs to callers.
283
+ * @returns Up to limit revisions strictly before beforeSequence, when supplied.
284
+ */
285
+ async function listResourceRevisions(db, resourceId, options = {}) {
286
+ const { beforeSequence, limit = DEFAULT_HISTORY_LIMIT } = options;
287
+ if (!Number.isInteger(limit) || limit < 1 || limit > MAX_HISTORY_LIMIT || beforeSequence !== void 0 && (!Number.isSafeInteger(beforeSequence) || beforeSequence < 1)) throw new RangeError("Invalid history bounds.");
288
+ const revisions = await db.select().from(resourceRevisions).where(and(eq(resourceRevisions.resourceId, resourceId), beforeSequence === void 0 ? void 0 : lt(resourceRevisions.sequence, beforeSequence))).orderBy(desc(resourceRevisions.sequence)).limit(limit);
289
+ if (revisions.length === 0) return [];
290
+ const revisionIds = revisions.map(({ id }) => id);
291
+ const [addressing, relations] = await Promise.all([db.select().from(revisionAddressing).where(inArray(revisionAddressing.revisionId, revisionIds)).orderBy(revisionAddressing.property, revisionAddressing.position), db.select().from(revisionRelations).where(inArray(revisionRelations.revisionId, revisionIds)).orderBy(revisionRelations.occurrence)]);
292
+ const addressingByRevision = /* @__PURE__ */ new Map();
293
+ for (const row of addressing) {
294
+ const rows = addressingByRevision.get(row.revisionId) ?? [];
295
+ rows.push(row);
296
+ addressingByRevision.set(row.revisionId, rows);
297
+ }
298
+ const relationsByRevision = /* @__PURE__ */ new Map();
299
+ for (const row of relations) {
300
+ const rows = relationsByRevision.get(row.revisionId) ?? [];
301
+ rows.push(row);
302
+ relationsByRevision.set(row.revisionId, rows);
303
+ }
304
+ return revisions.map((revision) => ({
305
+ ...revision,
306
+ addressing: addressingByRevision.get(revision.id) ?? [],
307
+ relations: relationsByRevision.get(revision.id) ?? []
308
+ }));
309
+ }
310
+ //#endregion
311
+ export { captureLegacyResourceRevision as a, LegacyResourceRevisionError as c, loadResourceRevision as i, listResourceRevisions as n, RevisionConflictError as o, loadCurrentResourceRevision as r, ResourceRevisionStateError as s, appendResourceRevision as t };
312
+
313
+ //# sourceMappingURL=resource-revision-DWg6et77.mjs.map