Skip to content

BaseCommand

Defined in: packages/ddd-core/application/base.command.ts:13

Base class for application CQRS commands.

Encapsulates non-enumerable session/authentication metadata and reports which of a declared set of fields this command actually carries, via getUpdateFields.

TSessionPrincipal = any

new BaseCommand<TSessionPrincipal>(sessionPrincipal?): BaseCommand<TSessionPrincipal>

Defined in: packages/ddd-core/application/base.command.ts:17

TSessionPrincipal

BaseCommand<TSessionPrincipal>

readonly optional sessionPrincipal?: TSessionPrincipal

Defined in: packages/ddd-core/application/base.command.ts:14


readonly optional sessionUser?: TSessionPrincipal

Defined in: packages/ddd-core/application/base.command.ts:15

getUpdateFields(updatableFields): string[]

Defined in: packages/ddd-core/application/base.command.ts:57

Returns the declared updatable fields that are actually present on this command.

A field counts as present when its value is not undefined. null therefore counts as an intentional mutation, which is important for nullable fields such as clearing a department.

Use this with field-level authorization so the authorization surface is an explicit list owned by the command type.

readonly string[]

Allowed updatable field names for this command.

string[]

Only fields present in the current command payload.

// updatableFields: the fields this command type declares updatable.
const fields = command.getUpdateFields(updatableFields);
authorizer.authorize('update', user, fields);

toJSON(): Record<string, unknown>

Defined in: packages/ddd-core/application/base.command.ts:33

Serializes enumerable command payload fields to a plain object.

Non-enumerable metadata such as sessionPrincipal and sessionUser is excluded, and fields whose value is undefined are omitted. This makes the result suitable for stable cache/idempotency fingerprinting.

Record<string, unknown>

The command payload without pipeline/session metadata.