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.
Type Parameters
Section titled “Type Parameters”TSessionPrincipal
Section titled “TSessionPrincipal”TSessionPrincipal = any
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BaseCommand<
TSessionPrincipal>(sessionPrincipal?):BaseCommand<TSessionPrincipal>
Defined in: packages/ddd-core/application/base.command.ts:17
Parameters
Section titled “Parameters”sessionPrincipal?
Section titled “sessionPrincipal?”TSessionPrincipal
Returns
Section titled “Returns”BaseCommand<TSessionPrincipal>
Properties
Section titled “Properties”sessionPrincipal?
Section titled “sessionPrincipal?”
readonlyoptionalsessionPrincipal?:TSessionPrincipal
Defined in: packages/ddd-core/application/base.command.ts:14
sessionUser?
Section titled “sessionUser?”
readonlyoptionalsessionUser?:TSessionPrincipal
Defined in: packages/ddd-core/application/base.command.ts:15
Methods
Section titled “Methods”getUpdateFields()
Section titled “getUpdateFields()”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.
Parameters
Section titled “Parameters”updatableFields
Section titled “updatableFields”readonly string[]
Allowed updatable field names for this command.
Returns
Section titled “Returns”string[]
Only fields present in the current command payload.
Example
Section titled “Example”// updatableFields: the fields this command type declares updatable.const fields = command.getUpdateFields(updatableFields);authorizer.authorize('update', user, fields);toJSON()
Section titled “toJSON()”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.
Returns
Section titled “Returns”Record<string, unknown>
The command payload without pipeline/session metadata.