Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More
Socket
Book a DemoSign in
Socket

@xylabs/creatable

Package Overview
Dependencies
Maintainers
5
Versions
174
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xylabs/creatable

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

latest
Source
npmnpm
Version
5.0.100
Version published
Maintainers
5
Created
Source

@xylabs/creatable

npm license

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Install

Using npm:

npm install {{name}}

Using yarn:

yarn add {{name}}

Using pnpm:

pnpm add {{name}}

Using bun:

bun add {{name}}

License

See the LICENSE file for license rights and limitations (LGPL-3.0-only).

Reference

packages

creatable

### .temp-typedoc

  ### classes

    ### <a id="AbstractCreatable"></a>AbstractCreatable

@xylabs/creatable

Base class for objects that follow an asynchronous creation and lifecycle pattern. Instances must be created via the static create method rather than direct construction. Provides start/stop lifecycle management with status tracking and telemetry support.

Extends

  • BaseEmitter<Partial<TParams & RequiredCreatableParams>, TEventData>

Extended by

Type Parameters

TParams

TParams extends CreatableParams = CreatableParams

TEventData

TEventData extends EventData = EventData

Constructors

Constructor

new AbstractCreatable<TParams, TEventData>(key, params): AbstractCreatable<TParams, TEventData>;

Parameters

key

unknown

params

Partial<TParams & RequiredCreatableParams>

Returns

AbstractCreatable<TParams, TEventData>

Overrides

BaseEmitter<Partial<TParams & RequiredCreatableParams>, TEventData>.constructor

Properties

defaultLogger?

static optional defaultLogger?: Logger;

Inherited from

BaseEmitter.defaultLogger

globalInstances

readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]>;

Inherited from

BaseEmitter.globalInstances

globalInstancesCountHistory

readonly static globalInstancesCountHistory: Record<BaseClassName, number[]>;

Inherited from

BaseEmitter.globalInstancesCountHistory

defaultLogger?

optional defaultLogger?: Logger;

Optional default logger for this instance.

_startPromise

protected _startPromise: Promisable<boolean> | undefined;

eventData

eventData: TEventData;

Type-level reference to the event data shape for external type queries.

Inherited from

BaseEmitter.eventData

Accessors

historyInterval

Get Signature

get static historyInterval(): number;

Returns

number

Set Signature

set static historyInterval(value): void;

Parameters

value

number

Returns

void

Inherited from

BaseEmitter.historyInterval

historyTime

Get Signature

get static historyTime(): number;

Returns

number

Set Signature

set static historyTime(value): void;

Parameters

value

number

Returns

void

Inherited from

BaseEmitter.historyTime

maxGcFrequency

Get Signature

get static maxGcFrequency(): number;

Returns

number

Set Signature

set static maxGcFrequency(value): void;

Parameters

value

number

Returns

void

Inherited from

BaseEmitter.maxGcFrequency

maxHistoryDepth

Get Signature

get static maxHistoryDepth(): number;

Returns

number

Inherited from

BaseEmitter.maxHistoryDepth

logger

Get Signature

get logger(): Logger | undefined;

Returns

Logger | undefined

Inherited from

BaseEmitter.logger

meter

Get Signature

get meter(): Meter | undefined;

Returns

Meter | undefined

Inherited from

BaseEmitter.meter

tracer

Get Signature

get tracer(): Tracer | undefined;

Returns

Tracer | undefined

Inherited from

BaseEmitter.tracer

name

Get Signature

get name(): CreatableName;

The name identifier for this creatable instance.

Returns

CreatableName

params

Get Signature

get params(): TParams & RequiredCreatableParams<void>;

The validated and merged parameters for this instance.

Returns

TParams & RequiredCreatableParams<void>

Overrides

BaseEmitter.params

startable

Get Signature

get startable(): boolean;

Whether this instance can be started (must be in 'created' or 'stopped' status).

Returns

boolean

status

Get Signature

get status(): CreatableStatus | null;

The current lifecycle status of this instance, or null if not yet initialized.

Returns

CreatableStatus | null

statusReporter

Get Signature

get statusReporter(): 
  | CreatableStatusReporter<void>
  | undefined;

The status reporter used to broadcast lifecycle changes.

Returns

| CreatableStatusReporter<void> | undefined

Methods

gc()

Call Signature

static gc(force?): void;

Parameters

force?

boolean

Returns

void

Inherited from

BaseEmitter.gc

Call Signature

static gc(className): void;

Parameters

className

BaseClassName

Returns

void

Inherited from

BaseEmitter.gc

instanceCount()

static instanceCount(className): number;

Parameters

className

BaseClassName

Returns

number

Inherited from

BaseEmitter.instanceCount

instanceCounts()

static instanceCounts(): Record<BaseClassName, number>;

Returns

Record<BaseClassName, number>

Inherited from

