Core Utilities
GetResponsibleModule
GetResponsibleModule determines which module is currently executing by inspecting the call stack. The core uses this function internally for automatic proxy cleanup and logging attribution. You can also call it directly when you need to know the caller's identity.
import { GetResponsibleModule } from "@antelopejs/interface-core";
const moduleId = GetResponsibleModule();
The function returns the module ID string, or undefined if the call originates outside any module context (for example, from the core itself). Use the return value to make decisions based on which module triggered a particular code path.
InterfaceFunction
InterfaceFunction creates a callable function backed by an AsyncProxy. InterfaceFunction is the primary way to declare functions in an interface definition. Consumers call the returned function like any regular async function — the proxy handles routing to the correct implementation.
import { InterfaceFunction } from "@antelopejs/interface-core";
export const GetUser = InterfaceFunction<(id: string) => Promise<User>>();
export const CreateUser = InterfaceFunction<(data: UserInput) => Promise<User>>();
Consumers import and call these functions directly. The proxy routes each call to the correct provider at runtime.
import { GetUser } from "@antelopejs/interface-example";
const user = await GetUser("user-123");
The type parameter defines the function signature. The returned function is fully typed, so consumers get autocompletion and type checking at the call site.
ImplementInterface
ImplementInterface connects an interface declaration with its implementation. Call it during the module's construct phase to bind your implementation functions to the corresponding interface proxies.
import { ImplementInterface } from "@antelopejs/interface-core";
export async function construct() {
ImplementInterface(
await import("./interface"),
await import("./implementations")
);
}
The first argument is the interface module (containing InterfaceFunction declarations). The second argument is the implementation module, which must export functions with the same names. The core matches each declaration to its implementation by name and attaches the implementation via the underlying proxy.
For standalone interface packages, import from the package name instead of a local path:
import { ImplementInterface } from "@antelopejs/interface-core";
export async function construct() {
ImplementInterface(
await import("@antelopejs/interface-email"),
await import("./implementations")
);
}
GetMetadata
GetMetadata retrieves metadata attached to a target object using a metadata class. Use it for reflection and introspection when building systems that need to read decorator-applied configuration at runtime.
import { GetMetadata } from "@antelopejs/interface-core";
class MyMeta {
static key = Symbol("MyMeta");
constructor(target: any) { /* initialize from target */ }
}
const metadata = GetMetadata(myInstance, MyMeta);
The function takes the target object as the first argument and a metadata class (with a static key symbol) as the second. An optional third argument controls prototype chain inheritance (defaults to true). The return value is an instance of the metadata class associated with the target.
GetInterfaceInstances and GetInterfaceInstance
These functions retrieve interface connection information at runtime. They are useful when multiple modules implement the same interface and you need to query or iterate over the connections.
import { GetInterfaceInstances, GetInterfaceInstance } from "@antelopejs/interface-core";
// Get all connections for a specific interface
const allConnections = GetInterfaceInstances("@antelopejs/interface-email");
// Get a specific connection by interface ID and connection ID
const connection = GetInterfaceInstance("@antelopejs/interface-email", "brevo-module");
GetInterfaceInstances takes an interface ID and returns all connections to implementations of that interface. GetInterfaceInstance takes an interface ID and a connection ID and returns the matching connection, or undefined if not found. These functions are primarily useful for advanced scenarios such as multi-provider routing or interface diagnostics.
Decorator Factories
Antelopejs provides factory functions that create typed decorators for use in interface definitions. These factories take a handler function whose arguments are split in two: the first arguments are the decorator target arguments (class, property key, descriptor, or parameter index depending on the decorator type), and the remaining arguments become the factory parameters that users pass when applying the decorator.
Basic Factories
Each factory creates a decorator for a specific target type. The type parameter T defines the factory parameter types as a tuple.
import {
MakeClassDecorator,
MakePropertyDecorator,
MakeMethodDecorator,
MakeParameterDecorator
} from "@antelopejs/interface-core/decorators";
// Create a class decorator — handler receives (target, ...factoryArgs)
const MyDecorator = MakeClassDecorator<[name: string]>((target, name) => {
// target is the class constructor, name is the factory parameter
});
// Create a property decorator — handler receives (target, key, ...factoryArgs)
const MyPropDecorator = MakePropertyDecorator<[required: boolean]>((target, key, required) => {
// target is the prototype, key is the property name
});
// Create a method decorator — handler receives (target, key, descriptor, ...factoryArgs)
const MyMethodDecorator = MakeMethodDecorator<[route: string]>((target, key, descriptor, route) => {
// target is the prototype, key is the method name, descriptor is the property descriptor
});
// Create a parameter decorator — handler receives (target, key, index, ...factoryArgs)
const MyParamDecorator = MakeParameterDecorator<[validate: boolean]>((target, key, index, validate) => {
// target is the prototype, key is the method name, index is the parameter position
});
The handler function receives the standard decorator arguments first, followed by any factory parameters. When applying the decorator, users pass only the factory parameters:
@MyDecorator("MyClassName")
class Example {
@MyPropDecorator(true)
name!: string;
@MyMethodDecorator("/api/users")
getUsers(@MyParamDecorator(true) id: string) {}
}
Combined Factories
Combined factories create decorators that work on multiple target types. Use these when a single decorator should be applicable to more than one kind of declaration.
import {
MakeMethodAndClassDecorator,
MakeParameterAndMethodDecorator
} from "@antelopejs/interface-core/decorators";
// Works on both methods and classes
const Transactional = MakeMethodAndClassDecorator<[isolation?: string]>((target, key, descriptor, isolation) => {
// key and descriptor are undefined when applied to a class
});
// Works on both parameters and methods
const Validate = MakeParameterAndMethodDecorator<[schema: string]>((target, key, indexOrDescriptor, schema) => {
// indexOrDescriptor is a number for parameters, a PropertyDescriptor for methods
});
Route method decorator and a Controller class decorator that consumers apply to their handler classes.