Skip to content

PersistedWrite

PersistedWrite<TEntity, TConstraint>(options?): <TResult>(target, key, descriptor) => void

Defined in: packages/ddd-core/persistence/decorators/persisted-write.decorator.ts:76

Applies the canonical persistence write lifecycle to a repository method whose first argument is the aggregate being written.

Equivalent to stacking, outermost to innermost: @Cache(options.cache) → @AcknowledgePersisted(...) → @MapPersistenceErrors(...), each selecting the first argument.

  • A rejected write translates known constraint errors, leaves the persisted version baseline unchanged and performs no cache maintenance.
  • A resolved write acknowledges the persisted version first, then runs best-effort cache maintenance.

It provides no transaction or event-delivery guarantee beyond those decorators: promise resolution must mean a durable autocommitted write. Use the individual decorators for other signatures, for writes that must not acknowledge (such as deletes), or for caller-owned ordering.

TEntity extends PersistedAggregate

TConstraint extends string = never

PersistedWriteOptions<TEntity, TConstraint> = {}

<TResult>(target, key, descriptor) => void

@PersistedWrite<User>({
cache: {
setKey: (user) => cacheKey(User.aggregateName, { id: user.id }),
invalidateKeys: (user) => [
cacheKey(User.aggregateName, { email: user.email }),
],
},
unique: { email: (user) => new UniqueEmailException(user) },
})
async save(user: User): Promise<UserSnapshot> { ... }