BaseEmitter.instanceCounts

startHistory()

static startHistory(): void;

Returns

void

Inherited from

BaseEmitter.startHistory

stopHistory()

static stopHistory(): void;

Returns

void

Inherited from

BaseEmitter.stopHistory

create()

static create<T>(this, inParams?): Promise<T>;

Asynchronously creates a new instance by processing params, constructing, and running both static and instance createHandlers.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

inParams?

Partial<T["params"]> = {}

Optional partial parameters to configure the instance

Returns

Promise<T>

The fully initialized instance

createHandler()

static createHandler<T>(this, instance): Promisable<T>;

Static hook called during creation to perform additional initialization. Override in subclasses to customize post-construction setup.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

instance

T

The newly constructed instance

Returns

Promisable<T>

The instance, potentially modified

paramsHandler()

static paramsHandler<T>(this, params?): Promisable<T["params"]>;

Static hook called during creation to validate and transform params. Override in subclasses to add default values or validation.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

params?

Partial<T["params"]> = {}

The raw partial params provided to create

Returns

Promisable<T["params"]>

The processed params ready for construction

createHandler()

createHandler(): Promisable<void>;

Instance-level creation hook. Override in subclasses to perform setup after construction.

Returns

Promisable<void>

paramsValidator()

paramsValidator(params): TParams & RequiredCreatableParams<void>;

Validates and returns the merged params, ensuring required fields are present. Override in subclasses to add custom validation logic.

Parameters

params

Partial<TParams & RequiredCreatableParams>

The raw partial params to validate

Returns

TParams & RequiredCreatableParams<void>

The validated params

span()

span<T>(name, fn): T;

Executes a function within a telemetry span.

Type Parameters

T

T

Parameters

name

string

The span name

fn

() => T

The function to execute within the span

Returns

T

spanAsync()

spanAsync<T>(
   name, 
   fn, 
config?): Promise<T>;

Executes an async function within a telemetry span.

Type Parameters

T

T

Parameters

name

string

The span name

fn

() => Promise<T>

The async function to execute within the span

config?

SpanConfig = {}

Optional span configuration

Returns

Promise<T>

start()

start(): Promise<boolean>;

Starts the instance, transitioning through 'starting' to 'started' status. Thread-safe via mutex. Returns true if already started or started successfully.

Returns

Promise<boolean>

started()

started(notStartedAction?): boolean;

Checks whether this instance is currently started. Takes an action if not started, based on the notStartedAction parameter.

Parameters

notStartedAction?

"error" | "throw" | "warn" | "log" | "none"

What to do if not started: 'error'/'throw' throws, 'warn'/'log' logs, 'none' is silent

Returns

boolean

True if started, false otherwise

startedAsync()

startedAsync(notStartedAction?, tryStart?): Promise<boolean>;

Async version of started that can optionally auto-start the instance.

Parameters

notStartedAction?

"error" | "throw" | "warn" | "log" | "none"

What to do if not started and auto-start is disabled

tryStart?

boolean = true

If true, attempts to start the instance automatically

Returns

Promise<boolean>

True if the instance is or becomes started

stop()

stop(): Promise<boolean>;

Stops the instance, transitioning through 'stopping' to 'stopped' status. Thread-safe via mutex. Returns true if already stopped or stopped successfully.

Returns

Promise<boolean>

_noOverride()

protected _noOverride(functionName?): void;

Asserts that the given function has not been overridden in a subclass. Used to enforce the handler pattern (override startHandler not start).

Parameters

functionName?

string = ...

Returns

void

setStatus()

Call Signature

protected setStatus(value, progress?): void;

Sets the lifecycle status and reports it via the status reporter.

Parameters

value

"creating" | "created" | "starting" | "started" | "stopping" | "stopped"

progress?

number

Returns

void

Call Signature

protected setStatus(value, error?): void;

Sets the lifecycle status and reports it via the status reporter.

Parameters

value

"error"

error?

Error

Returns

void

startHandler()

protected startHandler(): Promisable<void>;

Override in subclasses to define start behavior. Throw an error on failure.

Returns

Promisable<void>

stopHandler()

protected stopHandler(): Promisable<void>;

Override in subclasses to define stop behavior. Throw an error on failure.

Returns

Promisable<void>

clearListeners()

clearListeners(eventNames): this;

Removes all listeners for the specified event name(s).

Parameters

eventNames

keyof TEventData | keyof TEventData[]

One or more event names to clear listeners for.

Returns

this

This instance for chaining.

Inherited from

BaseEmitter.clearListeners

emit()

emit<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;

Emits an event, invoking all registered listeners concurrently.

Type Parameters

TEventName

TEventName extends string | number | symbol = keyof TEventData

TEventArgs

TEventArgs extends EventArgs = TEventData[TEventName]

Parameters

eventName

TEventName

