Skip to main content
Defined in: packages/common/src/library/library.ts:30 Base class for all NanoForge libraries.

Remarks

Extend this class to create a custom library, then register an instance with app.use(new MyLibrary()). A library owns its own context key (see defineLibraryKey), which is simultaneously its registry identity, its slot on Context, and the identifier used in dependencies/runBefore/ runAfter.

Example

Constructors

Constructor

new Library(relationships?): Library
Defined in: packages/common/src/library/library.ts:43

Parameters

relationships?
Partial<LibraryRelationships> Optional ordering overrides, keyed by other libraries’ key.

Returns

Library

Properties

key

abstract readonly key: string
Defined in: packages/common/src/library/library.ts:35 This library’s identity: its slot on Context, its registry key, and the identifier used to reference it in ordering relationships.

Accessors

relationships

Get Signature

get relationships(): LibraryRelationships
Defined in: packages/common/src/library/library.ts:51 Internal
Returns
LibraryRelationships

Methods

__clear()

__clear(_ctx): Promise<void>
Defined in: packages/common/src/library/library.ts:74 Called once after the tick loop stops.

Parameters

_ctx
Context

Returns

Promise<void>

__events()

__events(_ctx): Promise<void>
Defined in: packages/common/src/library/library.ts:66 Called every tick, in run order, whether or not the tick loop is paused — unlike __run. Use this for event/message draining that must not be affected by pause (e.g. listening for the command that resumes the loop), not for gameplay simulation.

Parameters

_ctx
Context

Returns

Promise<void>

__init()

__init(_ctx): Promise<void>
Defined in: packages/common/src/library/library.ts:57 Called once, in dependency order, before the tick loop starts.

Parameters

_ctx
InitContext

Returns

Promise<void>

__run()

__run(_ctx): Promise<void>
Defined in: packages/common/src/library/library.ts:70 Called every tick, in run order, while the tick loop is active and not paused.

Parameters

_ctx
Context

Returns

Promise<void>

expose()

expose(): unknown
Defined in: packages/common/src/library/library.ts:85 Returns this library’s public contribution to Context[this.key].

Returns

unknown

Remarks

Return a plain object exposing only what game code should be able to reach — never this — so internal state and lifecycle hooks never leak onto Context. Libraries with nothing to expose (headless libraries) can leave this unimplemented; they simply won’t appear on Context.

throwNotInitializedError()

protected throwNotInitializedError(): never
Defined in: packages/common/src/library/library.ts:89

Returns

never