Skip to content

@iamcalegari/mongoat / PluginContext

Interface: PluginContext<ModelType>

Defined in: src/types/plugin.ts:14

The sealed surface a plugin's setup() receives. Reading schema/ allowedMethods never exposes the live model reference — both are disconnected copies, so mutating them has no effect on the model being built. The only way a plugin can affect the model is through the three registration methods below (pre/post/static).

Type Parameters

ModelType

ModelType extends Document = Document

Properties

allowedMethods

readonly allowedMethods: readonly METHODS[]

Defined in: src/types/plugin.ts:16


collectionName

readonly collectionName: string

Defined in: src/types/plugin.ts:15


schema

readonly schema: Readonly<ModelValidationSchema>

Defined in: src/types/plugin.ts:17

Methods

post()

post<M>(method, fn, options?): void

Defined in: src/types/plugin.ts:34

Registers a post hook for method. fireAndForget follows the same semantics as the model's own .post() — the hook dispatch is not awaited and any rejection is routed to the model's onHookError instead of propagating to the caller.

Type Parameters

M

M extends METHODS

Parameters

method

M

fn

HookFn<HookContextMap<ModelType>[M]>

options?
fireAndForget?

boolean

Returns

void


pre()

pre<M>(method, fn): void

Defined in: src/types/plugin.ts:24

Registers a pre hook for method, appended after any hook already registered for the same method (declaration order is preserved across plugins and across the model's own config).

Type Parameters

M

M extends METHODS

Parameters

method

M

fn

HookFn<HookContextMap<ModelType>[M]>

Returns

void


static()

static(name, fn): void

Defined in: src/types/plugin.ts:47

Attaches fn as a method on the model under name. this inside fn is bound to the model instance, so escape-hatch/native methods (this.getCollection(), this.find(), ...) are available from within it. Colliding with a native model member — or with a static already registered by a different plugin — is rejected instead of silently overwritten.

Parameters

name

string

fn

(...args) => unknown

Returns

void