The event to emit.

eventArgs

TEventArgs

The data to pass to listeners.

Returns

Promise<void>

Inherited from

BaseEmitter.emit

emitSerial()

emitSerial<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;

Emits an event, invoking all registered listeners sequentially in order.

Type Parameters

TEventName

TEventName extends string | number | symbol = keyof TEventData

TEventArgs

TEventArgs extends EventArgs = TEventData[TEventName]

Parameters

eventName

TEventName

The event to emit.

eventArgs

TEventArgs

The data to pass to listeners.

Returns

Promise<void>

Inherited from

BaseEmitter.emitSerial

listenerCount()

listenerCount(eventNames): number;

Returns the total number of listeners registered for the specified event name(s).

Parameters

eventNames

keyof TEventData | keyof TEventData[]

One or more event names to count listeners for.

Returns

number

The total listener count.

Inherited from

BaseEmitter.listenerCount

off()

off<TEventName>(eventNames, listener): void;

Removes a specific listener from the specified event name(s).

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventNames

TEventName | TEventName[]

One or more event names to unsubscribe from.

listener

EventListener<TEventData[TEventName]>

The listener to remove.

Returns

void

Inherited from

BaseEmitter.off

offAny()

offAny(listener): void;

Removes a wildcard listener that was receiving all events.

Parameters

listener

EventAnyListener

The wildcard listener to remove.

Returns

void

Inherited from

BaseEmitter.offAny

on()

on<TEventName>(eventNames, listener): () => void;

Subscribes a listener to the specified event name(s).

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventNames

TEventName | TEventName[]

One or more event names to listen for.

listener

EventListener<TEventData[TEventName]>

The callback to invoke when the event fires.

Returns

An unsubscribe function.

() => void

Inherited from

BaseEmitter.on

onAny()

onAny(listener): () => void;

Subscribes a wildcard listener that receives all events.

Parameters

listener

EventAnyListener

The callback to invoke for any event.

Returns

An unsubscribe function.

() => void

Inherited from

BaseEmitter.onAny

once()

once<TEventName>(eventName, listener): () => void;

Subscribes a listener that will be invoked only once for the specified event, then automatically removed.

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventName

TEventName

The event to listen for.

listener

EventListener<TEventData[TEventName]>

The callback to invoke once.

Returns

An unsubscribe function.

() => void

Inherited from

BaseEmitter.once
    ### <a id="AbstractCreatableWithFactory"></a>AbstractCreatableWithFactory

@xylabs/creatable

Extends AbstractCreatable with a static factory method for creating pre-configured CreatableFactory instances.

Extends

Type Parameters

TParams

TParams extends CreatableParams = CreatableParams

TEventData

TEventData extends EventData = EventData

Constructors

Constructor

new AbstractCreatableWithFactory<TParams, TEventData>(key, params): AbstractCreatableWithFactory<TParams, TEventData>;

Parameters

key

unknown

params

Partial<TParams & RequiredCreatableParams>

Returns

AbstractCreatableWithFactory<TParams, TEventData>

Inherited from

AbstractCreatable.constructor

Properties

defaultLogger?

static optional defaultLogger?: Logger;

Inherited from

AbstractCreatable.defaultLogger

globalInstances

readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]>;

Inherited from

AbstractCreatable.globalInstances

globalInstancesCountHistory

readonly static globalInstancesCountHistory: Record<BaseClassName, number[]>;

Inherited from

AbstractCreatable.globalInstancesCountHistory

defaultLogger?

optional defaultLogger?: Logger;

Optional default logger for this instance.

Inherited from

AbstractCreatable.defaultLogger

_startPromise

protected _startPromise: Promisable<boolean> | undefined;

Inherited from

AbstractCreatable._startPromise

eventData

eventData: TEventData;

Type-level reference to the event data shape for external type queries.

Inherited from

AbstractCreatable.eventData

Accessors

historyInterval

Get Signature

get static historyInterval(): number;

Returns

number

Set Signature

set static historyInterval(value): void;

Parameters

value

number

Returns

void

Inherited from

AbstractCreatable.historyInterval

historyTime

Get Signature

get static historyTime(): number;

Returns

number

Set Signature

set static historyTime(value): void;

Parameters

value

number

Returns

void

Inherited from

AbstractCreatable.historyTime

maxGcFrequency

Get Signature

get static maxGcFrequency(): number;

Returns

number

Set Signature

set static maxGcFrequency(value): void;

Parameters

value

number

Returns

void

Inherited from

AbstractCreatable.maxGcFrequency

maxHistoryDepth

Get Signature

get static maxHistoryDepth(): number;

Returns

number

Inherited from

AbstractCreatable.maxHistoryDepth

logger

Get Signature

get logger(): Logger | undefined;

Returns

Logger | undefined

Inherited from

AbstractCreatable.logger

