@absolutejs/artifacts 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -108,6 +108,11 @@ normal migration workflow owns the four tables. Insert and select TypeBoxes
108
108
  generated directly from those tables are exported from the same entry point;
109
109
  hosts should reuse them instead of redefining database row schemas.
110
110
 
111
+ When a host owner is permanently deleted, call `artifacts.purgeOwner(ownerId)`.
112
+ The production store removes its current records, revisions, indexing state,
113
+ and outbox events in one transaction; orphaned asset bytes remain subject to
114
+ the package's history-aware garbage collector.
115
+
111
116
  ## File-backed artifact kinds
112
117
 
113
118
  Use the bundled definitions directly or compose them with application-specific
package/dist/drizzle.js CHANGED
@@ -216,6 +216,13 @@ var createDrizzleArtifactStore = (options) => ({
216
216
  if (events.length > 0)
217
217
  await transaction.insert(artifactEvents).values(eventRows(events));
218
218
  }),
219
+ purgeOwner: (ownerId) => options.db.transaction(async (transaction) => {
220
+ await transaction.delete(artifactIndexingStates).where(eq(artifactIndexingStates.ownerId, ownerId));
221
+ await transaction.delete(artifactEvents).where(eq(artifactEvents.ownerId, ownerId));
222
+ await transaction.delete(artifactRevisions).where(eq(artifactRevisions.ownerId, ownerId));
223
+ const deleted = await transaction.delete(artifactRecords).where(eq(artifactRecords.ownerId, ownerId)).returning({ id: artifactRecords.id });
224
+ return deleted.length;
225
+ }),
219
226
  save: (record, expectedRevision, events = []) => options.db.transaction(async (transaction) => {
220
227
  assertEventsBelongToArtifact(record, events);
221
228
  const updated = await transaction.update(artifactRecords).set(recordUpdate(record)).where(and(eq(artifactRecords.id, record.id), eq(artifactRecords.ownerId, record.ownerId), eq(artifactRecords.revision, expectedRevision))).returning({ id: artifactRecords.id });
package/dist/index.js CHANGED
@@ -471,6 +471,7 @@ var createArtifactService = (options) => {
471
471
  data: await options.assetStore.read(asset, { artifact })
472
472
  };
473
473
  },
474
+ purgeOwner: (ownerId) => options.store.purgeOwner(ownerId),
474
475
  restore: async (ownerId, artifactId, revision, expectedRevision) => {
475
476
  const current = await get(ownerId, artifactId);
476
477
  requireCapability(current, "edit");
@@ -680,6 +681,18 @@ var createMemoryArtifactStore = (initial = []) => {
680
681
  for (const event of newEvents)
681
682
  events.set(event.id, clone(event));
682
683
  },
684
+ purgeOwner: async (ownerId) => {
685
+ const artifactIds = [...records.values()].filter((record) => record.ownerId === ownerId).map((record) => record.id);
686
+ for (const artifactId of artifactIds) {
687
+ records.delete(artifactId);
688
+ revisions.delete(artifactId);
689
+ indexing.delete(artifactId);
690
+ }
691
+ for (const [eventId, event] of events)
692
+ if (event.ownerId === ownerId)
693
+ events.delete(eventId);
694
+ return artifactIds.length;
695
+ },
683
696
  save: async (record, expectedRevision, newEvents = []) => {
684
697
  const current = records.get(record.id);
685
698
  if (!current || current.ownerId !== record.ownerId || current.revision !== expectedRevision) {