@xylabs/sdk-js

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
sdk
### .temp-typedoc
### classes
### <a id="AbstractCreatable"></a>AbstractCreatable
@xylabs/sdk-js
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
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.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
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/sdk-js
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
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="ApiClient"></a>ApiClient
@xylabs/sdk-js
Abstract base class for API clients that provides stage and token configuration.
Constructors
Constructor
new ApiClient(token?, stage?): ApiClient;
Parameters
token?
string | null
stage?
ApiStage
Returns
ApiClient
Properties
stage?
protected optional stage?: ApiStage;
token?
protected optional token?: string | null;
Methods
endPoint()
abstract endPoint(): string;
Returns
string
### <a id="ApiEndpoint"></a>ApiEndpoint
@xylabs/sdk-js
Generic REST API endpoint wrapper that supports fetching and inserting typed data.
Type Parameters
T
T
The type of data returned by the endpoint
Constructors
Constructor
new ApiEndpoint<T>(config, path): ApiEndpoint<T>;
Parameters
config
ApiConfig
path
string
Returns
ApiEndpoint<T>
Accessors
value
Get Signature
get value(): T | undefined;
Returns
T | undefined
Methods
fetch()
fetch(): Promise<T>;
Returns
Promise<T>
get()
get(): Promise<T | NonNullable<T>>;
Returns
Promise<T | NonNullable<T>>
insert()
insert(value): Promise<T>;
Parameters
value
T
Returns
Promise<T>
### <a id="AxiosJson"></a>AxiosJson
@xylabs/sdk-js
Deprecated
use axiosJsonConfig instead
Extends
Constructors
Constructor
new AxiosJson(config?): AxiosJson;
Parameters
config?
RawAxiosJsonRequestConfig
Returns
AxiosJson
Overrides
Axios.constructor
Methods
axiosConfig()
static axiosConfig(config?): RawAxiosJsonRequestConfig;
Parameters
config?
RawAxiosJsonRequestConfig
Returns
RawAxiosJsonRequestConfig
create()
static create(config?): Axios;
Parameters
config?
RawAxiosJsonRequestConfig
Returns
Axios
### <a id="Base"></a>Base
@xylabs/sdk-js
Abstract base class providing logging, telemetry, and global instance tracking with WeakRef-based GC.
Extended by
Type Parameters
TParams
TParams extends BaseParams = BaseParams
The parameter type, extending BaseParams
Constructors
Constructor
new Base<TParams>(params): Base<TParams>;
Parameters
params
BaseParams<TParams>
Returns
Base<TParams>
Properties
defaultLogger?
static optional defaultLogger?: Logger;
globalInstances
readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]>;
globalInstancesCountHistory
readonly static globalInstancesCountHistory: Record<BaseClassName, number[]>;
Accessors
historyInterval
Get Signature
get static historyInterval(): number;
Returns
number
Set Signature
set static historyInterval(value): void;
Parameters
value
number
Returns
void
historyTime
Get Signature
get static historyTime(): number;
Returns
number
Set Signature
set static historyTime(value): void;
Parameters
value
number
Returns
void
maxGcFrequency
Get Signature
get static maxGcFrequency(): number;
Returns
number
Set Signature
set static maxGcFrequency(value): void;
Parameters
value
number
Returns
void
maxHistoryDepth
Get Signature
get static maxHistoryDepth(): number;
Returns
number
logger
Get Signature
get logger(): Logger | undefined;
Returns
Logger | undefined
meter
Get Signature
get meter(): Meter | undefined;
Returns
Meter | undefined
params
Get Signature
get params(): BaseParams<TParams>;
Returns
BaseParams<TParams>
tracer
Get Signature
get tracer(): Tracer | undefined;
Returns
Tracer | undefined
Methods
gc()
Call Signature
static gc(force?): void;
Parameters
force?
boolean
Returns
void
Call Signature
static gc(className): void;
Parameters
className
BaseClassName
Returns
void
instanceCount()
static instanceCount(className): number;
Parameters
className
BaseClassName
Returns
number
instanceCounts()
static instanceCounts(): Record<BaseClassName, number>;
Returns
Record<BaseClassName, number>
startHistory()
static startHistory(): void;
Returns
void
stopHistory()
static stopHistory(): void;
Returns
void
### <a id="BaseEmitter"></a>BaseEmitter
@xylabs/sdk-js
Base class that combines the Base utility class with typed event emission capabilities.
Delegates all event operations to an internal Events instance.
Extends
Extended by
Type Parameters
TParams
TParams extends BaseParams = BaseParams
TEventData
TEventData extends EventData = EventData
Implements
Constructors
Constructor
new BaseEmitter<TParams, TEventData>(params): BaseEmitter<TParams, TEventData>;
Parameters
params
BaseParams<TParams>
Returns
BaseEmitter<TParams, TEventData>
Overrides
Base.constructor
Properties
defaultLogger?
static optional defaultLogger?: Logger;
Inherited from
Base.defaultLogger
globalInstances
readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]>;
Inherited from
Base.globalInstances
globalInstancesCountHistory
readonly static globalInstancesCountHistory: Record<BaseClassName, number[]>;
Inherited from
Base.globalInstancesCountHistory
eventData
eventData: TEventData;
Type-level reference to the event data shape for external type queries.
Implementation of
EventEmitter.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
Base.historyInterval
historyTime
Get Signature
get static historyTime(): number;
Returns
number
Set Signature
set static historyTime(value): void;
Parameters
value
number
Returns
void
Inherited from
Base.historyTime
maxGcFrequency
Get Signature
get static maxGcFrequency(): number;
Returns
number
Set Signature
set static maxGcFrequency(value): void;
Parameters
value
number
Returns
void
Inherited from
Base.maxGcFrequency
maxHistoryDepth
Get Signature
get static maxHistoryDepth(): number;
Returns
number
Inherited from
Base.maxHistoryDepth
logger
Get Signature
get logger(): Logger | undefined;
Returns
Logger | undefined
Inherited from
Base.logger
meter
Get Signature
get meter(): Meter | undefined;
Returns
Meter | undefined
Inherited from
Base.meter
params
Get Signature
get params(): BaseParams<TParams>;
Returns
BaseParams<TParams>
Inherited from
Base.params
tracer
Get Signature
get tracer(): Tracer | undefined;
Returns
Tracer | undefined
Inherited from
Base.tracer
Methods
gc()
Call Signature
static gc(force?): void;
Parameters
force?
boolean
Returns
void
Inherited from
Base.gc
Call Signature
static gc(className): void;
Parameters
className
BaseClassName
Returns
void
Inherited from
Base.gc
instanceCount()
static instanceCount(className): number;
Parameters
className
BaseClassName
Returns
number
Inherited from
Base.instanceCount
instanceCounts()
static instanceCounts(): Record<BaseClassName, number>;
Returns
Record<BaseClassName, number>
Inherited from
Base.instanceCounts
startHistory()
static startHistory(): void;
Returns
void
Inherited from
Base.startHistory
stopHistory()
static stopHistory(): void;
Returns
void
Inherited from
Base.stopHistory
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.
Implementation of
EventEmitter.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>
Implementation of
EventEmitter.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>
Implementation of
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[]
One or more event names to count listeners for.
Returns
number
The total listener count.
Implementation of
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[]
One or more event names to unsubscribe from.
listener
EventListener<TEventData[TEventName]>
The listener to remove.
Returns
void
Implementation of
EventEmitter.off
offAny()
offAny(listener): void;
Removes a wildcard listener that was receiving all events.
Parameters
listener
EventAnyListener
The wildcard listener to remove.
Returns
void
Implementation of
EventEmitter.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
Implementation of
EventEmitter.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
Implementation of
EventEmitter.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
Implementation of
EventEmitter.once
### <a id="ConsoleLogger"></a>ConsoleLogger
@xylabs/sdk-js
A LevelLogger that delegates to the global console object.
Extends
Constructors
Constructor
new ConsoleLogger(level?): ConsoleLogger;
Parameters
level?
LogLevelValue
Returns
ConsoleLogger
Overrides
LevelLogger.constructor
Properties
level
readonly level: LogLevelValue;
Inherited from
LevelLogger.level
logger
readonly logger: Logger;
Inherited from
LevelLogger.logger
Accessors
debug
Get Signature
get debug(): LogFunction;
Returns
LogFunction
Inherited from
LevelLogger.debug
error
Get Signature
get error(): LogFunction;
Returns
LogFunction
Inherited from
LevelLogger.error
info
Get Signature
get info(): LogFunction;
Returns
LogFunction
Inherited from
LevelLogger.info
log
Get Signature
get log(): LogFunction;
Returns
LogFunction
Inherited from
LevelLogger.log
trace
Get Signature
get trace(): LogFunction;
Returns
LogFunction
Inherited from
LevelLogger.trace
warn
Get Signature
get warn(): LogFunction;
Returns
LogFunction
Inherited from
LevelLogger.warn
### <a id="EthAddressWrapper"></a>EthAddressWrapper
@xylabs/sdk-js
Wrapper around an Ethereum address providing parsing, formatting, validation, and checksum support.
Constructors
Constructor
protected new EthAddressWrapper(address): EthAddressWrapper;
Parameters
address
bigint
Returns
EthAddressWrapper
Methods
fromString()
static fromString(value?, base?): EthAddressWrapper | undefined;
Parameters
value?
string
base?
number
Returns
EthAddressWrapper | undefined
parse()
static parse(value, base?): EthAddressWrapper | undefined;
Parameters
value
unknown
base?
number
Returns
EthAddressWrapper | undefined
validate()
static validate(address): boolean;
Parameters
address
string
Returns
boolean
equals()
equals(address?): boolean;
Parameters
address?
string | EthAddressWrapper | null
Returns
boolean
toBigNumber()
toBigNumber(): bigint;
Returns
bigint
toHex()
toHex(): string;
Returns
string
toJSON()
toJSON(): string;
Returns
string
toLowerCaseString()
toLowerCaseString(): string;
Returns
string
toShortString()
toShortString(length?): string;
Parameters
length?
number
Returns
string
toString()
toString(checksum?, chainId?): string;
Parameters
checksum?
boolean
chainId?
string
Returns
string
validate()
validate(): boolean;
Returns
boolean
### <a id="Events"></a>Events
@xylabs/sdk-js
Core typed event emitter implementation supporting named events, wildcard listeners,
serial and concurrent emission, listener filtering, and debug logging.
Extends
Type Parameters
TEventData
TEventData extends EventData = EventData
Implements
Constructors
Constructor
new Events<TEventData>(params?): Events<TEventData>;
Parameters
params?
EventsParams
Returns
Events<TEventData>
Overrides
Base.constructor
Properties
defaultLogger?
static optional defaultLogger?: Logger;
Inherited from
Base.defaultLogger
globalInstances
readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]>;
Inherited from
Base.globalInstances
globalInstancesCountHistory
readonly static globalInstancesCountHistory: Record<BaseClassName, number[]>;
Inherited from
Base.globalInstancesCountHistory
anyMap
protected static anyMap: WeakMap<object, Set<EventAnyListener>>;
eventsMap
protected static eventsMap: WeakMap<object, Map<PropertyKey, Set<EventListenerInfo<EventArgs>>>>;
eventData
eventData: TEventData;
Type-level reference to the event data shape for external type queries.
Implementation of
EventEmitter.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
Base.historyInterval
historyTime
Get Signature
get static historyTime(): number;
Returns
number
Set Signature
set static historyTime(value): void;
Parameters
value
number
Returns
void
Inherited from
Base.historyTime
maxGcFrequency
Get Signature
get static maxGcFrequency(): number;
Returns
number
Set Signature
set static maxGcFrequency(value): void;
Parameters
value
number
Returns
void
Inherited from
Base.maxGcFrequency
maxHistoryDepth
Get Signature
get static maxHistoryDepth(): number;
Returns
number
Inherited from
Base.maxHistoryDepth
logger
Get Signature
get logger(): Logger | undefined;
Returns
Logger | undefined
Inherited from
Base.logger
meter
Get Signature
get meter(): Meter | undefined;
Returns
Meter | undefined
Inherited from
Base.meter
params
Get Signature
get params(): BaseParams<TParams>;
Returns
BaseParams<TParams>
Inherited from
Base.params
tracer
Get Signature
get tracer(): Tracer | undefined;
Returns
Tracer | undefined
Inherited from
Base.tracer
isDebugEnabled
Get Signature
get static isDebugEnabled(): boolean;
Whether debug mode is enabled globally or via the DEBUG environment variable.
Returns
boolean
Set Signature
set static isDebugEnabled(newValue): void;
Parameters
newValue
boolean
Returns
void
debug
Get Signature
get debug(): DebugOptions | undefined;
The debug configuration for this instance, if provided.
Returns
DebugOptions | undefined
Methods
gc()
Call Signature
static gc(force?): void;
Parameters
force?
boolean
Returns
void
Inherited from
Base.gc
Call Signature
static gc(className): void;
Parameters
className
BaseClassName
Returns
void
Inherited from
Base.gc
instanceCount()
static instanceCount(className): number;
Parameters
className
BaseClassName
Returns
number
Inherited from
Base.instanceCount
instanceCounts()
static instanceCounts(): Record<BaseClassName, number>;
Returns
Record<BaseClassName, number>
Inherited from
Base.instanceCounts
startHistory()
static startHistory(): void;
Returns
void
Inherited from
Base.startHistory
stopHistory()
static stopHistory(): void;
Returns
void
Inherited from
Base.stopHistory
clearListeners()
clearListeners(eventNames): void;
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
void
Implementation of
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
The event to emit.
eventArgs
TEventData[TEventName]
The data to pass to listeners.
Returns
Promise<void>
Implementation of
EventEmitter.emit
emitMetaEvent()
emitMetaEvent<TEventName>(eventName, eventArgs): Promise<boolean | undefined>;
Emits an internal meta event (listenerAdded or listenerRemoved).
Type Parameters
TEventName
TEventName extends keyof MetaEventData<TEventData>
Parameters
eventName
TEventName
The meta event name.
eventArgs
MetaEventData<TEventData>[TEventName]
The meta event data containing listener and event information.
Returns
Promise<boolean | undefined>
True if the meta event was emitted successfully.
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
The event to emit.
eventArgs
TEventData[TEventName]
The data to pass to listeners.
Returns
Promise<void>
Implementation of
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[]
One or more event names to count listeners for.
Returns
number
The total listener count.
Implementation of
EventEmitter.listenerCount
logIfDebugEnabled()
logIfDebugEnabled<TEventName>(
type,
eventName?,
eventArgs?): void;
Logs debug information if debug mode is enabled.
Type Parameters
TEventName
TEventName extends PropertyKey
Parameters
type
string
The type of operation being logged.
eventName?
TEventName
The event name, if applicable.
eventArgs?
EventArgs
The event data, if applicable.
Returns
void
off()
off<TEventName, TEventListener>(eventNames, listener): void;
Removes a specific listener from the specified event name(s).
Type Parameters
TEventName
TEventName extends string | number | symbol
TEventListener
TEventListener = EventListener<TEventData[TEventName]>
Parameters
eventNames
TEventName | TEventName[]
One or more event names to unsubscribe from.
listener
TEventListener
The listener to remove.
Returns
void
Implementation of
EventEmitter.off
offAny()
offAny(listener): void;
Removes a wildcard listener that was receiving all events.
Parameters
listener
EventAnyListener
The wildcard listener to remove.
Returns
void
Implementation of
EventEmitter.offAny
on()
on<TEventName>(
eventNames,
listener,
filter?): () => void;
Subscribes a listener to the specified event name(s).
Type Parameters
TEventName
TEventName extends string | number | symbol = keyof TEventData
Parameters
eventNames
TEventName | TEventName[]
One or more event names to listen for.
listener
EventListener<TEventData[TEventName]>
The callback to invoke when the event fires.
filter?
TEventData[TEventName]
Optional filter to selectively invoke the listener based on event data.
Returns
An unsubscribe function.
() => void
Implementation of
EventEmitter.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
Implementation of
EventEmitter.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
Implementation of
EventEmitter.once
### <a id="Factory"></a>Factory
@xylabs/sdk-js
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
### <a id="ForgetPromise"></a>ForgetPromise
@xylabs/sdk-js
Node.js extension of ForgetPromise that can terminate the process on exceptions or timeouts.
Extends
Constructors
Constructor
new ForgetPromise(): ForgetPromiseNode;
Returns
ForgetPromiseNode
Inherited from
ForgetPromise.constructor
Properties
activeForgets
static activeForgets: number;
Number of currently active (unresolved) forgotten promises.
Inherited from
ForgetPromise.activeForgets
exceptedForgets
static exceptedForgets: number;
Number of forgotten promises that threw exceptions.
Inherited from
ForgetPromise.exceptedForgets
logger
static logger: Logger;
Logger instance used for error and warning output.
Inherited from
ForgetPromise.logger
Accessors
active
Get Signature
get static active(): boolean;
Whether any forgotten promises are still active.
Returns
boolean
Inherited from
ForgetPromise.active
Methods
awaitInactive()
static awaitInactive(interval?, timeout?): Promise<number>;
Waits until all forgotten promises have completed.
Parameters
interval?
number
Polling interval in milliseconds.
timeout?
number
Optional maximum wait time in milliseconds.
Returns
Promise<number>
The number of remaining active forgets (0 if all completed).
Inherited from
ForgetPromise.awaitInactive
exceptionHandler()
static exceptionHandler(
error,
config,
externalStackTrace?): void;
Handles exceptions, optionally terminating the process based on config.
Parameters
error
Error
config
ForgetNodeConfig
externalStackTrace?
string
Returns
void
Overrides
ForgetPromise.exceptionHandler
forget()
static forget<T>(promise, config?): void;
Forgets a promise using Node.js-specific configuration with process termination support.
Type Parameters
T
T
Parameters
promise
Promisable<T>
config?
ForgetNodeConfig<T>
Returns
void
Overrides
ForgetPromise.forget
timeoutHandler()
static timeoutHandler(
time,
config,
externalStackTrace?): void;
Handles timeouts, optionally terminating the process based on config.
Parameters
time
number
config
ForgetNodeConfig
externalStackTrace?
string
Returns
void
Overrides
ForgetPromise.timeoutHandler
### <a id="IdLogger"></a>IdLogger
@xylabs/sdk-js
A logger wrapper that prefixes every log message with a bracketed identifier.
Useful for distinguishing log output from different components or instances.
Implements
Constructors
Constructor
new IdLogger(logger, id?): IdLogger;
Parameters
logger
Logger
id?
() => string
Returns
IdLogger
Accessors
id
Set Signature
set id(id): void;
Parameters
id
string
Returns
void
Methods
debug()
debug(...data): void;
Parameters
data
...unknown[]
Returns
void
Implementation of
Logger.debug
error()
error(...data): void;
Parameters
data
...unknown[]
Returns
void
Implementation of
Logger.error
info()
info(...data): void;
Parameters
data
...unknown[]
Returns
void
Implementation of
Logger.info
log()
log(...data): void;
Parameters
data
...unknown[]
Returns
void
Implementation of
Logger.log
trace()
trace(...data): void;
Parameters
data
...unknown[]
Returns
void
Implementation of
Logger.trace
warn()
warn(...data): void;
Parameters
data
...unknown[]
Returns
void
Implementation of
Logger.warn
### <a id="IsObjectFactory"></a>IsObjectFactory
@xylabs/sdk-js
Factory class for creating type-guard functions that validate objects against a given shape and optional additional checks.
Type Parameters
T
T extends TypedObject
Constructors
Constructor
new IsObjectFactory<T>(): IsObjectFactory<T>;
Returns
IsObjectFactory<T>
Methods
create()
create(shape?, additionalChecks?): TypeCheck<T>;
Creates a type-guard function that validates an object matches the given shape and passes additional checks.
Parameters
shape?
ObjectTypeShape
An optional map of property names to expected types.
additionalChecks?
TypeCheck<TypedObject>[]
Optional extra type-check functions to run after shape validation.
Returns
TypeCheck<T>
A type-guard function for type T.
### <a id="LevelLogger"></a>LevelLogger
@xylabs/sdk-js
A logger that filters messages based on a configured log level.
Methods for levels above the configured threshold return a no-op function.
Extended by
Implements
Constructors
Constructor
new LevelLogger(logger, level?): LevelLogger;
Parameters
logger
Logger
level?
LogLevelValue
Returns
LevelLogger
Properties
level
readonly level: LogLevelValue;
logger
readonly logger: Logger;
Accessors
debug
Get Signature
get debug(): LogFunction;
Returns
LogFunction
Implementation of
Logger.debug
error
Get Signature
get error(): LogFunction;
Returns
LogFunction
Implementation of
Logger.error
info
Get Signature
get info(): LogFunction;
Returns
LogFunction
Implementation of
Logger.info
log
Get Signature
get log(): LogFunction;
Returns
LogFunction
Implementation of
Logger.log
trace
Get Signature
get trace(): LogFunction;
Returns
LogFunction
Implementation of
Logger.trace
warn
Get Signature
get warn(): LogFunction;
Returns
LogFunction
Implementation of
Logger.warn
### <a id="ObjectWrapper"></a>ObjectWrapper
@xylabs/sdk-js
Abstract base class that wraps an object and provides typed access to it.
Extended by
Type Parameters
T
T extends EmptyObject = EmptyObject
Constructors
Constructor
new ObjectWrapper<T>(obj): ObjectWrapper<T>;
Parameters
obj
T
Returns
ObjectWrapper<T>
Properties
obj
readonly obj: T;
Accessors
stringKeyObj
Get Signature
get protected stringKeyObj(): StringKeyObject;
Returns
StringKeyObject
### <a id="PromiseEx"></a>PromiseEx
@xylabs/sdk-js
An extended Promise that carries an optional attached value and supports cancellation.
The value can be inspected via the then or value methods to conditionally cancel.
Extends
Type Parameters
T
T
V
V = void
Constructors
Constructor
new PromiseEx<T, V>(func, value?): PromiseEx<T, V>;
Parameters
func
PromiseExFunc<T>
value?
V
Returns
PromiseEx<T, V>
Overrides
Promise<T>.constructor
Properties
cancelled?
optional cancelled?: boolean;
Whether the promise has been cancelled via a value callback.
Methods
then()
then<TResult1, TResult2>(
onfulfilled?,
onrejected?,
onvalue?): Promise<TResult1 | TResult2>;
Attaches callbacks for the resolution and/or rejection of the Promise.
Type Parameters
TResult1
TResult1 = T
TResult2
TResult2 = never
Parameters
onfulfilled?
((value) => TResult1 | PromiseLike<TResult1>) | null
The callback to execute when the Promise is resolved.
onrejected?
((reason) => TResult2 | PromiseLike<TResult2>) | null
The callback to execute when the Promise is rejected.
onvalue?
(value?) => boolean
Returns
Promise<TResult1 | TResult2>
A Promise for the completion of which ever callback is executed.
Overrides
Promise.then
value()
value(onvalue?): this;
Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
Parameters
onvalue?
(value?) => boolean
A callback that receives the attached value and returns whether to cancel.
Returns
this
This instance for chaining.
### <a id="SilentLogger"></a>SilentLogger
@xylabs/sdk-js
A logger that does not log anything.
This is useful when you want to disable logging
like when running unit tests or in silent mode.
It implements the Logger interface but all methods
are no-op functions.
Implements
Constructors
Constructor
new SilentLogger(): SilentLogger;
Returns
SilentLogger
Properties
debug
readonly debug: (..._data) => undefined;
Parameters
_data
...unknown[]
Returns
undefined
Implementation of
Logger.debug
error
readonly error: (..._data) => undefined;
Parameters
_data
...unknown[]
Returns
undefined
Implementation of
Logger.error
info
readonly info: (..._data) => undefined;
Parameters
_data
...unknown[]
Returns
undefined
Implementation of
Logger.info
log
readonly log: (..._data) => undefined;
Parameters
_data
...unknown[]
Returns
undefined
Implementation of
Logger.log
trace
readonly trace: (..._data) => undefined;
Parameters
_data
...unknown[]
Returns
undefined
Implementation of
Logger.trace
warn
readonly warn: (..._data) => undefined;
Parameters
_data
...unknown[]
Returns
undefined
Implementation of
Logger.warn
### <a id="UniqueBase"></a>UniqueBase
@xylabs/sdk-js
Base class that registers itself as globally unique, preventing duplicate module instances.
Extends
Type Parameters
TParams
TParams extends BaseParams = BaseParams
Constructors
Constructor
new UniqueBase<TParams>(params): UniqueBase<TParams>;
Parameters
params
BaseParams<TParams>
Returns
UniqueBase<TParams>
Overrides
Base.constructor
Properties
defaultLogger?
static optional defaultLogger?: Logger;
Inherited from
Base.defaultLogger
globalInstances
readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]>;
Inherited from
Base.globalInstances
globalInstancesCountHistory
readonly static globalInstancesCountHistory: Record<BaseClassName, number[]>;
Inherited from
Base.globalInstancesCountHistory
uniqueDomain
readonly static uniqueDomain: "xy" = "xy";
uniqueName
readonly static uniqueName: string;
uniqueNameXyo
readonly static uniqueNameXyo: string;
Accessors
historyInterval
Get Signature
get static historyInterval(): number;
Returns
number
Set Signature
set static historyInterval(value): void;
Parameters
value
number
Returns
void
Inherited from
Base.historyInterval
historyTime
Get Signature
get static historyTime(): number;
Returns
number
Set Signature
set static historyTime(value): void;
Parameters
value
number
Returns
void
Inherited from
Base.historyTime
maxGcFrequency
Get Signature
get static maxGcFrequency(): number;
Returns
number
Set Signature
set static maxGcFrequency(value): void;
Parameters
value
number
Returns
void
Inherited from
Base.maxGcFrequency
maxHistoryDepth
Get Signature
get static maxHistoryDepth(): number;
Returns
number
Inherited from
Base.maxHistoryDepth
logger
Get Signature
get logger(): Logger | undefined;
Returns
Logger | undefined
Inherited from
Base.logger
meter
Get Signature
get meter(): Meter | undefined;
Returns
Meter | undefined
Inherited from
Base.meter
params
Get Signature
get params(): BaseParams<TParams>;
Returns
BaseParams<TParams>
Inherited from
Base.params
tracer
Get Signature
get tracer(): Tracer | undefined;
Returns
Tracer | undefined
Inherited from
Base.tracer
Methods
gc()
Call Signature
static gc(force?): void;
Parameters
force?
boolean
Returns
void
Inherited from
Base.gc
Call Signature
static gc(className): void;
Parameters
className
BaseClassName
Returns
void
Inherited from
Base.gc
instanceCount()
static instanceCount(className): number;
Parameters
className
BaseClassName
Returns
number
Inherited from
Base.instanceCount
instanceCounts()
static instanceCounts(): Record<BaseClassName, number>;
Returns
Record<BaseClassName, number>
Inherited from
Base.instanceCounts
startHistory()
static startHistory(): void;
Returns
void
Inherited from
Base.startHistory
stopHistory()
static stopHistory(): void;
Returns
void
Inherited from
Base.stopHistory
### <a id="ValidatorBase"></a>ValidatorBase
@xylabs/sdk-js
Abstract base class for validators that wraps a partial object and provides a validation method.
Extends
Type Parameters
T
T extends EmptyObject = AnyObject
Implements
Constructors
Constructor
new ValidatorBase<T>(obj): ValidatorBase<T>;
Parameters
obj
T
Returns
ValidatorBase<T>
Inherited from
ObjectWrapper.constructor
Properties
obj
readonly obj: T;
Inherited from
ObjectWrapper.obj
Accessors
stringKeyObj
Get Signature
get protected stringKeyObj(): StringKeyObject;
Returns
StringKeyObject
Inherited from
ObjectWrapper.stringKeyObj
Methods
validate()
abstract validate(payload): Promisable<Error[]>;
Parameters
payload
T
Returns
Promisable<Error[]>
Implementation of
Validator.validate
### <a id="XyConsoleSpanExporter"></a>XyConsoleSpanExporter
@xylabs/sdk-js
A console span exporter that formats spans with color-coded durations using chalk.
Spans are filtered by a configurable log level based on their duration.
Extends
Constructors
Constructor
new XyConsoleSpanExporter(logLevel?, logger?): XyConsoleSpanExporter;
Parameters
logLevel?
number
logger?
Logger
Returns
XyConsoleSpanExporter
Overrides
ConsoleSpanExporter.constructor
Properties
durationToLogLevel
readonly static durationToLogLevel: number[];
Duration thresholds (in ms) that map to increasing log levels.
logLevelToChalkColor
readonly static logLevelToChalkColor: ChalkInstance[];
Chalk color functions corresponding to each log level.
logger
logger: Logger;
Accessors
logLevel
Get Signature
get logLevel(): number;
The minimum log level required for a span to be exported.
Returns
number
Methods
export()
export(spans): void;
Export spans.
Parameters
spans
ReadableSpan[]
Returns
void
Overrides
ConsoleSpanExporter.export
logColor()
logColor(level): ChalkInstance;
Returns the chalk color function for the given log level.
Parameters
level
number
The log level index.
Returns
ChalkInstance
A chalk color function.
spanLevel()
spanLevel(span): number;
Determines the log level of a span based on its duration.
Parameters
span
ReadableSpan
The span to evaluate.
Returns
number
The numeric log level (index into durationToLogLevel).
### functions
### <a id="asAddress"></a>asAddress
@xylabs/sdk-js
Call Signature
function asAddress(value?): BrandedAddress | undefined;
Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config.
Parameters
value?
unknown
The value to coerce (must be a string)
Returns
BrandedAddress | undefined
The value as Address, or undefined if coercion fails and assert is not set
Call Signature
function asAddress(value, assert): BrandedAddress;
Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config.
Parameters
value
unknown
The value to coerce (must be a string)
assert
AssertConfig
If provided, throws on failure instead of returning undefined
Returns
BrandedAddress
The value as Address, or undefined if coercion fails and assert is not set
### <a id="asAddressV2"></a>asAddressV2
@xylabs/sdk-js
function asAddressV2(value?, assert?): BrandedAddress | undefined;
Alpha
Parameters
value?
unknown
assert?
boolean
Returns
BrandedAddress | undefined
### <a id="asEthAddress"></a>asEthAddress
@xylabs/sdk-js
Call Signature
function asEthAddress(value): EthAddress | undefined;
Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config.
Parameters
value
unknown
The value to coerce (must be a string)
Returns
EthAddress | undefined
The value as EthAddress, or undefined if coercion fails and assert is not set
Call Signature
function asEthAddress(value, assert): EthAddress;
Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config.
Parameters
value
unknown
The value to coerce (must be a string)
assert
AssertConfig
If provided, throws on failure instead of returning undefined
Returns
EthAddress
The value as EthAddress, or undefined if coercion fails and assert is not set
### <a id="asHash"></a>asHash
@xylabs/sdk-js
Call Signature
function asHash(value): BrandedHash | undefined;
Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config.
Parameters
value
unknown
The value to coerce (must be a string)
Returns
BrandedHash | undefined
The value as Hash, or undefined if coercion fails and assert is not set
Call Signature
function asHash(value, assert): BrandedHash;
Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config.
Parameters
value
unknown
The value to coerce (must be a string)
assert
AssertConfig
If provided, throws on failure instead of returning undefined
Returns
BrandedHash
The value as Hash, or undefined if coercion fails and assert is not set
### <a id="asHex"></a>asHex
@xylabs/sdk-js
Call Signature
function asHex(value): BrandedHex | undefined;
Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config.
Parameters
value
unknown
The value to coerce (must be a string)
Returns
BrandedHex | undefined
The value as Hex, or undefined if coercion fails and assert is not set
Call Signature
function asHex(value, assert): BrandedHex;
Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config.
Parameters
value
unknown
The value to coerce (must be a string)
assert
AssertConfig
If provided, throws on failure instead of returning undefined
Returns
BrandedHex
The value as Hex, or undefined if coercion fails and assert is not set
### <a id="assertDefinedEx"></a>assertDefinedEx
@xylabs/sdk-js
Call Signature
function assertDefinedEx<T>(expr, messageFunc?): T;
Asserts that a value is defined (not undefined) and returns the value.
Throws an error if the value is undefined.
Type Parameters
T
T
The type of value to check
Parameters
expr
T | undefined
Expression to be evaluated for being defined
messageFunc?
AssertExMessageFunc<T>
Function that returns a message for the error if expression is undefined
Returns
T
The value of the expression (guaranteed to be defined)
Throws
Error with the message returned by messageFunc
Example
const value = assertDefinedEx(possiblyUndefined, () => 'Value must be defined')
const config: Config | undefined = loadConfig()
const safeConfig = assertDefinedEx(config, () => 'Config failed to load')
Call Signature
function assertDefinedEx<T, R>(expr, errorFunc?): T;
Asserts that a value is defined (not undefined) and returns the value.
Throws a custom error if the value is undefined.
Type Parameters
T
T
The type of value to check
R
R extends Error
The type of error to throw
Parameters
expr
T | undefined
Expression to be evaluated for being defined
errorFunc?
AssertExErrorFunc<T, R>
Function that returns a custom error instance if expression is undefined
Returns
T
The value of the expression (guaranteed to be defined)
Throws
Custom error returned by errorFunc
Example
const user = assertDefinedEx(getUser(), () => new UserNotFoundError('User not found'))
### <a id="assertEx"></a>assertEx
@xylabs/sdk-js
Call Signature
function assertEx<T>(expr, messageFunc?): T;
Asserts that an expression is truthy and returns the value.
Throws an error if the expression is falsy.
Type Parameters
T
T
The type of value to check
Parameters
expr
T | null | undefined
Expression to be evaluated for truthiness
messageFunc?
AssertExMessageFunc<T>
Function that returns a message for the error if expression is falsy
Returns
T
The value of the expression (guaranteed to be truthy)
Throws
Error with the message returned by messageFunc
Example
const value = assertEx(possiblyFalsy, () => 'Value must be truthy')
const config: Config | null = loadConfig()
const safeConfig = assertEx(config, () => 'Config failed to load')
Call Signature
function assertEx<T, R>(expr, errorFunc?): T;
Asserts that an expression is truthy and returns the value.
Throws a custom error if the expression is falsy.
Type Parameters
T
T
The type of value to check
R
R extends Error
The type of error to throw
Parameters
expr
T | null | undefined
Expression to be evaluated for truthiness
errorFunc?
AssertExErrorFunc<T, R>
Function that returns a custom error instance if expression is falsy
Returns
T
The value of the expression (guaranteed to be truthy)
Throws
Custom error returned by errorFunc
Example
const user = assertEx(getUser(), () => new UserNotFoundError('User not found'))
### <a id="axiosJsonConfig"></a>axiosJsonConfig
@xylabs/sdk-js
function axiosJsonConfig(config?): RawAxiosJsonRequestConfig;
Creates an Axios config preconfigured for JSON requests with optional gzip compression.
Request bodies exceeding compressLength (default 1024 bytes) are automatically gzip-compressed.
Parameters
config?
RawAxiosJsonRequestConfig<any>
Base Axios config, optionally including a compressLength threshold
Returns
RawAxiosJsonRequestConfig
A fully configured Axios request config with JSON transforms
### <a id="cloneContextWithoutSpan"></a>cloneContextWithoutSpan
@xylabs/sdk-js
function cloneContextWithoutSpan(activeCtx, configKeys?): Context;
Creates a new OpenTelemetry context that preserves baggage and custom keys but has no active span.
Parameters
activeCtx
Context
The context to clone from.
configKeys?
symbol[]
Additional context keys to copy.
Returns
Context
A new context with baggage but no parent span.
### <a id="creatable"></a>creatable
@xylabs/sdk-js
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/sdk-js
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="createDeepMerge"></a>createDeepMerge
@xylabs/sdk-js
function createDeepMerge(options): <T>(...objects) => MergeAll<T>;
Creates a deep merge function with the specified options.
Parameters
options
MergeOptions
Options for merging.
Returns
A deep merge function configured for the specified options.
<T>(...objects) => MergeAll<T>
### <a id="fetchCompress"></a>fetchCompress
@xylabs/sdk-js
function fetchCompress(url, options?): Promise<Response>;
Drop-in replacement for native fetch that optionally gzip-compresses the request body.
When compressLength is set and the body string exceeds that threshold, the body is
gzip-compressed via pako and Content-Encoding: gzip is added to the headers.
Returns a standard Response — identical to what native fetch returns.
Parameters
url
string | URL
options?
FetchCompressOptions
Returns
Promise<Response>
### <a id="fetchJson"></a>fetchJson
@xylabs/sdk-js
function fetchJson<T>(url, options?): Promise<FetchJsonResponse<T>>;
JSON-configured fetch with optional gzip compression on request bodies.
Request bodies exceeding compressMinLength bytes are gzip-compressed via pako.
Type Parameters
T
T
Parameters
url
string
options?
FetchCompressOptions
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonDelete"></a>fetchJsonDelete
@xylabs/sdk-js
function fetchJsonDelete<T>(url, options?): Promise<FetchJsonResponse<T>>;
JSON DELETE request.
Type Parameters
T
T
Parameters
url
string
options?
FetchCompressOptions
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonGet"></a>fetchJsonGet
@xylabs/sdk-js
function fetchJsonGet<T>(url, options?): Promise<FetchJsonResponse<T>>;
JSON GET request.
Type Parameters
T
T
Parameters
url
string
options?
FetchCompressOptions
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonPatch"></a>fetchJsonPatch
@xylabs/sdk-js
function fetchJsonPatch<T>(
url,
data?,
options?): Promise<FetchJsonResponse<T>>;
JSON PATCH request with a body.
Type Parameters
T
T
Parameters
url
string
data?
unknown
options?
FetchCompressOptions
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonPost"></a>fetchJsonPost
@xylabs/sdk-js
function fetchJsonPost<T>(
url,
data?,
options?): Promise<FetchJsonResponse<T>>;
JSON POST request with a body.
Type Parameters
T
T
Parameters
url
string
data?
unknown
options?
FetchCompressOptions
Returns
Promise<FetchJsonResponse<T>>
### <a id="fetchJsonPut"></a>fetchJsonPut
@xylabs/sdk-js
function fetchJsonPut<T>(
url,
data?,
options?): Promise<FetchJsonResponse<T>>;
JSON PUT request with a body.
Type Parameters
T
T
Parameters
url
string
data?
unknown
options?
FetchCompressOptions
Returns
Promise<FetchJsonResponse<T>>
### <a id="hexToBigInt"></a>hexToBigInt
@xylabs/sdk-js
function hexToBigInt(hex): bigint;
Converts a Hex string to a BigInt.
Parameters
hex
BrandedHex
The hex string to convert
Returns
bigint
The BigInt representation of the hex value
### <a id="isAddressV2"></a>isAddressV2
@xylabs/sdk-js
function isAddressV2(value?): value is BrandedAddress;
Alpha
Parameters
value?
unknown
Returns
value is BrandedAddress
### <a id="isArray"></a>isArray
@xylabs/sdk-js
Call Signature
function isArray(value): value is readonly unknown[];
Type guard that checks whether a value is an array.
Parameters
value
unknown
Returns
value is readonly unknown[]
Call Signature
function isArray<T>(value): value is Extract<T, readonly unknown[]>;
Type guard that checks whether a value is an array.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, readonly unknown[]>
### <a id="isArrayBuffer"></a>isArrayBuffer
@xylabs/sdk-js
Call Signature
function isArrayBuffer(value): value is ArrayBuffer;
Type guard that checks if a value is an ArrayBuffer instance.
Parameters
value
unknown
Returns
value is ArrayBuffer
Call Signature
function isArrayBuffer<T>(value): value is Extract<T, ArrayBuffer>;
Type guard that checks if a value is an ArrayBuffer instance.
Type Parameters
T
T extends ArrayBuffer
Parameters
value
T
Returns
value is Extract<T, ArrayBuffer>
### <a id="isArrayBufferLike"></a>isArrayBufferLike
@xylabs/sdk-js
Call Signature
function isArrayBufferLike(value): value is ArrayBufferLike;
Type guard that checks if a value conforms to the ArrayBufferLike interface (has byteLength and slice).
Parameters
value
unknown
Returns
value is ArrayBufferLike
Call Signature
function isArrayBufferLike<T>(value): value is Extract<T, ArrayBufferLike>;
Type guard that checks if a value conforms to the ArrayBufferLike interface (has byteLength and slice).
Type Parameters
T
T extends ArrayBufferLike
Parameters
value
T
Returns
value is Extract<T, ArrayBufferLike>
### <a id="isArrayBufferView"></a>isArrayBufferView
@xylabs/sdk-js
Call Signature
function isArrayBufferView(value): value is ArrayBufferView<ArrayBufferLike>;
Type guard that checks whether a value is an ArrayBufferView (e.g., TypedArray or DataView).
Parameters
value
unknown
Returns
value is ArrayBufferView<ArrayBufferLike>
Call Signature
function isArrayBufferView<T>(value): value is Extract<T, ArrayBufferView<ArrayBufferLike>>;
Type guard that checks whether a value is an ArrayBufferView (e.g., TypedArray or DataView).
Type Parameters
T
T extends ArrayBufferView<ArrayBufferLike>
Parameters
value
T
Returns
value is Extract<T, ArrayBufferView<ArrayBufferLike>>
### <a id="isBigInt"></a>isBigInt
@xylabs/sdk-js
Call Signature
function isBigInt(value): value is bigint;
Type guard that checks whether a value is a bigint.
Parameters
value
unknown
Returns
value is bigint
Call Signature
function isBigInt<T>(value): value is Extract<T, bigint>;
Type guard that checks whether a value is a bigint.
Type Parameters
T
T extends bigint
Parameters
value
T
Returns
value is Extract<T, bigint>
### <a id="isBlob"></a>isBlob
@xylabs/sdk-js
Call Signature
function isBlob(value): value is Blob;
Type guard that checks whether a value is a Blob instance.
Parameters
value
unknown
Returns
value is Blob
Call Signature
function isBlob<T>(value): value is Extract<T, Blob>;
Type guard that checks whether a value is a Blob instance.
Type Parameters
T
T extends Blob
Parameters
value
T
Returns
value is Extract<T, Blob>
### <a id="isBoolean"></a>isBoolean
@xylabs/sdk-js
Call Signature
function isBoolean(value): value is boolean;
Type guard that checks whether a value is a boolean.
Parameters
value
unknown
Returns
value is boolean
Call Signature
function isBoolean<T>(value): value is Extract<T, boolean>;
Type guard that checks whether a value is a boolean.
Type Parameters
T
T extends boolean
Parameters
value
T
Returns
value is Extract<T, boolean>
### <a id="isDataView"></a>isDataView
@xylabs/sdk-js
Call Signature
function isDataView(value): value is DataView<ArrayBufferLike>;
Type guard that checks whether a value is a DataView instance.
Parameters
value
unknown
Returns
value is DataView<ArrayBufferLike>
Call Signature
function isDataView<T>(value): value is Extract<T, DataView<ArrayBufferLike>>;
Type guard that checks whether a value is a DataView instance.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, DataView<ArrayBufferLike>>
### <a id="isDate"></a>isDate
@xylabs/sdk-js
Call Signature
function isDate(value): value is Date;
Type guard that checks whether a value is a Date instance.
Parameters
value
unknown
Returns
value is Date
Call Signature
function isDate<T>(value): value is Extract<T, Date>;
Type guard that checks whether a value is a Date instance.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, Date>
### <a id="isDateString"></a>isDateString
@xylabs/sdk-js
Call Signature
function isDateString(value): value is string;
Type guard that checks whether a value is a string that can be parsed as a valid date.
Parameters
value
unknown
Returns
value is string
Call Signature
function isDateString<T>(value): value is Extract<T, string>;
Type guard that checks whether a value is a string that can be parsed as a valid date.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, string>
### <a id="isDefined"></a>isDefined
@xylabs/sdk-js
function isDefined<T>(value): value is Exclude<T, undefined>;
Type guard that checks whether a value is not undefined.
Type Parameters
T
T
Parameters
value
T
Returns
value is Exclude<T, undefined>
### <a id="isDefinedNotNull"></a>isDefinedNotNull
@xylabs/sdk-js
function isDefinedNotNull<T>(value): value is Exclude<T, null | undefined>;
Type guard that checks whether a value is neither undefined nor null.
Type Parameters
T
T
Parameters
value
T
Returns
value is Exclude<T, null | undefined>
### <a id="isEmpty"></a>isEmpty
@xylabs/sdk-js
Call Signature
function isEmpty<T>(value): value is T;
Type guard that checks whether a value is empty (empty string, empty array, or empty object).
Type Parameters
T
T
Parameters
value
unknown
Returns
value is T
Call Signature
function isEmpty<K, V, T>(value): value is Extract<T, Record<K, never>>;
Type guard that checks whether a value is empty (empty string, empty array, or empty object).
Type Parameters
K
K extends RecordKey
V
V
T
T extends Record<K, V>
Parameters
value
T
Returns
value is Extract<T, Record<K, never>>
Call Signature
function isEmpty<T>(value): value is Extract<T, never[]>;
Type guard that checks whether a value is empty (empty string, empty array, or empty object).
Type Parameters
T
T extends unknown[]
Parameters
value
T
Returns
value is Extract<T, never[]>
### <a id="isEmptyArray"></a>isEmptyArray
@xylabs/sdk-js
Call Signature
function isEmptyArray(value): value is [];
Type guard that checks whether a value is an empty array.
Parameters
value
unknown
Returns
value is []
Call Signature
function isEmptyArray<T>(value): value is Extract<T, unknown[]>;
Type guard that checks whether a value is an empty array.
Type Parameters
T
T extends unknown[]
Parameters
value
T
Returns
value is Extract<T, unknown[]>
### <a id="isEmptyObject"></a>isEmptyObject
@xylabs/sdk-js
Call Signature
function isEmptyObject(value): value is {};
Type guard that checks whether a value is an object with no own keys.
Parameters
value
unknown
Returns
value is {}
Call Signature
function isEmptyObject<K, V, T>(value): value is Extract<T, Record<K, never>>;
Type guard that checks whether a value is an object with no own keys.
Type Parameters
K
K extends RecordKey
V
V
T
T extends Record<K, V>
Parameters
value
T
Returns
value is Extract<T, Record<K, never>>
### <a id="isEmptyString"></a>isEmptyString
@xylabs/sdk-js
Call Signature
function isEmptyString(value): value is "";
Type guard that checks whether a value is an empty string.
Parameters
value
unknown
Returns
value is ""
Call Signature
function isEmptyString<T>(value): value is Extract<T, "">;
Type guard that checks whether a value is an empty string.
Type Parameters
T
T extends string
Parameters
value
T
Returns
value is Extract<T, "">
### <a id="isError"></a>isError
@xylabs/sdk-js
Call Signature
function isError(value): value is Error;
Type guard that checks whether a value is an Error instance.
Parameters
value
unknown
Returns
value is Error
Call Signature
function isError<T>(value): value is Extract<T, Error>;
Type guard that checks whether a value is an Error instance.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, Error>
### <a id="isFalsy"></a>isFalsy
@xylabs/sdk-js
Call Signature
function isFalsy<T>(value): value is Extract<T, false | "" | 0 | 0n | null | undefined>;
Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, false | "" | 0 | 0n | null | undefined>
Call Signature
function isFalsy<T>(value): value is Extract<T, false>;
Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends boolean
Parameters
value
T
Returns
value is Extract<T, false>
Call Signature
function isFalsy<T>(value): value is Extract<T, 0>;
Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends number
Parameters
value
T
Returns
value is Extract<T, 0>
Call Signature
function isFalsy<T>(value): value is Extract<T, 0n>;
Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends bigint
Parameters
value
T
Returns
value is Extract<T, 0n>
Call Signature
function isFalsy<T>(value): value is Extract<T, null>;
Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends null
Parameters
value
T
Returns
value is Extract<T, null>
Call Signature
function isFalsy<T>(value): value is Extract<T, undefined>;
Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends undefined
Parameters
value
T
Returns
value is Extract<T, undefined>
Call Signature
function isFalsy<T>(value): value is Extract<T, "">;
Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends string
Parameters
value
T
Returns
value is Extract<T, "">
### <a id="isFile"></a>isFile
@xylabs/sdk-js
Call Signature
function isFile(value): value is File;
Type guard that checks whether a value is a File instance.
Parameters
value
unknown
Returns
value is File
Call Signature
function isFile<T>(value): value is Extract<T, File>;
Type guard that checks whether a value is a File instance.
Type Parameters
T
T extends File
Parameters
value
T
Returns
value is Extract<T, File>
### <a id="isFunction"></a>isFunction
@xylabs/sdk-js
Call Signature
function isFunction(value): value is AnyFunction;
Type guard that checks whether a value is a function.
Parameters
value
unknown
Returns
value is AnyFunction
Call Signature
function isFunction<T>(value): value is Extract<T, AnyFunction>;
Type guard that checks whether a value is a function.
Type Parameters
T
T extends AnyFunction
Parameters
value
T
Returns
value is Extract<T, AnyFunction>
### <a id="isMap"></a>isMap
@xylabs/sdk-js
Call Signature
function isMap(value): value is Map<unknown, unknown>;
Type guard that checks whether a value is a Map instance.
Parameters
value
unknown
Returns
value is Map<unknown, unknown>
Call Signature
function isMap<K, V, T>(value): value is Extract<T, Map<K, V>>;
Type guard that checks whether a value is a Map instance.
Type Parameters
K
K
V
V
T
T extends Map<K, V>
Parameters
value
T
Returns
value is Extract<T, Map<K, V>>
### <a id="isNull"></a>isNull
@xylabs/sdk-js
Call Signature
function isNull(value): value is null;
Type guard that checks whether a value is null.
Parameters
value
unknown
Returns
value is null
Call Signature
function isNull<T>(value): value is Extract<T, null>;
Type guard that checks whether a value is null.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, null>
### <a id="isNumber"></a>isNumber
@xylabs/sdk-js
Call Signature
function isNumber(value): value is number;
Type guard that checks whether a value is a number.
Parameters
value
unknown
Returns
value is number
Call Signature
function isNumber<T>(value): value is Extract<T, number>;
Type guard that checks whether a value is a number.
Type Parameters
T
T extends number
Parameters
value
T
Returns
value is Extract<T, number>
### <a id="isObject"></a>isObject
@xylabs/sdk-js
Call Signature
function isObject(value): value is object;
Type guard that checks whether a value is a plain object (not null and not an array).
Parameters
value
unknown
Returns
value is object
Call Signature
function isObject<T>(value): value is Extract<T, object>;
Type guard that checks whether a value is a plain object (not null and not an array).
Type Parameters
T
T extends object
Parameters
value
T
Returns
value is Extract<T, object>
### <a id="isPopulatedArray"></a>isPopulatedArray
@xylabs/sdk-js
Call Signature
function isPopulatedArray(value): value is readonly unknown[];
Type guard that checks whether a value is a non-empty array.
Parameters
value
unknown
Returns
value is readonly unknown[]
Call Signature
function isPopulatedArray<T>(value): value is Extract<T, readonly unknown[]>;
Type guard that checks whether a value is a non-empty array.
Type Parameters
T
T extends unknown[]
Parameters
value
T
Returns
value is Extract<T, readonly unknown[]>
### <a id="isPromise"></a>isPromise
@xylabs/sdk-js
Call Signature
function isPromise(value): value is Promise<unknown>;
Type guard that checks whether a value is a Promise instance.
Parameters
value
unknown
Returns
value is Promise<unknown>
Call Signature
function isPromise<T>(value): value is Extract<T, Promise<unknown>>;
Type guard that checks whether a value is a Promise instance.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, Promise<unknown>>
### <a id="isPromiseLike"></a>isPromiseLike
@xylabs/sdk-js
Call Signature
function isPromiseLike(value): value is Promise<unknown>;
Type guard that checks whether a value is promise-like (has a then method).
Parameters
value
unknown
Returns
value is Promise<unknown>
Call Signature
function isPromiseLike<T>(value): value is Extract<T, Promise<unknown>>;
Type guard that checks whether a value is promise-like (has a then method).
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, Promise<unknown>>
### <a id="isRegExp"></a>isRegExp
@xylabs/sdk-js
Call Signature
function isRegExp(value): value is RegExp;
Type guard that checks whether a value is a RegExp instance.
Parameters
value
unknown
Returns
value is RegExp
Call Signature
function isRegExp<T>(value): value is Extract<T, RegExp>;
Type guard that checks whether a value is a RegExp instance.
Type Parameters
T
T extends RegExp
Parameters
value
T
Returns
value is Extract<T, RegExp>
### <a id="isSet"></a>isSet
@xylabs/sdk-js
Call Signature
function isSet(value): value is Set<unknown>;
Type guard that checks whether a value is a Set instance.
Parameters
value
unknown
Returns
value is Set<unknown>
Call Signature
function isSet<T>(value): value is Extract<T, Set<unknown>>;
Type guard that checks whether a value is a Set instance.
Type Parameters
T
T extends Set<unknown>
Parameters
value
unknown
Returns
value is Extract<T, Set<unknown>>
### <a id="isString"></a>isString
@xylabs/sdk-js
Call Signature
function isString(value): value is string;
Type guard that checks whether a value is a string.
Parameters
value
unknown
Returns
value is string
Call Signature
function isString<T>(value): value is Extract<T, string>;
Type guard that checks whether a value is a string.
Type Parameters
T
T extends string
Parameters
value
T
Returns
value is Extract<T, string>
### <a id="isSymbol"></a>isSymbol
@xylabs/sdk-js
Call Signature
function isSymbol(value): value is symbol;
Type guard that checks whether a value is a symbol.
Parameters
value
unknown
Returns
value is symbol
Call Signature
function isSymbol<T>(value): value is Extract<T, symbol>;
Type guard that checks whether a value is a symbol.
Type Parameters
T
T extends symbol
Parameters
value
T
Returns
value is Extract<T, symbol>
### <a id="isTruthy"></a>isTruthy
@xylabs/sdk-js
Call Signature
function isTruthy<T>(value): value is Exclude<T, false | "" | 0 | 0n | null | undefined>;
Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).
Type Parameters
T
T
Parameters
value
T
Returns
value is Exclude<T, false | "" | 0 | 0n | null | undefined>
Call Signature
function isTruthy<T>(value): value is Extract<T, true>;
Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends boolean
Parameters
value
T
Returns
value is Extract<T, true>
Call Signature
function isTruthy<T>(value): value is Extract<T, number>;
Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends number
Parameters
value
T
Returns
value is Extract<T, number>
Call Signature
function isTruthy<T>(value): value is Extract<T, bigint>;
Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends bigint
Parameters
value
T
Returns
value is Extract<T, bigint>
Call Signature
function isTruthy<T>(value): value is Extract<T, null>;
Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends null
Parameters
value
T
Returns
value is Extract<T, null>
Call Signature
function isTruthy<T>(value): value is Extract<T, undefined>;
Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends undefined
Parameters
value
T
Returns
value is Extract<T, undefined>
Call Signature
function isTruthy<T>(value): value is Extract<T, string>;
Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).
Type Parameters
T
T extends string
Parameters
value
T
Returns
value is Extract<T, string>
### <a id="isUndefined"></a>isUndefined
@xylabs/sdk-js
Call Signature
function isUndefined(value): value is undefined;
Type guard that checks whether a value is undefined.
Parameters
value
unknown
Returns
value is undefined
Call Signature
function isUndefined<T>(value): value is Extract<T, undefined>;
Type guard that checks whether a value is undefined.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, undefined>
### <a id="isUndefinedOrNull"></a>isUndefinedOrNull
@xylabs/sdk-js
Call Signature
function isUndefinedOrNull(value): value is null | undefined;
Type guard that checks whether a value is undefined or null.
Parameters
value
unknown
Returns
value is null | undefined
Call Signature
function isUndefinedOrNull<T>(value): value is Extract<T, null | undefined>;
Type guard that checks whether a value is undefined or null.
Type Parameters
T
T
Parameters
value
T
Returns
value is Extract<T, null | undefined>
### <a id="isWeakMap"></a>isWeakMap
@xylabs/sdk-js
Call Signature
function isWeakMap(value): value is WeakMap<WeakKey, unknown>;
Type guard that checks whether a value is a WeakMap instance.
Parameters
value
unknown
Returns
value is WeakMap<WeakKey, unknown>
Call Signature
function isWeakMap<K, V, T>(value): value is Extract<T, WeakMap<K, V>>;
Type guard that checks whether a value is a WeakMap instance.
Type Parameters
K
K extends WeakKey
V
V
T
T extends WeakMap<K, V>
Parameters
value
T
Returns
value is Extract<T, WeakMap<K, V>>
### <a id="isWeakSet"></a>isWeakSet
@xylabs/sdk-js
Call Signature
function isWeakSet(value): value is WeakSet<WeakKey>;
Type guard that checks whether a value is a WeakSet instance.
Parameters
value
unknown
Returns
value is WeakSet<WeakKey>
Call Signature
function isWeakSet<K, T>(value): value is Extract<T, WeakSet<K>>;
Type guard that checks whether a value is a WeakSet instance.
Type Parameters
K
K extends WeakKey
T
T extends WeakSet<K>
Parameters
value
T
Returns
value is Extract<T, WeakSet<K>>
### <a id="span"></a>span
@xylabs/sdk-js
function span<T>(
name,
fn,
traceProvider?): T;
Executes a synchronous function within an OpenTelemetry span, recording status and exceptions.
Type Parameters
T
T
Parameters
name
string
The span name.
fn
() => T
The function to execute.
traceProvider?
TracerProvider
Returns
T
The return value of fn.
### <a id="spanAsync"></a>spanAsync
@xylabs/sdk-js
function spanAsync<T>(
name,
fn,
config?): Promise<T>;
Executes an async function within an OpenTelemetry span, with optional time budget monitoring.
Type Parameters
T
T
Parameters
name
string
The span name.
fn
() => Promise<T>
The async function to execute.
config?
SpanConfig
Optional span configuration (tracer, logger, time budget).
Returns
Promise<T>
The resolved value of fn.
### <a id="spanDurationInMillis"></a>spanDurationInMillis
@xylabs/sdk-js
function spanDurationInMillis(span): number;
Calculates the duration of a span in milliseconds from its high-resolution time tuple.
Parameters
span
ReadableSpan
The span to measure.
Returns
number
The span duration in milliseconds.
### <a id="spanRoot"></a>spanRoot
@xylabs/sdk-js
function spanRoot<T>(
name,
fn,
tracer?): T;
Executes a synchronous function within a new root span that has no parent, even if a span is already active.
Type Parameters
T
T
Parameters
name
string
The span name.
fn
() => T
The function to execute.
tracer?
Tracer
Optional tracer to use.
Returns
T
The return value of fn.
### <a id="spanRootAsync"></a>spanRootAsync
@xylabs/sdk-js
function spanRootAsync<T>(
name,
fn,
config?): Promise<T>;
Executes an async function within a new root span (no parent), with optional time budget monitoring.
Type Parameters
T
T
Parameters
name
string
The span name.
fn
() => Promise<T>
The async function to execute.
config?
SpanConfig
Optional span configuration (tracer, logger, time budget).
Returns
Promise<T>
The resolved value of fn.
### <a id="staticImplements"></a>staticImplements
@xylabs/sdk-js
function staticImplements<T>(): <U>(constructor) => void;
Annotation to decorate classes which implement static methods
Type Parameters
T
T
Returns
The decorated class requiring it to implement
the members of the the type as static properties/methods
<U>(constructor) => void
### <a id="timeBudget"></a>timeBudget
@xylabs/sdk-js
function timeBudget<TResult>(
name,
logger,
func,
budget,
status?): Promise<TResult>;
Executes an async function and logs a warning if it exceeds the given time budget.
Type Parameters
TResult
TResult
Parameters
name
string
A label for the function, used in warning messages.
logger
Logger | undefined
The logger to use for budget-exceeded warnings.
func
() => Promise<TResult>
The async function to execute.
budget
number
The time budget in milliseconds.
status?
boolean
If true, logs periodic warnings while the function is still running.
Returns
Promise<TResult>
The result of the executed function.
### <a id="toAddressV2"></a>toAddressV2
@xylabs/sdk-js
function toAddressV2(value, assert?): BrandedAddress | undefined;
Alpha
Parameters
value
unknown
assert?
boolean
Returns
BrandedAddress | undefined
### <a id="toArrayBuffer"></a>toArrayBuffer
@xylabs/sdk-js
Call Signature
function toArrayBuffer(
value,
padLength?,
base?): undefined;
Converts a string, bigint, or ArrayBufferLike to an ArrayBufferLike, with optional zero-padding.
Parameters
value
undefined
The value to convert (hex string, bigint, or existing buffer)
padLength?
number
Minimum byte length, left-padded with zeros if needed
base?
number
Numeric base for string parsing (default 16)
Returns
undefined
The resulting ArrayBufferLike, or undefined if value is undefined
Call Signature
function toArrayBuffer(
value,
padLength?,
base?): ArrayBufferLike;
Converts a string, bigint, or ArrayBufferLike to an ArrayBufferLike, with optional zero-padding.
Parameters
value
string | bigint | ArrayBufferLike
The value to convert (hex string, bigint, or existing buffer)
padLength?
number
Minimum byte length, left-padded with zeros if needed
base?
number
Numeric base for string parsing (default 16)
Returns
ArrayBufferLike
The resulting ArrayBufferLike, or undefined if value is undefined
Call Signature
function toArrayBuffer(
value,
padLength?,
base?): ArrayBufferLike | undefined;
Converts a string, bigint, or ArrayBufferLike to an ArrayBufferLike, with optional zero-padding.
Parameters
value
string | bigint | ArrayBufferLike | undefined
The value to convert (hex string, bigint, or existing buffer)
padLength?
number
Minimum byte length, left-padded with zeros if needed
base?
number
Numeric base for string parsing (default 16)
Returns
ArrayBufferLike | undefined
The resulting ArrayBufferLike, or undefined if value is undefined
### <a id="toPromise"></a>toPromise
@xylabs/sdk-js
function toPromise<T>(value): Promise<T>;
Wraps a value in a Promise if it is not already one.
Type Parameters
T
T
Parameters
value
Promisable<T>
A value that may or may not be a Promise.
Returns
Promise<T>
A Promise resolving to the value.
### <a id="toUint8Array"></a>toUint8Array
@xylabs/sdk-js
Call Signature
function toUint8Array(
value,
padLength?,
base?): undefined;
Converts a string, bigint, or ArrayBufferLike to a Uint8Array, with optional zero-padding.
Parameters
value
undefined
The value to convert
padLength?
number
Minimum byte length, left-padded with zeros if needed
base?
number
Numeric base for string parsing (default 16)
Returns
undefined
The resulting Uint8Array, or undefined if value is undefined
Call Signature
function toUint8Array(
value,
padLength?,
base?): Uint8Array;
Converts a string, bigint, or ArrayBufferLike to a Uint8Array, with optional zero-padding.
Parameters
value
string | bigint | ArrayBufferLike
The value to convert
padLength?
number
Minimum byte length, left-padded with zeros if needed
base?
number
Numeric base for string parsing (default 16)
Returns
Uint8Array
The resulting Uint8Array, or undefined if value is undefined
Call Signature
function toUint8Array(
value,
padLength?,
base?): Uint8Array<ArrayBufferLike> | undefined;
Converts a string, bigint, or ArrayBufferLike to a Uint8Array, with optional zero-padding.
Parameters
value
string | bigint | ArrayBufferLike | undefined
The value to convert
padLength?
number
Minimum byte length, left-padded with zeros if needed
base?
number
Numeric base for string parsing (default 16)
Returns
Uint8Array<ArrayBufferLike> | undefined
The resulting Uint8Array, or undefined if value is undefined
### <a id="zodAllFactory"></a>zodAllFactory
@xylabs/sdk-js
function zodAllFactory<T, TName>(zod, name): object;
Alpha
Creates a bundle of is, as, and to factory functions for a given zod schema.
Type Parameters
T
T
TName
TName extends string
Parameters
zod
ZodType<T>
The zod schema to validate against
name
TName
The name used to suffix the generated function names (e.g. 'Address' produces isAddress, asAddress, toAddress)
Returns
object
An object containing is<Name>, as<Name>, and to<Name> functions
### <a id="zodAsAsyncFactory"></a>zodAsAsyncFactory
@xylabs/sdk-js
function zodAsAsyncFactory<TZod>(zod, name): {
<T> (value): Promise<T & TZod | undefined>;
<T> (value, assert): Promise<T & TZod>;
};
Creates an async function that validates a value against a zod schema and returns it with a narrowed type.
Uses safeParseAsync for schemas with async refinements. When called without an assert config, returns undefined on failure.
Type Parameters
TZod
TZod
Parameters
zod
ZodType<TZod>
The zod schema to validate against
name
string
A name used in error messages for identification
Returns
An async function that validates and narrows the type of a value
{
<T> (value): Promise<T & TZod | undefined>;
<T> (value, assert): Promise<T & TZod>;
}
### <a id="zodAsFactory"></a>zodAsFactory
@xylabs/sdk-js
function zodAsFactory<TZod>(zod, name): {
<T> (value): T & TZod | undefined;
<T> (value, assert): T & TZod;
};
Creates a function that validates a value against a zod schema and returns it with a narrowed type.
When called without an assert config, returns undefined on failure. When called with an assert config, throws on failure.
Type Parameters
TZod
TZod
Parameters
zod
ZodType<TZod>
The zod schema to validate against
name
string
A name used in error messages for identification
Returns
A function that validates and narrows the type of a value
{
<T> (value): T & TZod | undefined;
<T> (value, assert): T & TZod;
}
### <a id="zodIsFactory"></a>zodIsFactory
@xylabs/sdk-js
function zodIsFactory<TZod>(zod): <T>(value) => value is T & TZod;
Creates a type guard function that checks if a value matches a zod schema.
Type Parameters
TZod
TZod
Parameters
zod
ZodType<TZod>
The zod schema to validate against
Returns
A type guard function that returns true if the value passes validation
<T>(value) => value is T & TZod
### <a id="zodToAsyncFactory"></a>zodToAsyncFactory
@xylabs/sdk-js
function zodToAsyncFactory<TZod>(zod, name): {
<T> (value): Promise<T & TZod | undefined>;
<T> (value, assert): Promise<T & TZod>;
};
Creates an async function that converts a value to the zod schema type, delegating to zodAsAsyncFactory internally.
Provides overloads for optional assertion: without assert config resolves to undefined on failure, with assert config throws on failure.
Type Parameters
TZod
TZod
Parameters
zod
ZodType<TZod>
The zod schema to validate against
name
string
A name used in error messages for identification
Returns
An async function that validates and converts a value to the schema type
{
<T> (value): Promise<T & TZod | undefined>;
<T> (value, assert): Promise<T & TZod>;
}
### <a id="zodToFactory"></a>zodToFactory
@xylabs/sdk-js
function zodToFactory<TZod>(zod, name): {
<T> (value): T & TZod | undefined;
<T> (value, assert): T & TZod;
};
Creates a function that converts a value to the zod schema type, delegating to zodAsFactory internally.
Provides overloads for optional assertion: without assert config returns undefined on failure, with assert config throws on failure.
Type Parameters
TZod
TZod
Parameters
zod
ZodType<TZod>
The zod schema to validate against
name
string
A name used in error messages for identification
Returns
A function that validates and converts a value to the schema type
{
<T> (value): T & TZod | undefined;
<T> (value, assert): T & TZod;
}
### interfaces
### <a id="ApiConfig"></a>ApiConfig
@xylabs/sdk-js
Configuration for connecting to an API, including domain, authentication, and user identification.
Properties
apiDomain
apiDomain: string;
apiKey?
optional apiKey?: string;
jwtToken?
optional jwtToken?: string;
userid?
optional userid?: string;
### <a id="AsTypeFunction"></a>AsTypeFunction
@xylabs/sdk-js
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
Type Parameters
T
T extends AnyNonPromise = AnyNonPromise
Call Signature
AsTypeFunction<TType>(value): TType | undefined;
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
Type Parameters
TType
TType extends AnyNonPromise
Parameters
value
AnyNonPromise
Returns
TType | undefined
Call Signature
AsTypeFunction<TType>(value, config): TType;
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
Type Parameters
TType
TType extends AnyNonPromise
Parameters
value
AnyNonPromise
config
TypeCheckRequiredConfig
Returns
TType
Call Signature
AsTypeFunction<TType>(value, config): TType | undefined;
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
Type Parameters
TType
TType extends AnyNonPromise
Parameters
value
AnyNonPromise
config
| TypeCheckConfig
| TypeCheckOptionalConfig
Returns
TType | undefined
Call Signature
AsTypeFunction<TType>(value, assert): TType | undefined;
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
Type Parameters
TType
TType extends AnyNonPromise
Parameters
value
AnyNonPromise
assert
StringOrAlertFunction<TType>
Returns
TType | undefined
Call Signature
AsTypeFunction<TType>(
value,
assert,
config): TType;
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
Type Parameters
TType
TType extends AnyNonPromise
Parameters
value
AnyNonPromise
assert
StringOrAlertFunction<TType>
config
TypeCheckRequiredConfig
Returns
TType
Call Signature
AsTypeFunction<TType>(
value,
assert,
config): TType | undefined;
A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
Type Parameters
TType
TType extends AnyNonPromise
Parameters
value
AnyNonPromise
assert
StringOrAlertFunction<TType>
config
| TypeCheckConfig
| TypeCheckOptionalConfig
Returns
TType | undefined
### <a id="BaseEmitterParamsFields"></a>BaseEmitterParamsFields
@xylabs/sdk-js
Fields specific to BaseEmitter configuration parameters.
### <a id="BaseParamsFields"></a>BaseParamsFields
@xylabs/sdk-js
Common parameter fields available to all Base instances (logger, meter, tracer).
Properties
logger?
optional logger?: Logger;
meterProvider?
optional meterProvider?: MeterProvider;
traceProvider?
optional traceProvider?: TracerProvider;
### <a id="Creatable"></a>Creatable
@xylabs/sdk-js
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/sdk-js
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/sdk-js
Represents a created instance with a managed lifecycle (start/stop) and event emission.
Extends
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/sdk-js
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/sdk-js
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/sdk-js
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="DebugOptions"></a>DebugOptions
@xylabs/sdk-js
Configure debug options of an instance.
Properties
enabled?
optional enabled?: boolean;
logger?
optional logger?: DebugLogger;
name
readonly name: string;
### <a id="EventEmitter"></a>EventEmitter
@xylabs/sdk-js
Interface for a typed event emitter that supports subscribing, unsubscribing, and emitting events.
Extended by
Type Parameters
T
T extends EventData
Properties
eventData
eventData: T;
Type-level reference to the event data shape for external type queries.
Methods
clearListeners()
clearListeners(eventNames): void;
Removes all listeners for the specified event name(s).
Parameters
eventNames
keyof T | keyof T[]
Returns
void
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
T[TEventName]
Returns
Promise<void>
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
T[TEventName]
Returns
Promise<void>
listenerCount()
listenerCount(eventNames): number;
Returns the total number of listeners registered for the specified event name(s).
Parameters
eventNames
keyof T | keyof T[]
Returns
number
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<T[TEventName]>
Returns
void
offAny()
offAny(listener): void;
Removes a wildcard listener that was receiving all events.
Parameters
listener
| Promise<void>
| EventAnyListener
Returns
void
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<T[TEventName]>
Returns
EventUnsubscribeFunction
onAny()
onAny(listener): EventUnsubscribeFunction;
Subscribes a wildcard listener that receives all events and returns an unsubscribe function.
Parameters
listener
EventAnyListener
Returns
EventUnsubscribeFunction
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<T[TEventName]>
Returns
EventUnsubscribeFunction
### <a id="EventListenerInfo"></a>EventListenerInfo
@xylabs/sdk-js
Information about a registered event listener, including an optional filter for selective invocation.
Type Parameters
TEventArgs
TEventArgs extends EventArgs = EventArgs
Properties
filter?
optional filter?: TEventArgs;
listener
listener: EventListener<TEventArgs>;
### <a id="FetchCompressOptions"></a>FetchCompressOptions
@xylabs/sdk-js
Extends
Properties
compressMinLength?
optional compressMinLength?: number;
Gzip payloads larger than this byte count. Requires pako to be installed.
### <a id="FetchJsonResponse"></a>FetchJsonResponse
@xylabs/sdk-js
Structured response from a fetchJson call.
Type Parameters
T
T
Properties
data
data: T | null;
headers: Headers;
response
response: Response;
status
status: number;
statusText
statusText: string;
### <a id="ForgetNodeConfig"></a>ForgetNodeConfig
@xylabs/sdk-js
Node.js-specific forget configuration that extends ForgetConfig with process termination options.
Extends
Type Parameters
T
T = any
Properties
name?
optional name?: string;
Optional name for identifying the forgotten promise in logs.
Inherited from
ForgetConfig.name
onCancel?
optional onCancel?: () => void;
Called when the promise is cancelled due to timeout.
Returns
void
Inherited from
ForgetConfig.onCancel
onComplete?
optional onComplete?: (result) => void;
Called when the promise completes, with a tuple of [result, error].
Parameters
result
[T | undefined, Error | undefined]
Returns
void
Inherited from
ForgetConfig.onComplete
onException?
optional onException?: (error) => void;
Called when an exception occurs outside the promise itself.
Parameters
error
Error
Returns
void
Inherited from
ForgetConfig.onException
timeout?
optional timeout?: number;
Timeout in milliseconds after which the promise is considered timed out.
Inherited from
ForgetConfig.timeout
terminateOnException?
optional terminateOnException?: boolean;
Terminate the process on an exception that happens outside of the promise being forgotten.
terminateOnTimeout?
optional terminateOnTimeout?: boolean;
Terminate the process if the promise times out.
### <a id="HexConfig"></a>HexConfig
@xylabs/sdk-js
Configuration of validation and output format
Properties
bitLength?
optional bitLength?: number;
byteSize?
optional byteSize?: number;
prefix?
optional prefix?: boolean;
### <a id="KeyValueStore"></a>KeyValueStore
@xylabs/sdk-js
A read/write storage device.
Extends
Type Parameters
TValue
TValue
TKey
TKey = string
Methods
get()
get(key): Promisable<TValue | undefined>;
Returns a promise that resolves to the value for the given key.
Parameters
key
TKey
The key to get the value for.
Returns
Promisable<TValue | undefined>
Inherited from
ReadonlyKeyValueStore.get
keys()?
optional keys(): Promisable<TKey[]>;
The keys an array of keys.
Returns
Promisable<TKey[]>
Inherited from
ReadonlyKeyValueStore.keys
clear()?
optional clear(): Promisable<void>;
Removes all entries from the store.
Returns
Promisable<void>
delete()
delete(key): Promisable<void>;
Deletes the entry with the given key.
Parameters
key
TKey
The key of the entry to delete
Returns
Promisable<void>
set()
set(key, value): Promisable<void>;
Sets a value for the given key, creating or updating the entry.
Parameters
key
TKey
The key to set
value
TValue
The value to store
Returns
Promisable<void>
### <a id="Logger"></a>Logger
@xylabs/sdk-js
Interface to handle overlap between Winston &
console with as much congruency as possible.
Properties
debug
debug: LogFunction;
error
error: LogFunction;
info
info: LogFunction;
log
log: LogFunction;
trace
trace: LogFunction;
warn
warn: LogFunction;
### <a id="MetaEventData"></a>MetaEventData
@xylabs/sdk-js
Data shape for internal meta events that fire when listeners are added or removed.
Type Parameters
TEventData
TEventData extends EventData
Properties
listenerAdded
listenerAdded: object;
eventName?
optional eventName?: keyof TEventData;
listener
listener:
| EventListener<TEventData[keyof TEventData]>
| EventAnyListener<TEventData[keyof TEventData]>;
listenerRemoved
listenerRemoved: object;
eventName?
optional eventName?: keyof TEventData;
listener
listener:
| EventListener<TEventData[keyof TEventData]>
| EventAnyListener<TEventData[keyof TEventData]>;
### <a id="ObjectTypeConfig"></a>ObjectTypeConfig
@xylabs/sdk-js
Configuration options for object type checking.
Extends
Properties
log?
optional log?: boolean | Logger;
Inherited from
TypeCheckConfig.log
### <a id="PromiseType"></a>PromiseType
@xylabs/sdk-js
An interface representing any thenable (promise-like) object.
Properties
then
then: () => unknown;
Returns
unknown
### <a id="ReadonlyKeyValueStore"></a>ReadonlyKeyValueStore
@xylabs/sdk-js
A readonly storage device.
Extended by
Type Parameters
TValue
TValue
TKey
TKey = string
Methods
get()
get(key): Promisable<TValue | undefined>;
Returns a promise that resolves to the value for the given key.
Parameters
key
TKey
The key to get the value for.
Returns
Promisable<TValue | undefined>
keys()?
optional keys(): Promisable<TKey[]>;
The keys an array of keys.
Returns
Promisable<TKey[]>
### <a id="RequiredCreatableParams"></a>RequiredCreatableParams
@xylabs/sdk-js
The minimum required parameters for constructing a creatable.
Extends
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="RetryConfig"></a>RetryConfig
@xylabs/sdk-js
Configuration for retry behavior.
Extended by
Properties
backoff?
optional backoff?: number;
Multiplier applied to the interval after each retry. Defaults to 2.
interval?
optional interval?: number;
Initial delay in milliseconds between retries. Defaults to 100.
retries?
optional retries?: number;
Maximum number of retry attempts. Defaults to 0 (no retries).
### <a id="RetryConfigWithComplete"></a>RetryConfigWithComplete
@xylabs/sdk-js
Retry configuration extended with a custom completion check.
Extends
Type Parameters
T
T = unknown
Properties
backoff?
optional backoff?: number;
Multiplier applied to the interval after each retry. Defaults to 2.
Inherited from
RetryConfig.backoff
interval?
optional interval?: number;
Initial delay in milliseconds between retries. Defaults to 100.
Inherited from
RetryConfig.interval
retries?
optional retries?: number;
Maximum number of retry attempts. Defaults to 0 (no retries).
Inherited from
RetryConfig.retries
complete?
optional complete?: (result?) => boolean;
Determines whether the result is considered complete. Defaults to checking for a defined value.
Parameters
result?
T
Returns
boolean
### <a id="SpanConfig"></a>SpanConfig
@xylabs/sdk-js
Configuration options for span creation and execution.
Properties
logger?
optional logger?: Logger | null;
Optional logger for time budget warnings. Falls back to console if not provided.
timeBudgetLimit?
optional timeBudgetLimit?: number;
Maximum allowed execution time in milliseconds before logging a warning.
tracer?
optional tracer?: Tracer;
OpenTelemetry tracer to use. Defaults to a tracer named after the span.
### <a id="TypeCheck"></a>TypeCheck
@xylabs/sdk-js
A type guard function that checks whether a value conforms to type T, with optional configuration.
Type Parameters
T
T extends TypedValue
Call Signature
TypeCheck(obj): obj is T;
A type guard function that checks whether a value conforms to type T, with optional configuration.
Parameters
obj
AnyNonPromise
Returns
obj is T
Call Signature
TypeCheck(obj, config): obj is T;
A type guard function that checks whether a value conforms to type T, with optional configuration.
Parameters
obj
AnyNonPromise
config
TypeCheckConfig
Returns
obj is T
Call Signature
TypeCheck(obj, config): obj is T;
A type guard function that checks whether a value conforms to type T, with optional configuration.
Parameters
obj
AnyNonPromise
config
number | TypeCheckConfig | undefined
Returns
obj is T
### <a id="TypeCheckConfig"></a>TypeCheckConfig
@xylabs/sdk-js
Configuration options for type check functions, with optional logging.
Extended by
Properties
log?
optional log?: boolean | Logger;
### <a id="TypeCheckOptionalConfig"></a>TypeCheckOptionalConfig
@xylabs/sdk-js
Type check configuration that marks the value as optional, returning undefined on failure.
Extends
Properties
log?
optional log?: boolean | Logger;
Inherited from
TypeCheckConfig.log
required
required: false;
### <a id="TypeCheckRequiredConfig"></a>TypeCheckRequiredConfig
@xylabs/sdk-js
Type check configuration that marks the value as required, causing assertions on failure.
Extends
Properties
log?
optional log?: boolean | Logger;
Inherited from
TypeCheckConfig.log
required
required: true;
### <a id="Validator"></a>Validator
@xylabs/sdk-js
Interface for validating objects and returning any errors found.
Type Parameters
T
T extends EmptyObject = AnyObject
Methods
validate()
validate(payload): Promisable<Error[]>;
Parameters
payload
T
Returns
Promisable<Error[]>
### <a id="WithLabels"></a>WithLabels
@xylabs/sdk-js
Interface for objects that have labels.
Type Parameters
T
T extends Labels = Labels
Properties
labels
labels: T;
### <a id="WithOptionalLabels"></a>WithOptionalLabels
@xylabs/sdk-js
Interface for objects that have labels.
Type Parameters
T
T extends Labels = Labels
Properties
labels?
optional labels?: T;
### <a id="ZodFactoryConfigObject"></a>ZodFactoryConfigObject
@xylabs/sdk-js
Configuration object for zod factory functions, providing a name for error messages.
Properties
name
name: string;
### type-aliases
### <a id="Address"></a>Address
@xylabs/sdk-js
type Address = z.infer<typeof AddressZod>;
A validated 20-byte address string type, inferred from the AddressZod schema.
### <a id="AddressTransformZodType"></a>AddressTransformZodType
@xylabs/sdk-js
type AddressTransformZodType = z.infer<typeof AddressTransformZod>;
The output type of AddressTransformZod after parsing and transformation.
### <a id="AddressValidationZodType"></a>AddressValidationZodType
@xylabs/sdk-js
type AddressValidationZodType = z.infer<typeof AddressValidationZod>;
The output type of AddressValidationZod after parsing.
### <a id="AllZodFactories"></a>AllZodFactories
@xylabs/sdk-js
type AllZodFactories<TType, TName> = Record<`is${TName}`, ReturnType<typeof zodIsFactory>> & Record<`as${TName}`, ReturnType<typeof zodAsFactory>> & Record<`to${TName}`, ReturnType<typeof zodToFactory>>;
Alpha
Type Parameters
TType
TType
TName
TName extends string
### <a id="AnyFunction"></a>AnyFunction
@xylabs/sdk-js
type AnyFunction = (...args) => unknown;
A function type that accepts any arguments and returns unknown.
Parameters
args
...unknown[]
Returns
unknown
### <a id="AnyNonPromise"></a>AnyNonPromise
@xylabs/sdk-js
type AnyNonPromise = Exclude<TypedValue, PromiseType>;
Any non-promise typed value, excluding thenables.
### <a id="AnyObject"></a>AnyObject
@xylabs/sdk-js
type AnyObject = EmptyObject & Partial<Record<TypedKey, unknown>>;
Any object, which means that it does not enforce the set of fields that it has. Extending from AnyObject
will result in a type that includes the universal set of field names
### <a id="ApiStage"></a>ApiStage
@xylabs/sdk-js
type ApiStage = EnumValue<typeof ApiStage>;
A valid API stage value ('prod', 'beta', or 'local').
### <a id="AsOptionalTypeFunction"></a>AsOptionalTypeFunction
@xylabs/sdk-js
type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined;
A simplified type-narrowing function that returns T or undefined, without assertion support.
Type Parameters
T
T extends AnyNonPromise = AnyNonPromise
Type Parameters
TType
TType extends T
Parameters
value
AnyNonPromise
Returns
TType | undefined
### <a id="AssertConfig"></a>AssertConfig
@xylabs/sdk-js
type AssertConfig = string | AssertCallback | boolean;
Configuration for assertion behavior: a static message string, a boolean toggle, or a callback.
### <a id="AsyncMutex"></a>AsyncMutex
@xylabs/sdk-js
type AsyncMutex<T> = Promise<T>;
Type Parameters
T
T
Description
Used to document promises that are being used as Mutexes
### <a id="BaseClassName"></a>BaseClassName
@xylabs/sdk-js
type BaseClassName = string & object;
Branded string type representing a class name used for global instance tracking.
Type Declaration
__baseClassName
__baseClassName: true;
### <a id="BaseEmitterParams"></a>BaseEmitterParams
@xylabs/sdk-js
type BaseEmitterParams<T> = BaseParams<T & BaseEmitterParamsFields & T>;
Parameters type for configuring a BaseEmitter instance.
Type Parameters
T
T extends EmptyObject = EmptyObject
### <a id="BaseParams"></a>BaseParams
@xylabs/sdk-js
type BaseParams<TAdditionalParams> = TAdditionalParams & BaseParamsFields;
Parameters for constructing a Base instance, combining BaseParamsFields with optional additional params.
Type Parameters
TAdditionalParams
TAdditionalParams extends EmptyObject = EmptyObject
### <a id="Brand"></a>Brand
@xylabs/sdk-js
type Brand<T, B> = T & { [K in keyof B]: B[K] };
Creates a branded type by intersecting base type T with brand type B, enabling nominal typing in TypeScript.
Type Parameters
T
T
B
B
### <a id="BrandedHash"></a>BrandedHash
@xylabs/sdk-js
type BrandedHash = Brand<Hex, {
__hash: true;
}>;
Branded type representing a validated hash hex string.
### <a id="BrandedHex"></a>BrandedHex
@xylabs/sdk-js
type BrandedHex = Brand<Lowercase<string>, {
__hex: true;
}>;
Branded type representing a validated lowercase hex string.
### <a id="Compare"></a>Compare
@xylabs/sdk-js
type Compare<T> = (a, b) => number;
A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b.
Type Parameters
T
T
Parameters
a
T
b
T
Returns
number
### <a id="CreatableName"></a>CreatableName
@xylabs/sdk-js
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/sdk-js
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="DebugLogger"></a>DebugLogger
@xylabs/sdk-js
type DebugLogger = (type, debugName, eventName?, eventData?) => void;
Emittery can collect and log debug information.
To enable this feature set the DEBUG environment variable to emittery or *. Additionally, you can set the static isDebugEnabled variable to true
on the Emittery class, or myEmitter.debug.enabled on an instance of it for debugging a single instance.
See API for more information on how debugging works.
Parameters
type
string
debugName
string
eventName?
EventName
eventData?
EventArgs
Returns
void
### <a id="DeepOmitStartsWith"></a>DeepOmitStartsWith
@xylabs/sdk-js
type DeepOmitStartsWith<T, Prefix> = T extends infer U[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? { [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix> } : T;
Recursively omits keys that start with the given prefix, including in nested objects and arrays.
Type Parameters
T
T
Prefix
Prefix extends string
### <a id="DeepPickStartsWith"></a>DeepPickStartsWith
@xylabs/sdk-js
type DeepPickStartsWith<T, Prefix> = T extends infer U[] ? DeepPickStartsWith<U, Prefix>[] : T extends object ? { [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? K : never : K]: DeepPickStartsWith<T[K], Prefix> } : T;
Recursively picks only the keys that start with the given prefix, including in nested objects and arrays.
Type Parameters
T
T
Prefix
Prefix extends string
### <a id="DeepRestrictToJson"></a>DeepRestrictToJson
@xylabs/sdk-js
type DeepRestrictToJson<T> = { [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToJson<U>[] : T[K] extends object ? DeepRestrictToJson<T[K]> : T[K] extends JsonValue ? T[K] : never };
Recursively restricts an object type to only JSON-compatible values, excluding non-serializable types.
Type Parameters
T
T
### <a id="DeepRestrictToStringKeys"></a>DeepRestrictToStringKeys
@xylabs/sdk-js
type DeepRestrictToStringKeys<T> = { [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K] };
Recursively removes all non-string keys from an object type, including in nested objects and arrays.
Type Parameters
T
T
### <a id="EmptyObject"></a>EmptyObject
@xylabs/sdk-js
type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | ((...args) => unknown) | null>;
An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
extended from, which then adds only those additional fields
Type Parameters
T
T extends object = object
### <a id="Enum"></a>Enum
@xylabs/sdk-js
type Enum<T> = { readonly [K in keyof T]: T[K] };
A utility type that, given a Record<string, unknown>, returns a readonly version
of that record. This results in a type where all properties of T are readonly.
Type Parameters
T
T extends Readonly<Record<string | number | symbol, unknown>>
The record type to make readonly.
Example
export const DnsRecordType = Enum({
A: 1,
AAAA: 28,
CAA: 257,
CNAME: 5,
DNAME: 39,
MX: 15,
NS: 2,
PTR: 12,
SOA: 6,
SPF: 99,
SRV: 33,
TXT: 16,
})
export type DnsRecordType = Enum<typeof DnsRecordType>
### <a id="EnumKey"></a>EnumKey
@xylabs/sdk-js
type EnumKey<T, K> = keyof K;
A utility type that, given an Enum object, returns the union of its keys.
Type Parameters
T
T extends Record<string | number | symbol, unknown>
K
K = Enum<T>
### <a id="EnumValue"></a>EnumValue
@xylabs/sdk-js
type EnumValue<T, K> = K[keyof K];
A utility type that, given an Enum object, returns the union of its values.
Type Parameters
T
T extends Record<string | number | symbol, unknown>
K
K = Enum<T>
### <a id="EthAddress"></a>EthAddress
@xylabs/sdk-js
type EthAddress = Brand<string, {
__eth_address: true;
}>;
Branded type representing a validated Ethereum address with 0x prefix.
### <a id="EventAnyListener"></a>EventAnyListener
@xylabs/sdk-js
type EventAnyListener<TEventArgs> = (eventName, eventData) => Promisable<void>;
A listener that receives all events regardless of name.
Type Parameters
TEventArgs
TEventArgs extends EventArgs = EventArgs
Parameters
eventName
EventName
The name of the emitted event.
eventData
TEventArgs
The data associated with the event.
Returns
Promisable<void>
### <a id="EventArgs"></a>EventArgs
@xylabs/sdk-js
type EventArgs = string | number | object;
The allowed types for event argument payloads.
### <a id="EventData"></a>EventData
@xylabs/sdk-js
type EventData = Record<EventName, EventArgs>;
A mapping of event names to their corresponding event argument types.
### <a id="EventListener"></a>EventListener
@xylabs/sdk-js
type EventListener<TEventArgs> = (eventData) => Promisable<void>;
A listener for a specific event type.
Type Parameters
TEventArgs
TEventArgs extends EventArgs = EventArgs
Parameters
eventData
TEventArgs
The data associated with the event.
Returns
Promisable<void>
### <a id="EventName"></a>EventName
@xylabs/sdk-js
type EventName = PropertyKey;
A valid event name, which can be any property key (string, number, or symbol).
### <a id="EventUnsubscribeFunction"></a>EventUnsubscribeFunction
@xylabs/sdk-js
type EventUnsubscribeFunction = () => void;
A function returned by event subscription methods that unsubscribes the listener when called.
Returns
void
### <a id="EventsParams"></a>EventsParams
@xylabs/sdk-js
type EventsParams = BaseParams<{
debug?: DebugOptions;
}>;
Parameters for constructing an Events instance, with optional debug configuration.
### <a id="FetchJsonOptions"></a>FetchJsonOptions
@xylabs/sdk-js
type FetchJsonOptions = FetchCompressOptions;
Fetch request options extended with an optional gzip compression threshold.
### <a id="FieldType"></a>FieldType
@xylabs/sdk-js
type FieldType =
| "string"
| "number"
| "object"
| "symbol"
| "undefined"
| "null"
| "array"
| "function";
Union of string literals representing the possible types of an object field.
### <a id="Hash"></a>Hash
@xylabs/sdk-js
type Hash = z.infer<typeof HashZod>;
A validated hash string type, inferred from the HashZod schema.
### <a id="HashBitLength"></a>HashBitLength
@xylabs/sdk-js
type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
Valid bit lengths for hash values.
### <a id="Hex"></a>Hex
@xylabs/sdk-js
type Hex = z.infer<typeof HexZod>;
A validated hex string type, inferred from the HexZod schema.
### <a id="IdentityFunction"></a>IdentityFunction
@xylabs/sdk-js
type IdentityFunction<T> = (value) => value is T;
A type guard function that narrows an unknown value to type T.
Type Parameters
T
T
Parameters
value
unknown
Returns
value is T
### <a id="JsonArray"></a>JsonArray
@xylabs/sdk-js
type JsonArray = z.infer<typeof JsonArrayZod>;
A JSON array containing JSON values.
### <a id="JsonObject"></a>JsonObject
@xylabs/sdk-js
type JsonObject = z.infer<typeof JsonObjectZod>;
A JSON object with string keys and JSON values.
### <a id="JsonValue"></a>JsonValue
@xylabs/sdk-js
type JsonValue = z.infer<typeof JsonValueZod>;
A recursive JSON value: string, number, boolean, null, array, or object.
### <a id="Labels"></a>Labels
@xylabs/sdk-js
type Labels = Record<string, string | undefined>;
Object used to represent labels identifying a resource.
### <a id="LogFunction"></a>LogFunction
@xylabs/sdk-js
type LogFunction = (...data) => void;
A generic logging function that accepts any number of arguments.
Parameters
data
...unknown[]
Returns
void
### <a id="LogLevelKey"></a>LogLevelKey
@xylabs/sdk-js
type LogLevelKey = EnumKey<typeof LogLevel>;
String key for a log level (e.g. 'error', 'warn', 'info').
### <a id="LogLevelValue"></a>LogLevelValue
@xylabs/sdk-js
type LogLevelValue = EnumValue<typeof LogLevel>;
Numeric value of a log level (1 through 6).
### <a id="LogVerbosity"></a>LogVerbosity
@xylabs/sdk-js
type LogVerbosity = LogLevelKey;
Alias for LogLevelKey, representing the verbosity setting as a string.
### <a id="NullablePromisable"></a>NullablePromisable
@xylabs/sdk-js
type NullablePromisable<T, V> = Promisable<T | null, V>;
A Promisable that may resolve to null.
Type Parameters
T
T
V
V = never
### <a id="NullablePromisableArray"></a>NullablePromisableArray
@xylabs/sdk-js
type NullablePromisableArray<T, V> = PromisableArray<T | null, V>;
A Promisable array where elements may be null.
Type Parameters
T
T
V
V = never
### <a id="ObjectTypeShape"></a>ObjectTypeShape
@xylabs/sdk-js
type ObjectTypeShape = Record<string | number | symbol, FieldType>;
Describes the expected shape of an object by mapping each key to its expected field type.
### <a id="OmitByPredicate"></a>OmitByPredicate
@xylabs/sdk-js
type OmitByPredicate<T> = (value, key) => boolean;
A predicate function used to determine which properties to omit from an object.
Type Parameters
T
T extends EmptyObject = Record<string, unknown>
Parameters
value
T[keyof T]
key
keyof T
Returns
boolean
### <a id="OmitStartsWith"></a>OmitStartsWith
@xylabs/sdk-js
type OmitStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string}` ? never : K]: T[K] };
Omits the keys of T that start with the given prefix.
Type Parameters
T
T
Prefix
Prefix extends string
### <a id="Optional"></a>Optional
@xylabs/sdk-js
type Optional<T, F> = Omit<T, F> & Partial<Pick<T, F>>;
Makes the specified fields of T optional while keeping the rest required.
Type Parameters
T
T extends object
F
F extends keyof T
### <a id="OptionalPromisable"></a>OptionalPromisable
@xylabs/sdk-js
type OptionalPromisable<T, V> = Promisable<T | undefined, V>;
A Promisable that may resolve to undefined.
Type Parameters
T
T
V
V = never
### <a id="OptionalPromisableArray"></a>OptionalPromisableArray
@xylabs/sdk-js
type OptionalPromisableArray<T, V> = PromisableArray<T | undefined, V>;
A Promisable array where elements may be undefined.
Type Parameters
T
T
V
V = never
### <a id="Override"></a>Override
@xylabs/sdk-js
type Override<T1, T2> = Omit<T1, keyof T2> & T2;
Overrides properties of T1 with those from T2.
Type Parameters
T1
T1
T2
T2
### <a id="PartialRecord"></a>PartialRecord
@xylabs/sdk-js
type PartialRecord<K, T> = Partial<Record<K, T>>;
Type Parameters
K
K extends keyof any
T
T
Deprecated
use Partial<Record<>> instead
### <a id="PickByPredicate"></a>PickByPredicate
@xylabs/sdk-js
type PickByPredicate<T> = (value, key) => boolean;
A predicate function used to determine which properties to pick from an object.
Type Parameters
T
T extends EmptyObject = Record<string, unknown>
Parameters
value
T[keyof T]
key
keyof T
Returns
boolean
### <a id="PickStartsWith"></a>PickStartsWith
@xylabs/sdk-js
type PickStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string}` ? K : never]: T[K] };
Picks only the keys of T that start with the given prefix.
Type Parameters
T
T
Prefix
Prefix extends string
### <a id="Profiler"></a>Profiler
@xylabs/sdk-js
type Profiler = Record<string, number[]>;
A record of named timing entries, where each key maps to an array of timestamps.
### <a id="Promisable"></a>Promisable
@xylabs/sdk-js
type Promisable<T, V> = PromiseEx<T, V> | Promise<T> | T;
A value that may be a Promise, PromiseEx, or a plain synchronous value.
Type Parameters
T
T
V
V = never
### <a id="PromisableArray"></a>PromisableArray
@xylabs/sdk-js
type PromisableArray<T, V> = Promisable<T[], V>;
A Promisable that resolves to an array.
Type Parameters
T
T
V
V = never
### <a id="PromiseExFunc"></a>PromiseExFunc
@xylabs/sdk-js
type PromiseExFunc<T> = (resolve?, reject?) => void;
The executor function passed to the PromiseEx constructor.
Type Parameters
T
T
Parameters
resolve?
PromiseExSubFunc<T, void>
reject?
PromiseExSubFunc<T, void>
Returns
void
### <a id="PromiseExSubFunc"></a>PromiseExSubFunc
@xylabs/sdk-js
type PromiseExSubFunc<T, TResult> = (value) => TResult;
A resolve/reject callback used within PromiseEx.
Type Parameters
T
T
TResult
TResult = T
Parameters
value
T
Returns
TResult
### <a id="PromiseExValueFunc"></a>PromiseExValueFunc
@xylabs/sdk-js
type PromiseExValueFunc<V> = (value?) => boolean;
A callback that inspects the attached value and returns whether to cancel the promise.
Type Parameters
V
V
Parameters
value?
V
Returns
boolean
### <a id="RecordKey"></a>RecordKey
@xylabs/sdk-js
type RecordKey = string | number | symbol;
A union of valid object key types.
### <a id="Simplify"></a>Simplify
@xylabs/sdk-js
type Simplify<T> = { [K in keyof T]: T[K] } & object;
Flattens an intersection or complex mapped type into a single object type for better readability.
Type Parameters
T
T
### <a id="StandardCreatableStatus"></a>StandardCreatableStatus
@xylabs/sdk-js
type StandardCreatableStatus =
| "creating"
| "created"
| "starting"
| "started"
| "stopping"
| "stopped"
| "error";
The standard lifecycle statuses a creatable can transition through.
### <a id="StringKeyObject"></a>StringKeyObject
@xylabs/sdk-js
type StringKeyObject<T> = Record<string, T>;
An object type with string keys and values of type T.
Type Parameters
T
T = unknown
### <a id="StringOrAlertFunction"></a>StringOrAlertFunction
@xylabs/sdk-js
type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>;
A string message or function that produces an assertion error message for a failed type check.
Type Parameters
T
T extends AnyNonPromise
### <a id="TypeOfTypes"></a>TypeOfTypes
@xylabs/sdk-js
type TypeOfTypes =
| "string"
| "number"
| "object"
| "array"
| "buffer"
| "null"
| "undefined"
| "bigint"
| "boolean"
| "function"
| "symbol";
Union of string literals representing the possible results of the extended typeOf function.
### <a id="TypedArray"></a>TypedArray
@xylabs/sdk-js
type TypedArray = TypedValue[];
An array of TypedValue elements.
### <a id="TypedKey"></a>TypedKey
@xylabs/sdk-js
type TypedKey<T> = T extends string ? T : string | number | symbol;
A valid key for a typed object. Defaults to string | number | symbol unless narrowed by T.
Type Parameters
T
T extends string | void = void
### <a id="TypedObject"></a>TypedObject
@xylabs/sdk-js
type TypedObject =
| {
[key: string | number | symbol]: TypedValue;
}
| object;
An object whose keys are TypedKey and whose values are TypedValue.
### <a id="TypedValue"></a>TypedValue
@xylabs/sdk-js
type TypedValue =
| bigint
| string
| number
| boolean
| null
| TypedObject
| TypedArray
| Function
| symbol
| undefined;
A value that can appear in a typed object tree (primitives, objects, arrays, functions, and symbols).
### <a id="WithAdditional"></a>WithAdditional
@xylabs/sdk-js
type WithAdditional<T, TAdditional> = TAdditional extends EmptyObject ? T & TAdditional : T;
Intersects T with TAdditional if TAdditional is an object, otherwise returns T unchanged.
Type Parameters
T
T extends EmptyObject | void
TAdditional
TAdditional extends EmptyObject | void = void
### <a id="ZodFactoryConfig"></a>ZodFactoryConfig
@xylabs/sdk-js
type ZodFactoryConfig =
| AssertConfig
| ZodFactoryConfigObject;
Configuration for zod factory assertion behavior, either an AssertConfig or a named config object.
### variables
### <a id="ADDRESS_LENGTH"></a>ADDRESS_LENGTH
@xylabs/sdk-js
const ADDRESS_LENGTH: 40;
The character length of an address hex string (40 hex characters / 20 bytes).
### <a id="AddressRegEx"></a>AddressRegEx
@xylabs/sdk-js
const AddressRegEx: RegExp;
Regular expression matching a 20-byte (40 hex character) address string.
### <a id="AddressTransformZod"></a>AddressTransformZod
@xylabs/sdk-js
const AddressTransformZod: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodBigInt, z.ZodNumber]>, z.ZodTransform<string, string | number | bigint>>, z.ZodTransform<Lowercase<string> & object & object, string>>;
Zod schema that accepts a string, bigint, or number and transforms it into a validated Address.
### <a id="AddressValidationZod"></a>AddressValidationZod
@xylabs/sdk-js
const AddressValidationZod: z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & object & object, string>>;
Zod schema that validates a string is a properly formatted 40-character hex address.
### <a id="AddressZod"></a>AddressZod
@xylabs/sdk-js
const AddressZod: z.ZodPipe<z.ZodString, z.ZodTransform<BrandedAddress, string>>;
Zod schema that validates and transforms a string into a branded Address type.
### <a id="ApiStage"></a>ApiStage
@xylabs/sdk-js
const ApiStage: Enum<{
Beta: "beta";
Local: "local";
Prod: "prod";
}>;
Deployment stage identifiers for API environments.
### <a id="AsObjectFactory"></a>AsObjectFactory
@xylabs/sdk-js
const AsObjectFactory: object;
Factory for creating type-narrowing functions for TypedObject types.
Type Declaration
create
create: <T>(typeCheck) => AsTypeFunction;
Type Parameters
T
T extends TypedObject
Parameters
typeCheck
TypeCheck<T>
Returns
AsTypeFunction
createOptional
createOptional: <T>(typeCheck) => (value) => T | undefined;
Type Parameters
T
T extends TypedObject
Parameters
typeCheck
TypeCheck<T>
Returns
(value) => T | undefined
### <a id="AsTypeFactory"></a>AsTypeFactory
@xylabs/sdk-js
const AsTypeFactory: object;
Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined.
Supports optional assertion messages and configuration for required/optional behavior.
Type Declaration
create
create: <T>(typeCheck) => AsTypeFunction<T>;
Type Parameters
T
T extends AnyNonPromise
Parameters
typeCheck
TypeCheck<T>
Returns
AsTypeFunction<T>
createOptional
createOptional: <T>(typeCheck) => (value) => T | undefined;
Type Parameters
T
T extends AnyNonPromise
Parameters
typeCheck
TypeCheck<T>
Returns
(value) => T | undefined
### <a id="BigIntToJsonZod"></a>BigIntToJsonZod
@xylabs/sdk-js
const BigIntToJsonZod: z.ZodPipe<z.ZodBigInt, z.ZodTransform<BrandedHex, bigint>>;
Zod schema that transforms a non-negative BigInt into a hex string for JSON serialization.
### <a id="Buffer"></a>Buffer
@xylabs/sdk-js
const Buffer: BufferConstructor;
### <a id="ETH_ZERO_ADDRESS"></a>ETH_ZERO_ADDRESS
@xylabs/sdk-js
const ETH_ZERO_ADDRESS: EthAddress;
The zero Ethereum address constant (0x followed by 40 zero characters).
### <a id="Enum"></a>Enum
@xylabs/sdk-js
const Enum: <T>(obj) => Enum<T>;
Transforms a given record object into a readonly "enum-like" structure while preserving
the literal types of its values. This allows you to use the returned object both at runtime
(for lookups) and at compile time (for strongly typed values).
To maintain literal types (i.e., prevent them from being widened to string, number, etc.),
ensure you annotate your object with as const before passing it to Enum.
Type Parameters
T
T extends Record<string | number | symbol, unknown>
A record type with string keys and any kind of values.
Parameters
obj
Readonly<T>
A readonly record object annotated with as const.
Returns
Enum<T>
A readonly version of the provided record, preserving exact literal value types.
Example
const DnsRecordType = Enum({
A: 1,
AAAA: 28,
CAA: 257,
CNAME: 5,
DNAME: 39,
MX: 15,
NS: 2,
PTR: 12,
SOA: 6,
SPF: 99,
SRV: 33,
TXT: 16,
} as const);
### <a id="EthAddressFromStringSchema"></a>EthAddressFromStringSchema
@xylabs/sdk-js
const EthAddressFromStringSchema: z.ZodPipe<z.ZodString, z.ZodTransform<EthAddress, string>>;
Deprecated
use EthAddressFromStringZod
### <a id="EthAddressFromStringZod"></a>EthAddressFromStringZod
@xylabs/sdk-js
const EthAddressFromStringZod: z.ZodPipe<z.ZodString, z.ZodTransform<EthAddress, string>>;
Zod schema that validates and transforms a string into an EthAddress type.
### <a id="EthAddressRegEx"></a>EthAddressRegEx
@xylabs/sdk-js
const EthAddressRegEx: RegExp;
Regular expression matching a 20-byte Ethereum address with 0x prefix (mixed case).
### <a id="EthAddressToStringSchema"></a>EthAddressToStringSchema
@xylabs/sdk-js
const EthAddressToStringSchema: z.ZodString;
Deprecated
use EthAddressToStringZod
### <a id="EthAddressToStringZod"></a>EthAddressToStringZod
@xylabs/sdk-js
const EthAddressToStringZod: z.ZodString;
Zod schema that validates a string is a properly formatted Ethereum address.
### <a id="EthAddressZod"></a>EthAddressZod
@xylabs/sdk-js
const EthAddressZod: z.ZodString & z.ZodType<EthAddress, string, z.core.$ZodTypeInternals<EthAddress, string>>;
Zod schema that validates a string as a properly formatted Ethereum address using regex and type guard.
### <a id="HASH_LENGTH"></a>HASH_LENGTH
@xylabs/sdk-js
const HASH_LENGTH: 32;
The byte length of a standard hash (32 bytes / 256 bits).
### <a id="HashBitLength"></a>HashBitLength
@xylabs/sdk-js
HashBitLength: HashBitLength[];
Array of all valid hash bit lengths for runtime validation.
### <a id="HashRegEx"></a>HashRegEx
@xylabs/sdk-js
const HashRegEx: RegExp;
Regular expression matching a 32-byte (64 hex character) hash string.
### <a id="HashToJsonZod"></a>HashToJsonZod
@xylabs/sdk-js
const HashToJsonZod: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<BrandedHash, string>>, z.ZodTransform<string, BrandedHash>>;
Zod schema that transforms a Hash to a plain string for JSON serialization.
### <a id="HashZod"></a>HashZod
@xylabs/sdk-js
const HashZod: z.ZodPipe<z.ZodString, z.ZodTransform<BrandedHash, string>>;
Zod schema that validates and transforms a string into a branded Hash type.
### <a id="HexRegEx"></a>HexRegEx
@xylabs/sdk-js
const HexRegEx: RegExp;
Regular expression matching a lowercase hex string without prefix.
### <a id="HexRegExMinMax"></a>HexRegExMinMax
@xylabs/sdk-js
const HexRegExMinMax: (minBytes?, maxBytes?) => RegExp;
Creates a RegExp matching lowercase hex strings with a byte length in the given range.
Parameters
minBytes?
number
Minimum number of bytes (default 0)
maxBytes?
number
Maximum number of bytes
Returns
RegExp
A RegExp for validating hex strings within the byte range
### <a id="HexRegExMinMaxMixedCaseWithPrefix"></a>HexRegExMinMaxMixedCaseWithPrefix
@xylabs/sdk-js
const HexRegExMinMaxMixedCaseWithPrefix: (minBytes?, maxBytes?) => RegExp;
Creates a RegExp matching mixed-case hex strings with a 0x prefix and a byte length in the given range.
Parameters
minBytes?
number
Minimum number of bytes (default 0)
maxBytes?
number
Maximum number of bytes
Returns
RegExp
A RegExp for validating prefixed hex strings within the byte range
### <a id="HexRegExWithPrefix"></a>HexRegExWithPrefix
@xylabs/sdk-js
const HexRegExWithPrefix: RegExp;
Regular expression matching a lowercase hex string with a 0x prefix.
### <a id="HexZod"></a>HexZod
@xylabs/sdk-js
const HexZod: z.ZodPipe<z.ZodString, z.ZodTransform<BrandedHex, string>>;
Zod schema that validates and transforms a string into a branded Hex type.
### <a id="JsonObjectZod"></a>JsonObjectZod
@xylabs/sdk-js
const JsonObjectZod: z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
Zod schema for a JSON object with string keys and recursive JSON values.
### <a id="JsonToBigIntZod"></a>JsonToBigIntZod
@xylabs/sdk-js
const JsonToBigIntZod: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<BrandedHex, string>>, z.ZodTransform<bigint, BrandedHex>>;
Zod schema that parses a JSON hex string into a BigInt.
### <a id="JsonToHashZod"></a>JsonToHashZod
@xylabs/sdk-js
const JsonToHashZod: z.ZodPipe<z.ZodString, z.ZodTransform<BrandedHash, string>>;
Zod schema that parses a JSON string into a validated Hash, throwing on invalid input.
### <a id="LogLevel"></a>LogLevel
@xylabs/sdk-js
const LogLevel: Enum<{
error: 1;
warn: 2;
info: 3;
log: 4;
debug: 5;
trace: 6;
}>;
Numeric log level values, from least verbose (error=1) to most verbose (trace=6).
### <a id="NoOpLogFunction"></a>NoOpLogFunction
@xylabs/sdk-js
const NoOpLogFunction: (..._data) => undefined;
A log function that silently discards all arguments.
Parameters
_data
...unknown[]
Returns
undefined
### <a id="URL"></a>URL
@xylabs/sdk-js
const URL: {
(url, base?): URL;
prototype: URL;
canParse: boolean;
createObjectURL: string;
parse: URL | null;
revokeObjectURL: void;
};
Node.js-specific URL class, imported from the node:url module.
Type Declaration
Parameters
url
string | URL
base?
string | URL
Returns
URL
prototype
prototype: URL;
canParse()
canParse(input, base?): boolean;
Parameters
input
string | URL
base?
string | URL
Returns
boolean
createObjectURL()
createObjectURL(blob): string;
Parameters
blob
Blob
Returns
string
parse()
parse(input, base?): URL | null;
Parameters
input
string | URL
base?
string | URL
Returns
URL | null
revokeObjectURL()
revokeObjectURL(id): void;
Parameters
id
string
Returns
void
### <a id="ZERO_ADDRESS"></a>ZERO_ADDRESS
@xylabs/sdk-js
const ZERO_ADDRESS: Address;
A 160-bit zero address constant.
### <a id="ZERO_HASH"></a>ZERO_HASH
@xylabs/sdk-js
const ZERO_HASH: Hash;
A 256-bit zero hash constant.
### <a id="asAnyObject"></a>asAnyObject
@xylabs/sdk-js
const asAnyObject: AsTypeFunction;
Type-narrowing function that casts a value to AnyObject if it is a plain object, or returns undefined.
### <a id="asJsonArray"></a>asJsonArray
@xylabs/sdk-js
const asJsonArray: {
<T> (value): T & unknown[] | undefined;
<T> (value, assert): T & unknown[];
};
Casts a value to JsonArray or returns undefined if it does not conform.
Call Signature
<T>(value): T & unknown[] | undefined;
Type Parameters
T
T
Parameters
value
T
Returns
T & unknown[] | undefined
Call Signature
<T>(value, assert): T & unknown[];
Type Parameters
T
T
Parameters
value
T
assert
ZodFactoryConfig
Returns
T & unknown[]
### <a id="asJsonObject"></a>asJsonObject
@xylabs/sdk-js
const asJsonObject: {
<T> (value): T & Record<string, unknown> | undefined;
<T> (value, assert): T & Record<string, unknown>;
};
Casts a value to JsonObject or returns undefined if it does not conform.
Call Signature
<T>(value): T & Record<string, unknown> | undefined;
Type Parameters
T
T
Parameters
value
T
Returns
T & Record<string, unknown> | undefined
Call Signature
<T>(value, assert): T & Record<string, unknown>;
Type Parameters
T
T
Parameters
value
T
assert
ZodFactoryConfig
Returns
T & Record<string, unknown>
### <a id="asJsonValue"></a>asJsonValue
@xylabs/sdk-js
const asJsonValue: {
<T> (value): T | undefined;
<T> (value, assert): T;
};
Casts a value to JsonValue or returns undefined if it does not conform.
Call Signature
<T>(value): T | undefined;
Type Parameters
T
T
Parameters
value
T
Returns
T | undefined
Call Signature
<T>(value, assert): T;
Type Parameters
T
T
Parameters
value
T
assert
ZodFactoryConfig
Returns
T
### <a id="assertError"></a>assertError
@xylabs/sdk-js
const assertError: (value, assert, defaultMessage) => undefined;
Throws an Error based on the assert configuration when a value fails validation.
Parameters
value
unknown
The value being validated
assert
AssertConfig | undefined
Assertion config controlling the error message
defaultMessage
string
Fallback message if no custom message is provided
Returns
undefined
### <a id="axios"></a>axios
@xylabs/sdk-js
const axios: Axios;
Deprecated
use axiosJson instead
### <a id="axiosJson"></a>axiosJson
@xylabs/sdk-js
const axiosJson: Axios;
### <a id="bitsToNibbles"></a>bitsToNibbles
@xylabs/sdk-js
const bitsToNibbles: (value) => number;
Converts a bit count to the equivalent number of hex nibbles (4 bits each).
Parameters
value
number
The number of bits (must be a multiple of 4)
Returns
number
The number of nibbles
### <a id="bufferPolyfill"></a>bufferPolyfill
@xylabs/sdk-js
const bufferPolyfill: () => void;
Returns
void
### <a id="clearTimeoutEx"></a>clearTimeoutEx
@xylabs/sdk-js
const clearTimeoutEx: (id) => void;
Cancels a timeout previously created with setTimeoutEx.
Parameters
id
string
The timeout ID returned by setTimeoutEx.
Returns
void
### <a id="containsAll"></a>containsAll
@xylabs/sdk-js
const containsAll: <T>(source, target) => boolean;
Checks whether the source array contains every element in the target array.
Type Parameters
T
T
Parameters
source
T[]
The array to search within
target
T[]
The elements that must all be present
Returns
boolean
True if every target element exists in source
### <a id="createProfiler"></a>createProfiler
@xylabs/sdk-js
const createProfiler: () => Profiler;
Creates a new empty profiler instance.
Returns
Profiler
### <a id="deepMerge"></a>deepMerge
@xylabs/sdk-js
const deepMerge: <T>(...objects) => MergeAll<T>;
Deeply merges multiple objects into a new object.
Type Parameters
T
T extends AnyObject[]
Parameters
objects
...T
Multiple objects to merge deeply.
The function merges properties from all objects into a new object.
If a property exists in multiple objects, the last object's value will be used.
If a property is an object, it will be merged recursively.
If a property is an array, it will be overwritten by the last object's value.
If a property is a primitive value, it will be overwritten by the last object's value.
If a property is undefined in the source, it will be skipped.
If a property is a symbol, it will be merged as well.
Returns
MergeAll<T>
A new object with the merged properties.
### <a id="defaultForgetNodeConfig"></a>defaultForgetNodeConfig
@xylabs/sdk-js
const defaultForgetNodeConfig: ForgetNodeConfig<unknown>;
Default Node.js forget configuration with termination disabled.
### <a id="delay"></a>delay
@xylabs/sdk-js
const delay: (ms) => Promise<unknown>;
Returns a promise that resolves after the specified number of milliseconds.
Parameters
ms
number
The number of milliseconds to delay.
Returns
Promise<unknown>
A promise that resolves after the delay.
### <a id="difference"></a>difference
@xylabs/sdk-js
const difference: <TKey>(a, b) => Set<TKey>;
Returns a new set containing elements in a that are not in b.
Type Parameters
TKey
TKey
Parameters
a
Set<TKey>
The source set
b
Set<TKey>
The set of elements to exclude
Returns
Set<TKey>
A new set representing the difference of a and b
### <a id="disableGloballyUnique"></a>disableGloballyUnique
@xylabs/sdk-js
const disableGloballyUnique: () => void;
Disables global uniqueness checks, allowing duplicate registrations without throwing.
Returns
void
### <a id="distinct"></a>distinct
@xylabs/sdk-js
const distinct: <T>(value, index, array) => boolean;
Array filter callback that removes duplicate values, with correct NaN handling.
Use with array.filter(distinct).
Type Parameters
T
T
Parameters
value
T
index
number
array
T[]
Returns
boolean
### <a id="ellipsize"></a>ellipsize
@xylabs/sdk-js
const ellipsize: (value, length?) => string;
Truncates a string to show the first and last length characters separated by an ellipsis.
Parameters
value
string
The string to ellipsize
length?
number
Number of characters to keep at each end (default 2)
Returns
string
The ellipsized string
### <a id="equalArrayBuffers"></a>equalArrayBuffers
@xylabs/sdk-js
const equalArrayBuffers: (a1, a2) => boolean;
Compares two ArrayBuffers for byte-level equality.
Parameters
a1
ArrayBufferLike
First buffer
a2
ArrayBufferLike
Second buffer
Returns
boolean
True if the buffers have the same length and identical bytes
### <a id="exists"></a>exists
@xylabs/sdk-js
const exists: <T>(x?) => x is NonNullable<T>;
Used to type narrow an object which is possibly null or undefined. Works well
with functional Array methods. For example:
Type Parameters
T
T
Parameters
x?
T | null
The object which is potentially undefined or null
Returns
x is NonNullable<T>
False if the object is null/undefined, true otherwise
Example
const payloads: XyoPayload[] = boundWitness._payloads?.filter(exists) || []
### <a id="filterAs"></a>filterAs
@xylabs/sdk-js
const filterAs: <In, Out>(x, predicate) => NonNullable<Out>[];
Maps each element using the predicate and filters out nullish results.
Type Parameters
In
In
Out
Out
Parameters
x
In[]
The input array
predicate
(a) => Out
Transform function applied to each element
Returns
NonNullable<Out>[]
Array of non-nullish transformed values
### <a id="filterAsync"></a>filterAsync
@xylabs/sdk-js
const filterAsync: <T>(array, predicate) => Promise<T[]>;
Returns the elements of an array that meet the condition specified in a callback function.
Type Parameters
T
T
Parameters
array
T[]
The array to filter.
predicate
(value, index, array) => Promise<boolean>
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
Returns
Promise<T[]>
The elements of an array that meet the condition specified in a callback function.
### <a id="findAs"></a>findAs
@xylabs/sdk-js
const findAs: <In, Out>(x, predicate) => NonNullable<Out> | undefined;
Maps each element using the predicate and returns the first non-nullish result.
Type Parameters
In
In
Out
Out
Parameters
x
In[]
The input array
predicate
(a) => Out
Transform function applied to each element
Returns
NonNullable<Out> | undefined
The first non-nullish transformed value, or undefined
### <a id="findLastAs"></a>findLastAs
@xylabs/sdk-js
const findLastAs: <In, Out>(x, predicate) => NonNullable<Out> | undefined;
Maps each element using the predicate and returns the last non-nullish result.
Type Parameters
In
In
Out
Out
Parameters
x
In[]
The input array
predicate
(a) => Out
Transform function applied to each element
Returns
NonNullable<Out> | undefined
The last non-nullish transformed value, or undefined
### <a id="flatten"></a>flatten
@xylabs/sdk-js
const flatten: <T>(a?, b?) => T[];
Concatenates two values or arrays into a single flat array, filtering out nullish entries.
Type Parameters
T
T
Parameters
a?
T | ConcatArray<T>
First value or array
b?
T | ConcatArray<T>
Second value or array
Returns
T[]
A flat array of non-nullish elements
### <a id="forget"></a>forget
@xylabs/sdk-js
const forget: <T>(promise, config?) => void;
Node.js variant of forget that can optionally terminate the process on exceptions or timeouts.
Type Parameters
T
T
Parameters
promise
Promisable<T>
The promise or promisable value to forget.
config?
ForgetNodeConfig<T>
Optional Node.js-specific configuration including process termination options.
Returns
void
### <a id="fromFixedPoint"></a>fromFixedPoint
@xylabs/sdk-js
const fromFixedPoint: (value, places?) => bigint;
Converts a fixed-point bigint back to a whole-number bigint by dividing out the decimal places.
Parameters
value
bigint
The fixed-point bigint value to convert
places?
number
Number of decimal places (default 18)
Returns
bigint
The whole-number bigint result
### <a id="fulfilled"></a>fulfilled
@xylabs/sdk-js
const fulfilled: <T>(val) => val is PromiseFulfilledResult<T>;
For use with Promise.allSettled to filter only successful results
Type Parameters
T
T
Parameters
val
PromiseSettledResult<T>
Returns
val is PromiseFulfilledResult<T>
### <a id="fulfilledValues"></a>fulfilledValues
@xylabs/sdk-js
const fulfilledValues: <T>(previousValue, currentValue) => T[];
For use with Promise.allSettled to reduce to only successful result values
Type Parameters
T
T
Parameters
previousValue
T[]
currentValue
PromiseSettledResult<T>
Returns
T[]
Examples
const resolved = Promise.resolve('resolved')
const rejected = Promise.reject('rejected')
const settled = await Promise.allSettled([resolved, rejected])
const results = settled.reduce(fulfilledValues, [] as string[])
const resolved = Promise.resolve('resolved')
const rejected = Promise.reject('rejected')
const settled = await Promise.allSettled([resolved, rejected])
const results = settled.reduce<string[]>(fulfilledValues, [])
### <a id="functionName"></a>functionName
@xylabs/sdk-js
const functionName: (depth?) => string;
Returns the name of the calling function by inspecting the stack trace.
Parameters
depth?
number
The stack frame depth to read the function name from (default: 2).
Returns
string
The function name, or '' if it cannot be determined.
### <a id="getApiStage"></a>getApiStage
@xylabs/sdk-js
const getApiStage: (hostname) => "beta" | "local" | "prod";
Determines the API stage based on the hostname.
Parameters
hostname
string
The hostname to evaluate
Returns
"beta" | "local" | "prod"
The corresponding ApiStage (Local, Beta, or Prod)
### <a id="getFunctionName"></a>getFunctionName
@xylabs/sdk-js
const getFunctionName: (depth?) => string;
Retrieves the name of the calling function by inspecting the stack trace.
Parameters
depth?
number
The stack frame depth to inspect (default: 2, the caller's caller).
Returns
string
The function name, or '' if it cannot be determined.
### <a id="globallyUnique"></a>globallyUnique
@xylabs/sdk-js
const globallyUnique: (name, value, domain?) => string;
Registers a value as globally unique under the given name and domain.
Throws if a different value is already registered under the same key.
Parameters
name
string | symbol
The unique name or symbol
value
unknown
The value to register
domain?
string
The namespace domain (default 'global')
Returns
string
The fully qualified unique name
### <a id="handleError"></a>handleError
@xylabs/sdk-js
const handleError: <T>(error, handler) => T;
Invokes the handler if the value is an Error, otherwise re-throws it.
Type Parameters
T
T
Parameters
error
any
The caught value to inspect
handler
(error) => T
Callback invoked with the Error if it is one
Returns
T
The handler's return value
### <a id="handleErrorAsync"></a>handleErrorAsync
@xylabs/sdk-js
const handleErrorAsync: <T>(error, handler) => Promise<T>;
Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.
Type Parameters
T
T
Parameters
error
any
The caught value to inspect
handler
(error) => Promise<T>
Async callback invoked with the Error if it is one
Returns
Promise<T>
The handler's resolved return value
### <a id="hasAllLabels"></a>hasAllLabels
@xylabs/sdk-js
const 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
### <a id="hexFrom"></a>hexFrom
@xylabs/sdk-js
const hexFrom: (value, config?) => Hex;
Takes unknown value and tries our best to convert it to a hex string
Parameters
value
string | number | bigint | ArrayBufferLike
config?
HexConfig
Returns
Hex
### <a id="hexFromArrayBuffer"></a>hexFromArrayBuffer
@xylabs/sdk-js
const hexFromArrayBuffer: (buffer, config?) => Hex;
Convert an ArrayBuffer to a hex string
Parameters
buffer
ArrayBufferLike
config?
HexConfig
Returns
Hex
### <a id="hexFromBigInt"></a>hexFromBigInt
@xylabs/sdk-js
const hexFromBigInt: (value, config?) => Hex;
Convert a bigint to a hex string
Parameters
value
bigint
config?
HexConfig
Returns
Hex
### <a id="hexFromHexString"></a>hexFromHexString
@xylabs/sdk-js
const hexFromHexString: (value, config?) => Hex;
Normalizes a hex string by stripping an optional 0x prefix, lowercasing, and padding to byte/bit boundaries.
Parameters
value
string
The hex string to normalize (with or without 0x prefix)
config?
HexConfig
Configuration for prefix, byteSize, and bitLength padding
Returns
Hex
The normalized Hex string
### <a id="hexFromNumber"></a>hexFromNumber
@xylabs/sdk-js
const hexFromNumber: (value, config?) => Hex;
Converts a number to a hex string by converting to BigInt first.
Parameters
value
number
The number to convert
config?
HexConfig
Optional hex output configuration
Returns
Hex
The hex string representation
### <a id="ifDefined"></a>ifDefined
@xylabs/sdk-js
const ifDefined: <T>(value, func) => T | undefined;
Invokes the callback only if the value is neither null nor undefined.
Type Parameters
T
T
Parameters
value
T
The value to check.
func
(value) => void
The callback to invoke with the value if it is defined.
Returns
T | undefined
The value if defined, or undefined otherwise.
### <a id="ifTypeOf"></a>ifTypeOf
@xylabs/sdk-js
const ifTypeOf: <T, R>(typeName, value, trueFunc, isFunc?) => R | undefined;
Invokes the callback if the value matches the specified type, with an optional additional predicate.
Type Parameters
T
T
R
R
Parameters
typeName
TypeOfTypes
The expected type name to match against.
value
unknown
The value to check.
trueFunc
(value) => R
The callback to invoke if the type matches.
isFunc?
(value) => boolean
Optional additional predicate that must also return true.
Returns
R | undefined
The result of trueFunc if the type matches (and isFunc passes), or undefined.
### <a id="intersection"></a>intersection
@xylabs/sdk-js
const intersection: <TKey>(a, b) => Set<TKey>;
Returns a new set containing only elements present in both a and b.
Type Parameters
TKey
TKey
Parameters
a
Set<TKey>
The first set
b
Set<TKey>
The second set
Returns
Set<TKey>
A new set representing the intersection of a and b
### <a id="isAddress"></a>isAddress
@xylabs/sdk-js
const isAddress: (value?, config?) => value is Address;
Type guard that checks whether a value is a valid 160-bit address.
Parameters
value?
unknown
The value to check
config?
HexConfig
Optional hex config (defaults to 160-bit, no prefix)
Returns
value is Address
True if the value is a valid Address
### <a id="isBrowser"></a>isBrowser
@xylabs/sdk-js
const isBrowser: () => boolean;
Returns whether the current environment is a browser. Always returns false in Node.js.
Returns
boolean
### <a id="isEthAddress"></a>isEthAddress
@xylabs/sdk-js
const isEthAddress: (value?, config?) => value is EthAddress;
Type guard that checks whether a value is a valid 0x-prefixed Ethereum address.
Parameters
value?
unknown
The value to check
config?
HexConfig
Optional hex config (defaults to 160-bit with prefix)
Returns
value is EthAddress
True if the value is a valid EthAddress
### <a id="isEthAddressWrapper"></a>isEthAddressWrapper
@xylabs/sdk-js
const isEthAddressWrapper: (obj) => obj is { type: string } & EthAddressWrapper;
Type guard that checks if the given object is an instance of EthAddressWrapper.
Parameters
obj
type
string
Returns
obj is { type: string } & EthAddressWrapper
### <a id="isHash"></a>isHash
@xylabs/sdk-js
const isHash: (value, bitLength?) => value is Hash;
Type guard that checks whether a value is a valid hash of the specified bit length.
Parameters
value
unknown
The value to check
bitLength?
HashBitLength
The expected bit length of the hash (defaults to 256)
Returns
value is Hash
True if the value is a valid Hash
### <a id="isHashBitLength"></a>isHashBitLength
@xylabs/sdk-js
const isHashBitLength: (value) => value is HashBitLength;
Type guard that checks whether a value is a valid hash bit length.
Parameters
value
unknown
The value to check
Returns
value is HashBitLength
True if the value is one of the supported HashBitLength values
### <a id="isHex"></a>isHex
@xylabs/sdk-js
const isHex: (value, config?) => value is Hex;
Type guard that checks whether a value is a valid hex string.
Parameters
value
unknown
The value to check
config?
HexConfig
Optional configuration for prefix and bit length validation
Returns
value is Hex
True if the value is a valid Hex string
### <a id="isHexZero"></a>isHexZero
@xylabs/sdk-js
const isHexZero: (value?) => boolean | undefined;
Checks whether a hex string represents a zero value.
Parameters
value?
string
The hex string to check
Returns
boolean | undefined
True if zero, false if non-zero, or undefined if the input is not a string
### <a id="isJsonArray"></a>isJsonArray
@xylabs/sdk-js
const isJsonArray: <T>(value) => value is T & unknown[];
Type guard that checks if a value is a valid JSON array.
Type Parameters
T
T
Parameters
value
T
Returns
value is T & unknown[]
### <a id="isJsonObject"></a>isJsonObject
@xylabs/sdk-js
const isJsonObject: <T>(value) => value is T & Record<string, unknown>;
Type guard that checks if a value is a valid JSON object.
Type Parameters
T
T
Parameters
value
T
Returns
value is T & Record<string, unknown>
### <a id="isJsonValue"></a>isJsonValue
@xylabs/sdk-js
const isJsonValue: <T>(value) => value is T;
Type guard that checks if a value is a valid JSON value.
Type Parameters
T
T
Parameters
value
T
Returns
value is T
### <a id="isLocalhost"></a>isLocalhost
@xylabs/sdk-js
const isLocalhost: (hostname) => boolean;
Checks whether a hostname refers to the local machine (localhost, 127.0.0.1, ::1, or *.localhost).
Parameters
hostname
string
The hostname to check
Returns
boolean
true if the hostname is a localhost address
### <a id="isNode"></a>isNode
@xylabs/sdk-js
const isNode: () => boolean;
Returns whether the current environment is Node.js. Always returns true in this entry point.
Returns
boolean
### <a id="isType"></a>isType
@xylabs/sdk-js
const isType: (value, expectedType) => boolean;
Checks whether a value matches the expected field type, with correct handling for arrays and nulls.
Parameters
value
unknown
The value to check.
expectedType
FieldType
The expected type string.
Returns
boolean
True if the value matches the expected type.
### <a id="isTypedArray"></a>isTypedArray
@xylabs/sdk-js
const isTypedArray: (value) => value is TypedArray;
Type guard that checks whether a value is a TypedArray (an array where every element is a TypedValue).
Parameters
value
unknown
The value to check.
Returns
value is TypedArray
True if the value is an array of TypedValue elements.
### <a id="isTypedKey"></a>isTypedKey
@xylabs/sdk-js
const isTypedKey: (value) => value is TypedKey;
Type guard that checks whether a value is a valid TypedKey (string, bigint, number, or symbol).
Parameters
value
unknown
The value to check.
Returns
value is TypedKey
True if the value is a valid TypedKey.
### <a id="isTypedObject"></a>isTypedObject
@xylabs/sdk-js
const isTypedObject: (value) => value is TypedObject;
Type guard that checks whether a value is a TypedObject (an object with TypedKey keys and TypedValue values).
Parameters
value
unknown
The value to check.
Returns
value is TypedObject
True if the value is a valid TypedObject.
### <a id="isTypedValue"></a>isTypedValue
@xylabs/sdk-js
const isTypedValue: (value) => value is TypedValue;
Type guard that checks whether a value is a valid TypedValue.
Parameters
value
unknown
The value to check.
Returns
value is TypedValue
True if the value is a string, number, boolean, null, TypedObject, or TypedArray.
### <a id="isValidTypedFieldPair"></a>isValidTypedFieldPair
@xylabs/sdk-js
const isValidTypedFieldPair: (pair) => pair is [key: TypedKey, value: TypedValue];
Type guard that checks whether a key-value pair has a valid TypedKey and TypedValue.
Parameters
pair
[unknown, unknown]
A tuple of [key, value] to validate.
Returns
pair is [key: TypedKey, value: TypedValue]
True if the key is a TypedKey and the value is a TypedValue.
### <a id="isWebworker"></a>isWebworker
@xylabs/sdk-js
const isWebworker: () => boolean;
Returns whether the current environment is a web worker. Always returns false in Node.js.
Returns
boolean
### <a id="nibblesToBits"></a>nibblesToBits
@xylabs/sdk-js
const nibblesToBits: (value) => number;
Converts a nibble count to the equivalent number of bits.
Parameters
value
number
The number of nibbles
Returns
number
The number of bits
### <a id="omitBy"></a>omitBy
@xylabs/sdk-js
const omitBy: <T>(obj, predicate, maxDepth?) => Partial<T>;
Creates a new object excluding properties that satisfy the predicate, with optional recursive depth.
Type Parameters
T
T extends EmptyObject
Parameters
obj
T
The source object to omit properties from.
predicate
OmitByPredicate
A function that returns true for properties to exclude.
maxDepth?
number
Maximum recursion depth for nested objects.
Returns
Partial<T>
A partial copy of the object without matching properties.
### <a id="omitByPrefix"></a>omitByPrefix
@xylabs/sdk-js
const omitByPrefix: <T, P>(payload, prefix, maxDepth?) => DeepOmitStartsWith<T, P>;
Omits all properties whose keys start with the given prefix, recursively through nested objects.
Type Parameters
T
T extends EmptyObject
P
P extends string
Parameters
payload
T
The source object.
prefix
P
The string prefix to match keys against.
maxDepth?
number
Maximum recursion depth.
Returns
DeepOmitStartsWith<T, P>
A new object without properties that have matching prefixed keys.
### <a id="padHex"></a>padHex
@xylabs/sdk-js
const padHex: (hex, byteCount?) => string;
Parameters
hex
string
byteCount?
number
Returns
string
### <a id="pickBy"></a>pickBy
@xylabs/sdk-js
const pickBy: <T>(obj, predicate, maxDepth?) => Partial<T>;
Creates a new object containing only the properties that satisfy the predicate, with optional recursive depth.
Type Parameters
T
T extends EmptyObject
Parameters
obj
T
The source object to pick properties from.
predicate
PickByPredicate
A function that returns true for properties to include.
maxDepth?
number
Maximum recursion depth for nested objects.
Returns
Partial<T>
A partial copy of the object with only matching properties.
### <a id="pickByPrefix"></a>pickByPrefix
@xylabs/sdk-js
const pickByPrefix: <T, P>(payload, prefix, maxDepth?) => DeepPickStartsWith<T, P>;
Picks all properties whose keys start with the given prefix, recursively through nested objects.
Type Parameters
T
T extends EmptyObject
P
P extends string
Parameters
payload
T
The source object.
prefix
P
The string prefix to match keys against.
maxDepth?
number
Maximum recursion depth.
Returns
DeepPickStartsWith<T, P>
A new object containing only properties with matching prefixed keys.
### <a id="profile"></a>profile
@xylabs/sdk-js
const profile: (profiler, name) => void;
Records a timestamp for the given profile name.
Parameters
profiler
Profiler
The profiler instance to record into.
name
string
The name of the timing entry.
Returns
void
### <a id="profileReport"></a>profileReport
@xylabs/sdk-js
const profileReport: (profiler) => Record<string, number>;
Generates a report of elapsed times for each profiled entry.
Parameters
profiler
Profiler
The profiler instance to report on.
Returns
Record<string, number>
A record mapping each profile name to its elapsed time in milliseconds, plus a '-all-' total.
### <a id="rejected"></a>rejected
@xylabs/sdk-js
const rejected: <T>(val) => val is PromiseRejectedResult;
For use with Promise.allSettled to filter only rejected results
Type Parameters
T
T
Parameters
val
PromiseSettledResult<T>
Returns
val is PromiseRejectedResult
### <a id="removeFields"></a>removeFields
@xylabs/sdk-js
const removeFields: <T, K>(obj, fields) => Omit<T, K>;
Returns a shallow copy of the object with the specified fields removed.
Type Parameters
T
T extends EmptyObject
K
K extends keyof T
Parameters
obj
T
The source object.
fields
K[]
An array of keys to remove.
Returns
Omit<T, K>
A new object without the specified fields.
### <a id="retry"></a>retry
@xylabs/sdk-js
const retry: <T>(func, config?) => Promise<T | undefined>;
Retries an async function with exponential backoff until it completes or retries are exhausted.
Type Parameters
T
T = unknown
Parameters
func
() => Promisable<T | undefined>
The function to retry.
config?
RetryConfigWithComplete<T>
Optional retry configuration including backoff, interval, retries, and completion check.
Returns
Promise<T | undefined>
The result of the function, or undefined if all retries were exhausted.
### <a id="setTimeoutEx"></a>setTimeoutEx
@xylabs/sdk-js
const setTimeoutEx: (func, delay) => string;
Sets a timeout using an optimized internal timer that coalesces multiple timeouts into a single native timer.
Parameters
func
Function
The function to call after the delay.
delay
number
The delay in milliseconds (must be >= 0).
Returns
string
A unique string ID that can be used with clearTimeoutEx to cancel the timeout.
### <a id="toAddress"></a>toAddress
@xylabs/sdk-js
const toAddress: (value, config?) => Address;
Converts a value to a 160-bit Address hex string.
Parameters
value
string | number | bigint | ArrayBufferLike
The value to convert (string, number, bigint, or ArrayBuffer)
config?
HexConfig
Optional hex config (defaults to 160-bit, no prefix)
Returns
Address
The value as an Address
### <a id="toDecimalPrecision"></a>toDecimalPrecision
@xylabs/sdk-js
const toDecimalPrecision: (value, digits) => string;
Formats a number to the specified number of significant digits, returning a string with minimal trailing zeros.
Parameters
value
number
The number to format
digits
number
The number of significant digits
Returns
string
A string representation of the number with the specified precision
### <a id="toEthAddress"></a>toEthAddress
@xylabs/sdk-js
const toEthAddress: (value, config?) => EthAddress;
Converts a value to a 0x-prefixed Ethereum address string.
Parameters
value
string | number | bigint | ArrayBufferLike
The value to convert (string, number, bigint, or ArrayBuffer)
config?
HexConfig
Optional hex config (defaults to 160-bit, no inner prefix)
Returns
EthAddress
The value as an EthAddress
### <a id="toFixedPoint"></a>toFixedPoint
@xylabs/sdk-js
const toFixedPoint: (value, places?) => bigint;
Converts a bigint or decimal string to a fixed-point bigint representation.
Parameters
value
bigint | string
The value to convert (bigint or string with optional decimal point)
places?
number
Number of decimal places (default 18)
Returns
bigint
A bigint representing the value scaled by 10^places
### <a id="toHex"></a>toHex
@xylabs/sdk-js
const toHex: (value, config?) => BrandedHex;
takes any value and tries our best to convert it to a hex string
Parameters
value
string | number | bigint | ArrayBufferLike
config?
HexConfig
Returns
BrandedHex
### <a id="toHexLegacy"></a>toHexLegacy
@xylabs/sdk-js
const toHexLegacy: (buffer) => string;
Converts an ArrayBuffer to a hex string without padding or normalization.
Parameters
buffer
ArrayBuffer
The ArrayBuffer to convert
Returns
string
A lowercase hex string representation of the buffer
### <a id="toJsonArray"></a>toJsonArray
@xylabs/sdk-js
const toJsonArray: {
<T> (value): T & unknown[] | undefined;
<T> (value, assert): T & unknown[];
};
Parses a value into a JsonArray, throwing if it does not conform.
Call Signature
<T>(value): T & unknown[] | undefined;
Type Parameters
T
T
Parameters
value
T
Returns
T & unknown[] | undefined
Call Signature
<T>(value, assert): T & unknown[];
Type Parameters
T
T
Parameters
value
T
assert
ZodFactoryConfig
Returns
T & unknown[]
### <a id="toJsonObject"></a>toJsonObject
@xylabs/sdk-js
const toJsonObject: {
<T> (value): T & Record<string, unknown> | undefined;
<T> (value, assert): T & Record<string, unknown>;
};
Parses a value into a JsonObject, throwing if it does not conform.
Call Signature
<T>(value): T & Record<string, unknown> | undefined;
Type Parameters
T
T
Parameters
value
T
Returns
T & Record<string, unknown> | undefined
Call Signature
<T>(value, assert): T & Record<string, unknown>;
Type Parameters
T
T
Parameters
value
T
assert
ZodFactoryConfig
Returns
T & Record<string, unknown>
### <a id="toJsonValue"></a>toJsonValue
@xylabs/sdk-js
const toJsonValue: {
<T> (value): T | undefined;
<T> (value, assert): T;
};
Parses a value into a JsonValue, throwing if it does not conform.
Call Signature
<T>(value): T | undefined;
Type Parameters
T
T
Parameters
value
T
Returns
T | undefined
Call Signature
<T>(value, assert): T;
Type Parameters
T
T
Parameters
value
T
assert
ZodFactoryConfig
Returns
T
### <a id="toSafeJson"></a>toSafeJson
@xylabs/sdk-js
const toSafeJson: (value, maxDepth?) => JsonValue;
Converts a value to a JSON-safe representation, handling circular references and non-serializable types.
Parameters
value
unknown
The value to convert.
maxDepth?
number
Maximum recursion depth.
Returns
JsonValue
A JSON-safe value.
### <a id="toSafeJsonArray"></a>toSafeJsonArray
@xylabs/sdk-js
const toSafeJsonArray: (value, cycleList?, maxDepth?) => any[];
Converts an array to a JSON-safe array, handling circular references and depth limits.
Parameters
value
unknown[]
The array to convert.
cycleList?
unknown[]
Tracks visited objects to detect circular references.
maxDepth?
number
Maximum recursion depth before truncating.
Returns
any[]
A JSON-safe array representation.
### <a id="toSafeJsonObject"></a>toSafeJsonObject
@xylabs/sdk-js
const toSafeJsonObject: (value, cycleList?, maxDepth?) => JsonObject;
Converts an object to a JSON-safe object, handling circular references and depth limits.
Parameters
value
object
The object to convert.
cycleList?
unknown[]
Tracks visited objects to detect circular references.
maxDepth?
number
Maximum recursion depth before truncating.
Returns
JsonObject
A JSON-safe object representation.
### <a id="toSafeJsonString"></a>toSafeJsonString
@xylabs/sdk-js
const toSafeJsonString: (value, maxDepth?) => string;
Converts a value to a pretty-printed JSON string, safely handling circular references and non-JSON types.
Parameters
value
unknown
The value to serialize.
maxDepth?
number
Maximum recursion depth.
Returns
string
A formatted JSON string.
### <a id="toSafeJsonValue"></a>toSafeJsonValue
@xylabs/sdk-js
const toSafeJsonValue: (value, cycleList?, maxDepth?) => JsonValue;
Converts an unknown value to a JSON-safe value, replacing circular references with '[Circular]' and
non-JSON types with descriptive placeholder strings.
Parameters
value
unknown
The value to convert.
cycleList?
unknown[]
Tracks visited objects to detect circular references.
maxDepth?
number
Maximum recursion depth before truncating with '[MaxDepth]'.
Returns
JsonValue
A JSON-safe representation of the value.
### <a id="typeOf"></a>typeOf
@xylabs/sdk-js
const typeOf: <T>(item) => TypeOfTypes;
Extended typeof that distinguishes arrays from objects (unlike native typeof).
Type Parameters
T
T
Parameters
item
T
The value to check.
Returns
TypeOfTypes
The type of the item as a TypeOfTypes string.
### <a id="union"></a>union
@xylabs/sdk-js
const union: <TKey>(a, b) => Set<TKey>;
Returns a new set containing all elements from both a and b.
Type Parameters
TKey
TKey
Parameters
a
Set<TKey>
The first set
b
Set<TKey>
The second set
Returns
Set<TKey>
A new set representing the union of a and b
### <a id="uniq"></a>uniq
@xylabs/sdk-js
const uniq: <T>(arr) => T[];
Returns a new array with duplicate values removed.
Type Parameters
T
T
Parameters
arr
T[]
The input array
Returns
T[]
A deduplicated array
### <a id="uniqBy"></a>uniqBy
@xylabs/sdk-js
const uniqBy: <T, I>(arr, iteratee) => T[];
Returns a new array with duplicates removed, using a key function for comparison.
Type Parameters
T
T
I
I
Parameters
arr
T[]
The input array
iteratee
(item) => I
Function that returns the key to compare by
Returns
T[]
A deduplicated array keeping the first occurrence of each key
### <a id="validateType"></a>validateType
@xylabs/sdk-js
const validateType: <T>(typeName, value, optional?) => [T | undefined, Error[]];
Validates that a value matches the expected type, returning the value and any errors.
Type Parameters
T
T
Parameters
typeName
TypeOfTypes
The expected type name.
value
T
The value to validate.
optional?
boolean
If true, undefined values are accepted without error.
Returns
[T | undefined, Error[]]
A tuple of [value or undefined, array of errors].