meter

Get Signature

get meter(): Meter | undefined;

Returns

Meter | undefined

Inherited from

AbstractCreatable.meter

tracer

Get Signature

get tracer(): Tracer | undefined;

Returns

Tracer | undefined

Inherited from

AbstractCreatable.tracer

name

Get Signature

get name(): CreatableName;

The name identifier for this creatable instance.

Returns

CreatableName

Inherited from

AbstractCreatable.name

params

Get Signature

get params(): TParams & RequiredCreatableParams<void>;

The validated and merged parameters for this instance.

Returns

TParams & RequiredCreatableParams<void>

Inherited from

AbstractCreatable.params

startable

Get Signature

get startable(): boolean;

Whether this instance can be started (must be in 'created' or 'stopped' status).

Returns

boolean

Inherited from

AbstractCreatable.startable

status

Get Signature

get status(): CreatableStatus | null;

The current lifecycle status of this instance, or null if not yet initialized.

Returns

CreatableStatus | null

Inherited from

AbstractCreatable.status

statusReporter

Get Signature

get statusReporter(): 
  | CreatableStatusReporter<void>
  | undefined;

The status reporter used to broadcast lifecycle changes.

Returns

| CreatableStatusReporter<void> | undefined

Inherited from

AbstractCreatable.statusReporter

Methods

gc()

Call Signature

static gc(force?): void;

Parameters

force?

boolean

Returns

void

Inherited from

AbstractCreatable.gc

Call Signature

static gc(className): void;

Parameters

className

BaseClassName

Returns

void

Inherited from

AbstractCreatable.gc

instanceCount()

static instanceCount(className): number;

Parameters

className

BaseClassName

Returns

number

Inherited from

AbstractCreatable.instanceCount

instanceCounts()

static instanceCounts(): Record<BaseClassName, number>;

Returns

Record<BaseClassName, number>

Inherited from

AbstractCreatable.instanceCounts

startHistory()

static startHistory(): void;

Returns

void

Inherited from

AbstractCreatable.startHistory

stopHistory()

static stopHistory(): void;

Returns

void

Inherited from

AbstractCreatable.stopHistory

create()

static create<T>(this, inParams?): Promise<T>;

Asynchronously creates a new instance by processing params, constructing, and running both static and instance createHandlers.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

inParams?

Partial<T["params"]> = {}

Optional partial parameters to configure the instance

Returns

Promise<T>

The fully initialized instance

Inherited from

AbstractCreatable.create

createHandler()

static createHandler<T>(this, instance): Promisable<T>;

Static hook called during creation to perform additional initialization. Override in subclasses to customize post-construction setup.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

instance

T

The newly constructed instance

Returns

Promisable<T>

The instance, potentially modified

Inherited from

AbstractCreatable.createHandler

paramsHandler()

static paramsHandler<T>(this, params?): Promisable<T["params"]>;

Static hook called during creation to validate and transform params. Override in subclasses to add default values or validation.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

params?

Partial<T["params"]> = {}

The raw partial params provided to create

Returns

Promisable<T["params"]>

The processed params ready for construction

Inherited from

AbstractCreatable.paramsHandler

createHandler()

createHandler(): Promisable<void>;

Instance-level creation hook. Override in subclasses to perform setup after construction.

Returns

Promisable<void>

Inherited from

AbstractCreatable.createHandler

paramsValidator()

paramsValidator(params): TParams & RequiredCreatableParams<void>;

Validates and returns the merged params, ensuring required fields are present. Override in subclasses to add custom validation logic.

Parameters

params

Partial<TParams & RequiredCreatableParams>

The raw partial params to validate

Returns

TParams & RequiredCreatableParams<void>

The validated params

Inherited from

AbstractCreatable.paramsValidator

span()

span<T>(name, fn): T;

Executes a function within a telemetry span.

Type Parameters

T

T

Parameters

name

string

The span name

fn

() => T

The function to execute within the span

Returns

T

Inherited from

AbstractCreatable.span

spanAsync()

spanAsync<T>(
   name, 
   fn, 
config?): Promise<T>;

Executes an async function within a telemetry span.

Type Parameters

T

T

Parameters

name

string

The span name

fn

() => Promise<T>

The async function to execute within the span

config?

SpanConfig = {}

Optional span configuration

Returns

Promise<T>

Inherited from

AbstractCreatable.spanAsync

start()

start(): Promise<boolean>;

Starts the instance, transitioning through 'starting' to 'started' status. Thread-safe via mutex. Returns true if already started or started successfully.

Returns

Promise<boolean>

Inherited from

AbstractCreatable.start

started()

started(notStartedAction?): boolean;

Checks whether this instance is currently started. Takes an action if not started, based on the notStartedAction parameter.

Parameters

notStartedAction?

"error" | "throw" | "warn" | "log" | "none"

