Module - ChangeLog
It will track insert, update and delete operations on your entities.
Once you have it setup, assign you the role ChangeLog.Admin
(You can get it via
Roles_ChangeLog.ChangeLog_Admin
), and in Admin UI, you will be able to see all changes in the
entity named FF Change Logs
.
Installation
Section titled “Installation”npm add firstly@latest -D
import { changelog } from 'firstly/changelog/server'
export const api = remultApi({ modules: [changelog()],})
The best practice is to create your decorator @APP_Entity
helper to wrap the @Entity
decorator.
import { Entity, isBackend, type EntityOptions } from 'remult'import { recordDeleted, recordSaved } from 'firstly/changeLog'
export function APP_Entity<entityType>( key: string, options?: EntityOptions< entityType extends new (...args: any) => any ? InstanceType<entityType> : entityType >,) { return Entity(key, { ...options,
// changesLogs saved: async (entity, e) => { await options?.saved?.(entity, e) if (options?.changeLog === false) { // Don't log changes } else { if (isBackend()) { await recordSaved(entity, e, options?.changeLog) } } }, deleted: async (entity, e) => { await options?.deleted?.(entity, e) if (options?.changeLog === false) { // Don't log changes } else { if (isBackend()) { await recordDeleted(entity, e, options?.changeLog) } } }, })}
Then, for any entity to opt-in change logs, you just need to use @APP_Entity
decorator.
For example:
-- @Entity('User')++ @APP_Entity('User')export class User { @Fields.string() name = ''}