What to do if not started: 'error'/'throw' throws, 'warn'/'log' logs, 'none' is silent

Returns

boolean

True if started, false otherwise

Inherited from

AbstractCreatable.started

startedAsync()

startedAsync(notStartedAction?, tryStart?): Promise<boolean>;

Async version of started that can optionally auto-start the instance.

Parameters

notStartedAction?

"error" | "throw" | "warn" | "log" | "none"

What to do if not started and auto-start is disabled

tryStart?

boolean = true

If true, attempts to start the instance automatically

Returns

Promise<boolean>

True if the instance is or becomes started

Inherited from

AbstractCreatable.startedAsync

stop()

stop(): Promise<boolean>;

Stops the instance, transitioning through 'stopping' to 'stopped' status. Thread-safe via mutex. Returns true if already stopped or stopped successfully.

Returns

Promise<boolean>

Inherited from

AbstractCreatable.stop

_noOverride()

protected _noOverride(functionName?): void;

Asserts that the given function has not been overridden in a subclass. Used to enforce the handler pattern (override startHandler not start).

Parameters

functionName?

string = ...

Returns

void

Inherited from

AbstractCreatable._noOverride

setStatus()

Call Signature

protected setStatus(value, progress?): void;

Sets the lifecycle status and reports it via the status reporter.

Parameters

value

"creating" | "created" | "starting" | "started" | "stopping" | "stopped"

progress?

number

Returns

void

Inherited from

AbstractCreatable.setStatus

Call Signature

protected setStatus(value, error?): void;

Sets the lifecycle status and reports it via the status reporter.

Parameters

value

"error"

error?

Error

Returns

void

Inherited from

AbstractCreatable.setStatus

startHandler()

protected startHandler(): Promisable<void>;

Override in subclasses to define start behavior. Throw an error on failure.

Returns

Promisable<void>

Inherited from

AbstractCreatable.startHandler

stopHandler()

protected stopHandler(): Promisable<void>;

Override in subclasses to define stop behavior. Throw an error on failure.

Returns

Promisable<void>

Inherited from

AbstractCreatable.stopHandler

factory()

static factory<T>(
   this, 
   params?, 
labels?): CreatableFactory<T>;

Creates a factory that produces instances of this class with pre-configured params and labels.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

params?

Partial<T["params"]>

Default parameters for instances created by the factory

labels?

Labels

Labels to assign to created instances

Returns

CreatableFactory<T>

clearListeners()

clearListeners(eventNames): this;

Removes all listeners for the specified event name(s).

Parameters

eventNames

keyof TEventData | keyof TEventData[]

One or more event names to clear listeners for.

Returns

this

This instance for chaining.

Inherited from

AbstractCreatable.clearListeners

emit()

emit<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;

Emits an event, invoking all registered listeners concurrently.

Type Parameters

TEventName

TEventName extends string | number | symbol = keyof TEventData

TEventArgs

TEventArgs extends EventArgs = TEventData[TEventName]

Parameters

eventName

TEventName

The event to emit.

eventArgs

TEventArgs

The data to pass to listeners.

Returns

Promise<void>

Inherited from

AbstractCreatable.emit

emitSerial()

emitSerial<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;

Emits an event, invoking all registered listeners sequentially in order.

Type Parameters

TEventName

TEventName extends string | number | symbol = keyof TEventData

TEventArgs

TEventArgs extends EventArgs = TEventData[TEventName]

Parameters

eventName

TEventName

The event to emit.

eventArgs

TEventArgs

The data to pass to listeners.

Returns

Promise<void>

Inherited from

AbstractCreatable.emitSerial

listenerCount()

listenerCount(eventNames): number;

Returns the total number of listeners registered for the specified event name(s).

Parameters

eventNames

keyof TEventData | keyof TEventData[]

One or more event names to count listeners for.

Returns

number

The total listener count.

Inherited from

AbstractCreatable.listenerCount

off()

off<TEventName>(eventNames, listener): void;

Removes a specific listener from the specified event name(s).

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventNames

TEventName | TEventName[]

One or more event names to unsubscribe from.

listener

EventListener<TEventData[TEventName]>

The listener to remove.

Returns

void

Inherited from

AbstractCreatable.off

offAny()

offAny(listener): void;

Removes a wildcard listener that was receiving all events.

Parameters

listener

EventAnyListener

The wildcard listener to remove.

Returns

void

Inherited from

AbstractCreatable.offAny

on()

on<TEventName>(eventNames, listener): () => void;

Subscribes a listener to the specified event name(s).

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventNames

TEventName | TEventName[]

One or more event names to listen for.

listener

EventListener<TEventData[TEventName]>

The callback to invoke when the event fires.

Returns

An unsubscribe function.

() => void

Inherited from

AbstractCreatable.on

onAny()

onAny(listener): () => void;

Subscribes a wildcard listener that receives all events.

Parameters

listener

EventAnyListener

The callback to invoke for any event.

Returns

An unsubscribe function.

() => void

Inherited from

AbstractCreatable.onAny

once()

once<TEventName>(eventName, listener): () => void;

Subscribes a listener that will be invoked only once for the specified event, then automatically removed.

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventName

TEventName

The event to listen for.

listener

EventListener<TEventData[TEventName]>

The callback to invoke once.

Returns

An unsubscribe function.

() => void

Inherited from

AbstractCreatable.once

    ### <a id="Factory"></a>Factory

@xylabs/creatable

A concrete factory that wraps a Creatable class with default parameters and labels. Instances are created by merging caller-provided params over the factory defaults.

Type Parameters

T

T extends CreatableInstance = CreatableInstance

Implements

Constructors

Constructor

new Factory<T>(
   creatable, 
   params?, 
labels?): Factory<T>;

Parameters

creatable

Creatable<T>

params?

Partial<T["params"]>

labels?

Labels = {}

Returns

Factory<T>

Properties

creatable

creatable: Creatable<T>;

The Creatable class this factory delegates creation to.

defaultParams?

optional defaultParams?: Partial<T["params"]>;

Default parameters merged into every create call.

labels?

optional labels?: Labels;

Labels identifying resources created by this factory.

Methods

withParams()

static withParams<T>(
   creatableModule, 
   params?, 
labels?): Factory<T>;

Creates a new Factory instance with the given default params and labels.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

creatableModule

Creatable<T>

The Creatable class to wrap

params?

Partial<T["params"]>

Default parameters for new instances

labels?

Labels = {}

Labels to assign to created instances

Returns

Factory<T>

create()

create(params?): Promise<T>;

Creates a new instance, merging the provided params over the factory defaults.

Parameters

params?

Partial<T["params"]>

Optional parameters to override the factory defaults

Returns

Promise<T>

Implementation of

CreatableFactory.create

  ### functions

    ### <a id="creatable"></a>creatable

@xylabs/creatable

function creatable<T>(): <U>(constructor) => void;

Class annotation to be used to decorate Modules which support an asynchronous creation pattern

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Returns

The decorated Module requiring it implement the members of the CreatableModule as statics properties/methods

<U>(constructor) => void

    ### <a id="creatableFactory"></a>creatableFactory

@xylabs/creatable

function creatableFactory(): <U>(constructor) => void;

Class annotation to be used to decorate Modules which support an asynchronous creation factory pattern

Returns

The decorated Module requiring it implement the members of the CreatableModule as statics properties/methods

<U>(constructor) => void

    ### <a id="hasAllLabels"></a>hasAllLabels

@xylabs/creatable

function hasAllLabels(source?, required?): boolean;

Returns true if the source object has all the labels from the required set

Parameters

source?

Labels

Source object to check against

required?

Labels

Set of labels to check for in source

Returns

boolean

True of the source object has all the labels from the required set

  ### interfaces

    ### <a id="Creatable"></a>Creatable

@xylabs/creatable

Static interface for classes that support asynchronous creation. Provides the create, createHandler, and paramsHandler static methods used to construct instances through the creatable lifecycle.

Extended by

Type Parameters

T

T extends CreatableInstance = CreatableInstance

Constructors

Constructor

new Creatable(key, params): T & AbstractCreatable<T["params"], EventData>;

Constructs a new raw instance. Should not be called directly; use create instead.

Parameters

key

unknown

params

Partial<CreatableParams>

Returns

T & AbstractCreatable<T["params"], EventData>

Properties

defaultLogger?

optional defaultLogger?: Logger;

Optional default logger shared across instances created by this class.

Methods

create()

create<T>(this, params?): Promise<T>;

Asynchronously creates and initializes a new instance with the given params.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

params?

Partial<T["params"]>

Returns

Promise<T>

createHandler()

createHandler<T>(this, instance): Promisable<T>;

Hook called after construction to perform additional initialization on the instance.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

instance

T

Returns

Promisable<T>

paramsHandler()

paramsHandler<T>(this, params?): Promisable<T["params"] & RequiredCreatableParams<void>>;

Hook called to validate and transform params before instance construction.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

params?

Partial<T["params"]>

Returns

Promisable<T["params"] & RequiredCreatableParams<void>>

    ### <a id="CreatableFactory"></a>CreatableFactory

@xylabs/creatable

A factory interface for creating instances of a Creatable with pre-configured parameters. Unlike the full Creatable, this only exposes the create method.

Extends

  • Omit<Creatable<T>, | "create" | "createHandler" | "paramsHandler" | "defaultLogger" | "factory">

Type Parameters

T

T extends CreatableInstance = CreatableInstance

Methods

create()

create(this, params?): Promise<T>;

Creates a new instance, merging the provided params with the factory's defaults.

Parameters

this

CreatableFactory<T>

params?

Partial<T["params"]>

Returns

Promise<T>

    ### <a id="CreatableInstance"></a>CreatableInstance

@xylabs/creatable

Represents a created instance with a managed lifecycle (start/stop) and event emission.

Extends

  • EventEmitter<TEventData>

Type Parameters

TParams

TParams extends CreatableParams = CreatableParams

TEventData

TEventData extends EventData = EventData

Properties

eventData

eventData: TEventData;

The event data type associated with this instance.

Overrides

EventEmitter.eventData

name

name: CreatableName;

The name identifier for this instance.

params

params: TParams;

The parameters used to configure this instance.

start

start: () => Promise<boolean>;

Starts the instance. Resolves to true if started successfully.

Returns

Promise<boolean>

stop

stop: () => Promise<boolean>;

Stops the instance. Resolves to true if stopped successfully.

Returns

Promise<boolean>

Methods

clearListeners()

clearListeners(eventNames): void;

Removes all listeners for the specified event name(s).

Parameters

eventNames

keyof TEventData | keyof TEventData[]

Returns

void

Inherited from

EventEmitter.clearListeners

emit()

emit<TEventName>(eventName, eventArgs): Promise<void>;

Emits an event, invoking all registered listeners concurrently.

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventName

TEventName

eventArgs

TEventData[TEventName]

Returns

Promise<void>

Inherited from

EventEmitter.emit

emitSerial()

emitSerial<TEventName>(eventName, eventArgs): Promise<void>;

Emits an event, invoking all registered listeners sequentially in order.

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventName

TEventName

eventArgs

TEventData[TEventName]

Returns

Promise<void>

Inherited from

EventEmitter.emitSerial

listenerCount()

listenerCount(eventNames): number;

Returns the total number of listeners registered for the specified event name(s).

Parameters

eventNames

keyof TEventData | keyof TEventData[]

Returns

number

Inherited from

EventEmitter.listenerCount

off()

off<TEventName>(eventNames, listener): void;

Removes a specific listener from the specified event name(s).

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventNames

TEventName | TEventName[]

listener

EventListener<TEventData[TEventName]>

Returns

void

Inherited from

EventEmitter.off

offAny()

offAny(listener): void;

Removes a wildcard listener that was receiving all events.

Parameters

listener

Promise<void> | EventAnyListener

Returns

void

Inherited from

EventEmitter.offAny

on()

on<TEventName>(eventNames, listener): EventUnsubscribeFunction;

Subscribes a listener to the specified event name(s) and returns an unsubscribe function.

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventNames

TEventName | TEventName[]

listener

EventListener<TEventData[TEventName]>

Returns

EventUnsubscribeFunction

Inherited from

EventEmitter.on

onAny()

onAny(listener): EventUnsubscribeFunction;

Subscribes a wildcard listener that receives all events and returns an unsubscribe function.

Parameters

listener

EventAnyListener

Returns

EventUnsubscribeFunction

Inherited from

EventEmitter.onAny

once()

once<TEventName>(eventName, listener): EventUnsubscribeFunction;

Subscribes a listener that will be invoked only once for the specified event, then automatically removed.

Type Parameters

TEventName

TEventName extends string | number | symbol

Parameters

eventName

TEventName

listener

EventListener<TEventData[TEventName]>

Returns

EventUnsubscribeFunction

Inherited from

EventEmitter.once
    ### <a id="CreatableParams"></a>CreatableParams

@xylabs/creatable

Parameters for creating a creatable instance, combining required params with emitter params.

Extends

Properties

logger?

optional logger?: Logger;

Inherited from

RequiredCreatableParams.logger

meterProvider?

optional meterProvider?: MeterProvider;

Inherited from

RequiredCreatableParams.meterProvider

traceProvider?

optional traceProvider?: TracerProvider;

Inherited from

RequiredCreatableParams.traceProvider

name?

optional name?: CreatableName;

Optional name identifying this creatable instance.

Inherited from

RequiredCreatableParams.name

statusReporter?

optional statusReporter?: CreatableStatusReporter<void>;

Optional reporter for broadcasting status changes.

Inherited from

RequiredCreatableParams.statusReporter

    ### <a id="CreatableStatusReporter"></a>CreatableStatusReporter

@xylabs/creatable

Reports status changes for a creatable, supporting progress tracking and error reporting.

Type Parameters

TAdditionalStatus

TAdditionalStatus extends void | string = void

Methods

report()

Call Signature

report(
   name, 
   status, 
   progress): void;

Report a non-error status with a numeric progress value.

Parameters

name

BaseClassName

status

| "creating" | "created" | "starting" | "started" | "stopping" | "stopped" | Exclude<TAdditionalStatus extends void ? StandardCreatableStatus : TAdditionalStatus, "error">

progress

number

Returns

void

Call Signature

report(
   name, 
   status, 
   error): void;

Report an error status with the associated Error.

Parameters

name

BaseClassName

status

| "error" | Extract<TAdditionalStatus extends void ? StandardCreatableStatus : TAdditionalStatus, "error">

error

Error

Returns

void

Call Signature

report(name, status): void;

Report a status change without progress or error details.

Parameters

name

BaseClassName

status

CreatableStatus<TAdditionalStatus>

Returns

void

    ### <a id="CreatableWithFactory"></a>CreatableWithFactory

@xylabs/creatable

Extends Creatable with a factory method that produces pre-configured CreatableFactory instances.

Extends

Type Parameters

T

T extends CreatableInstance = CreatableInstance

Constructors

Constructor

new CreatableWithFactory(key, params): T & AbstractCreatable<T["params"], EventData>;

Constructs a new raw instance. Should not be called directly; use create instead.

Parameters

key

unknown

params

Partial<CreatableParams>

Returns

T & AbstractCreatable<T["params"], EventData>

Inherited from

Creatable.constructor

Properties

defaultLogger?

optional defaultLogger?: Logger;

Optional default logger shared across instances created by this class.

Inherited from

Creatable.defaultLogger

Methods

create()

create<T>(this, params?): Promise<T>;

Asynchronously creates and initializes a new instance with the given params.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

params?

Partial<T["params"]>

Returns

Promise<T>

Inherited from

Creatable.create

createHandler()

createHandler<T>(this, instance): Promisable<T>;

Hook called after construction to perform additional initialization on the instance.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

instance

T

Returns

Promisable<T>

Inherited from

Creatable.createHandler

paramsHandler()

paramsHandler<T>(this, params?): Promisable<T["params"] & RequiredCreatableParams<void>>;

Hook called to validate and transform params before instance construction.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

params?

Partial<T["params"]>

Returns

Promisable<T["params"] & RequiredCreatableParams<void>>

Inherited from

Creatable.paramsHandler

factory()

factory<T>(
   this, 
   params?, 
labels?): CreatableFactory<T>;

Creates a factory with the given default params and labels.

Type Parameters

T

T extends CreatableInstance<CreatableParams, EventData>

Parameters

this

Creatable<T>

params?

Partial<T["params"]>

labels?

Labels

Returns

CreatableFactory<T>

    ### <a id="RequiredCreatableParams"></a>RequiredCreatableParams

@xylabs/creatable

The minimum required parameters for constructing a creatable.

Extends

  • BaseEmitterParams

Extended by

Type Parameters

TAdditionalStatus

TAdditionalStatus extends CreatableStatus | void = void

Properties

logger?

optional logger?: Logger;

Inherited from

BaseEmitterParams.logger

meterProvider?

optional meterProvider?: MeterProvider;

Inherited from

BaseEmitterParams.meterProvider

traceProvider?

optional traceProvider?: TracerProvider;

Inherited from

BaseEmitterParams.traceProvider

name?

optional name?: CreatableName;

Optional name identifying this creatable instance.

statusReporter?

optional statusReporter?: CreatableStatusReporter<TAdditionalStatus>;

Optional reporter for broadcasting status changes.

    ### <a id="WithLabels"></a>WithLabels

@xylabs/creatable

Interface for objects that have labels.

Type Parameters

T

T extends Labels = Labels

Properties

labels

labels: T;
    ### <a id="WithOptionalLabels"></a>WithOptionalLabels

@xylabs/creatable

Interface for objects that have labels.

Type Parameters

T

T extends Labels = Labels

Properties

labels?

optional labels?: T;
  ### type-aliases

    ### <a id="CreatableName"></a>CreatableName

@xylabs/creatable

type CreatableName = Exclude<string, "creatable-name-reserved-32546239486"> & BaseClassName;

A branded string type used as the name identifier for creatables.

    ### <a id="CreatableStatus"></a>CreatableStatus

@xylabs/creatable

type CreatableStatus<TAdditionalStatus> = 
  | StandardCreatableStatus
  | TAdditionalStatus extends void ? StandardCreatableStatus : TAdditionalStatus;

A creatable's status, optionally extended with additional custom status values.

Type Parameters

TAdditionalStatus

TAdditionalStatus extends void | string = void

    ### <a id="Labels"></a>Labels

@xylabs/creatable

type Labels = Record<string, string | undefined>;

Object used to represent labels identifying a resource.

    ### <a id="StandardCreatableStatus"></a>StandardCreatableStatus

@xylabs/creatable

type StandardCreatableStatus = 
  | "creating"
  | "created"
  | "starting"
  | "started"
  | "stopping"
  | "stopped"
  | "error";

The standard lifecycle statuses a creatable can transition through.

FAQs

Package last updated on 22 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts