Skip to content

Core API Reference

All exports from @pandino/pandino.

ts
import { OSGiBootstrap, ServiceTracker, /* ... */ } from '@pandino/pandino';

Bootstrap

ExportTypeDescription
OSGiBootstrapClassEntry point for initializing the framework
BootstrapConfigInterfaceConfiguration options for the bootstrap process

OSGiBootstrap

ts
const bootstrap = new OSGiBootstrap({ frameworkLogLevel: LogLevel.DEBUG });
const framework = await bootstrap.start();
MemberSignatureDescription
constructornew OSGiBootstrap(config?: BootstrapConfig)Creates a new bootstrap instance
startstart(): Promise<OSGiFramework>Starts the framework and all built-in services
stopstop(): Promise<void>Stops the framework and all bundles
getFrameworkgetFramework(): OSGiFrameworkReturns the framework instance

BootstrapConfig

PropertyTypeDefaultDescription
frameworkLogLevel?LogLevelLogLevel.INFOLog level for framework-level logging

Framework & Bundle

ExportTypeDescription
OSGiFrameworkClassThe running framework instance
BundleInterfaceRepresents an installed bundle
BundleContextInterfaceAccess point for bundle operations
BundleActivatorInterfaceLifecycle callbacks for a bundle
BundleMetadataInterfaceBundle header metadata
BundleModuleInterfaceModule format for bundle loading

OSGiFramework

The core framework class. Implements BundleActivator.

MethodSignatureDescription
startstart(): Promise<void>Starts the framework
stopstop(): Promise<void>Stops all bundles and the framework
getBundleContextgetBundleContext(): BundleContextReturns the system bundle context
getBundlegetBundle(id: number): Bundle | nullReturns a bundle by ID
getBundlesgetBundles(): Bundle[]Returns all installed bundles
installBundleinstallBundle(module: Promise<BundleModule>, config?): Promise<Bundle>Installs a bundle from a module promise
installBundleinstallBundle(location: string, config?): Promise<Bundle>Installs a bundle from a location string

Bundle

MethodSignatureDescription
getBundleIdgetBundleId(): numberReturns the bundle's unique identifier
getSymbolicNamegetSymbolicName(): stringReturns the bundle's symbolic name
getVersiongetVersion(): stringReturns the bundle's version
getStategetState(): BundleStateReturns the current state (see BUNDLE_STATES)
getHeadersgetHeaders(locale?: string): Record<string, string>Returns the bundle's headers
getLocationgetLocation(): stringReturns the bundle's install location
startstart(options?: number): Promise<void>Starts the bundle
stopstop(options?: number): Promise<void>Stops the bundle
updateupdate(source?: ReadableStream): Promise<void>Updates the bundle
uninstalluninstall(): Promise<void>Uninstalls the bundle
getRegisteredServicesgetRegisteredServices(): ServiceReference<any>[]Returns services registered by this bundle
getServicesInUsegetServicesInUse(): ServiceReference<any>[]Returns services currently used by this bundle
getContextgetContext(): BundleContextReturns the bundle's context
getBundleModulegetBundleModule(): BundleModule | nullReturns the original bundle module
getResourcegetResource(path: string): string | nullReturns a resource by logical path
findResourcesfindResources(basePath: string, pattern: string): string[]Finds resources matching a glob pattern

BundleContext

MethodSignatureDescription
registerServiceregisterService<S>(clazz: string | string[] | Function, service: S, properties?: Record<string, any>): ServiceRegistration<S>Registers a service
getServiceReferencegetServiceReference<S>(clazz: string | Function): ServiceReference<S> | nullGets the best matching service reference
getServiceReferencesgetServiceReferences<S>(clazz: string | Function, filter?: string | null): ServiceReference<S>[] | nullGets all matching service references
getServicegetService<S>(reference: ServiceReference<S>): S | nullGets the service object from a reference
ungetServiceungetService(reference: ServiceReference<any>): booleanReleases a service reference
installBundleinstallBundle(module: Promise<BundleModule>, config?): Promise<Bundle>Installs a bundle
addServiceListeneraddServiceListener(listener: ServiceListener, filter?: string): voidAdds a service event listener
removeServiceListenerremoveServiceListener(listener: ServiceListener): voidRemoves a service event listener
addBundleListeneraddBundleListener(listener: BundleListener): voidAdds a bundle event listener
removeBundleListenerremoveBundleListener(listener: BundleListener): voidRemoves a bundle event listener
createFiltercreateFilter(filter: string): FilterCreates an LDAP filter
getBundlegetBundle(): BundleReturns this context's bundle
getBundlesgetBundles(): Bundle[]Returns all installed bundles
getPropertygetProperty(key: string): string | undefinedReturns a framework property
getLogServicegetLogService(): LogService | nullReturns the log service if available
getDataFilegetDataFile(filename: string): stringReturns a data file path for the bundle

BundleActivator

ts
class MyActivator implements BundleActivator {
  async start(context: BundleContext) { /* register services */ }
  async stop(context: BundleContext) { /* cleanup */ }
}
MethodSignatureDescription
startstart(context: BundleContext): void | Promise<void>Called when the bundle is started
stopstop(context: BundleContext): void | Promise<void>Called when the bundle is stopped

BundleMetadata

PropertyTypeRequiredDescription
bundleSymbolicNamestringYesUnique bundle identifier
bundleVersionstringYesSemantic version string
bundleName?stringNoHuman-readable name
bundleDescription?stringNoBundle description
bundleManifestVersion?stringNoManifest format version
bundleActivator?stringNoActivator class name
importPackage?stringNoRequired packages
exportPackage?stringNoExported packages
requireBundle?stringNoRequired bundles

BundleModule

The expected shape of a bundle module for installBundle().

ts
const bundleModule: BundleModule = {
  default: {
    headers: {
      bundleSymbolicName: 'com.example.my-bundle',
      bundleVersion: '1.0.0',
    },
    activator: new MyActivator(),
    components: [MyComponentClass],
    resources: { 'config.json': '{"key": "value"}' },
  },
};
PropertyTypeDescription
default.headersobjectBundle metadata headers
default.activator?BundleActivatorOptional lifecycle activator
default.components?(new (...args: any[]) => any)[]Optional SCR component classes
default.resources?Record<string, string>Optional resource map (logical path to content)

Service Registry

ExportTypeDescription
ServiceReference<S>InterfaceHandle to look up a service
ServiceRegistration<S>InterfaceHandle for a registered service
ServiceFactory<S>InterfaceFactory for per-bundle service instances
FilterInterfaceLDAP filter for service matching
ServiceTracker<S, T>ClassTracks matching services dynamically
ServiceTrackerCustomizer<S, T>InterfaceCallbacks for customizing service tracking

ServiceReference<S>

MethodSignatureDescription
getPropertygetProperty(key: string): anyReturns a service property
getPropertyKeysgetPropertyKeys(): string[]Returns all property keys
getBundlegetBundle(): BundleReturns the bundle that registered the service
getPropertiesgetProperties(): Record<string, any>Returns all service properties
isAssignableToisAssignableTo(bundle: Bundle, className: string): booleanChecks assignment compatibility

ServiceRegistration<S>

MethodSignatureDescription
getReferencegetReference(): ServiceReference<S>Returns the service reference
setPropertiessetProperties(properties: Record<string, any>): voidUpdates service properties
unregisterunregister(): voidUnregisters the service

ServiceFactory<S>

ts
const factory: ServiceFactory<MyService> = {
  getService(bundle, registration) { return new MyServiceImpl(bundle); },
  ungetService(bundle, registration, service) { service.dispose(); },
};
MethodSignatureDescription
getServicegetService(bundle: Bundle, registration: ServiceRegistration<S>): SCreates a service instance for a bundle
ungetServiceungetService(bundle: Bundle, registration: ServiceRegistration<S>, service: S): voidReleases a service instance

Filter

MethodSignatureDescription
matchmatch(properties: Record<string, any>): booleanTests whether properties match the filter
toStringtoString(): stringReturns the LDAP filter string

ServiceTracker<S, T>

ts
const tracker = new ServiceTracker(context, 'MyService');
tracker.open();
const service = tracker.getService();
MemberSignatureDescription
constructornew ServiceTracker(context, referenceOrClassNameOrFilter, customizer?)Creates a tracker. Second argument can be a ServiceReference, class name string, Function, or Filter
openopen(): ServiceTracker<S, T>Starts tracking; returns itself for chaining
closeclose(): voidStops tracking and releases all tracked services
getServicegetService(reference?): T | nullReturns the highest-ranked tracked service, or one by reference
getServicesgetServices(): T[]Returns all tracked service objects
getServiceReferencesgetServiceReferences(): ServiceReference<S>[] | nullReturns tracked references sorted by ranking
sizesize(): numberReturns the number of tracked services

ServiceTrackerCustomizer<S, T>

MethodSignatureDescription
addingServiceaddingService(reference: ServiceReference<S>, service: S): T | nullCalled when a service is being added. Return null to skip tracking
modifiedServicemodifiedService(reference: ServiceReference<S>, service: S, tracked: T): voidCalled when a tracked service's properties change
removedServiceremovedService(reference: ServiceReference<S>, service: S, tracked: T): voidCalled when a tracked service is unregistering

Events & Listeners

ExportTypeDescription
ServiceEventClassFired on service registry changes
BundleEventClassFired on bundle lifecycle changes
ServiceListenerInterfaceListener for service events
BundleListenerInterfaceListener for bundle events

ServiceEvent

MemberSignatureDescription
constructornew ServiceEvent(type: ServiceEventType, reference: ServiceReference<any>)Creates a service event
getTypegetType(): ServiceEventTypeReturns the event type (see SERVICE_EVENT_TYPES)
getServiceReferencegetServiceReference(): ServiceReference<any>Returns the affected service reference

BundleEvent

MemberSignatureDescription
constructornew BundleEvent(type: number, bundle: Bundle)Creates a bundle event
getTypegetType(): numberReturns the event type
getBundlegetBundle(): BundleReturns the affected bundle

ServiceListener

MethodSignatureDescription
serviceChangedserviceChanged(event: ServiceEvent): voidCalled when a service event occurs

BundleListener

MethodSignatureDescription
bundleChangedbundleChanged(event: BundleEvent): voidCalled when a bundle event occurs

Built-in Services

Event Admin

ExportTypeDescription
EventAdminInterfacePublish-subscribe event service
EventClassAn event with a topic and properties
EventHandlerInterfaceHandler for events

EventAdmin

MethodSignatureDescription
postEventpostEvent(event: Event): voidPosts an event asynchronously
sendEventsendEvent(event: Event): voidSends an event synchronously

Event

ts
const event = new Event('com/example/topic', { key: 'value' });
MemberSignatureDescription
constructornew Event(topic: string, properties?: Record<string, any>)Creates an event
getTopicgetTopic(): stringReturns the event topic
getPropertygetProperty(name: string): anyReturns a property value
getPropertiesgetProperties(): Record<string, any>Returns a copy of all properties
getPropertyNamesgetPropertyNames(): string[]Returns all property keys
containsPropertycontainsProperty(name: string): booleanChecks if a property exists

EventHandler

MethodSignatureDescription
handleEventhandleEvent(event: Event): voidCalled when a matching event is received

Configuration Admin

ExportTypeDescription
ConfigurationAdminInterfaceService for managing configurations
ConfigurationInterfaceA single configuration instance
ManagedServiceInterfaceService that receives configuration updates
ManagedServiceFactoryInterfaceFactory that receives per-PID configuration updates
ConfigurationEventTypeEnumType of configuration change
ConfigurationEventInterfaceEvent for configuration changes
ConfigurationListenerInterfaceListener for configuration events

ConfigurationAdmin

MethodSignatureDescription
getConfigurationgetConfiguration(pid: string, location?: string): Promise<Configuration>Gets or creates a configuration by PID
createFactoryConfigurationcreateFactoryConfiguration(factoryPid: string, location?: string): Promise<Configuration>Creates a new factory configuration
listConfigurationslistConfigurations(filter?: string): Promise<Configuration[] | null>Lists configurations matching a filter

Configuration

MethodSignatureDescription
getPidgetPid(): stringReturns the configuration PID
getFactoryPidgetFactoryPid(): string | nullReturns the factory PID, if any
getPropertiesgetProperties(): Record<string, any> | nullReturns configuration properties
updateupdate(properties: Record<string, any>): Promise<void>Updates configuration properties
deletedelete(): Promise<void>Deletes the configuration
getBundleLocationgetBundleLocation(): string | nullReturns the bound bundle location
setBundleLocationsetBundleLocation(location: string | null): Promise<void>Sets the bundle location binding

ManagedService

MethodSignatureDescription
updatedupdated(properties: Record<string, any> | null): void | Promise<void>Called when configuration is updated or deleted

ManagedServiceFactory

MethodSignatureDescription
getNamegetName(): stringReturns the factory name
updatedupdated(pid: string, properties: Record<string, any>): void | Promise<void>Called when a factory configuration is created or updated
deleteddeleted(pid: string): void | Promise<void>Called when a factory configuration is deleted

ConfigurationEventType

ValueNumberDescription
UPDATED1Configuration was updated
DELETED2Configuration was deleted

ConfigurationEvent

MethodSignatureDescription
getPidgetPid(): stringReturns the PID of the changed configuration
getFactoryPidgetFactoryPid(): string | nullReturns the factory PID, if any
getTypegetType(): ConfigurationEventTypeReturns the event type

ConfigurationListener

MethodSignatureDescription
configurationEventconfigurationEvent(event: ConfigurationEvent): voidCalled when a configuration change occurs

Log Service

ExportTypeDescription
LogServiceInterfaceLogging service
LogLevelEnumLogging severity levels

LogService

MethodSignatureDescription
loglog(level: LogLevel, message: string, exception?: Error, context?: Record<string, unknown>): voidLogs at a specific level
errorerror(message: string, exception?: Error, context?: Record<string, unknown>): voidLogs an error
warnwarn(message: string, exception?: Error, context?: Record<string, unknown>): voidLogs a warning
infoinfo(message: string, exception?: Error, context?: Record<string, unknown>): voidLogs an informational message
debugdebug(message: string, exception?: Error, context?: Record<string, unknown>): voidLogs a debug message
isLoggableisLoggable(level: LogLevel): booleanChecks if a level is currently loggable
setLogLevelsetLogLevel(level: LogLevel): voidSets the minimum log level
getLogLevelgetLogLevel(): LogLevelReturns the current log level
addLogListeneraddLogListener(listener: LogListener): voidAdds a log listener
removeLogListenerremoveLogListener(listener: LogListener): voidRemoves a log listener

LogLevel

ValueNumberDescription
ERROR1Error conditions
WARN2Warning conditions
INFO3Informational messages
DEBUG4Debug-level messages

Declarative Services

ExportTypeDescription
ServiceComponentRuntimeClassThe SCR service that manages component lifecycle
ComponentContextInterfaceContext available to activated components
getDecoratorInfoFunctionReturns decorator metadata for a component class

ServiceComponentRuntime

MethodSignatureDescription
registerComponentregisterComponent(classRef: any, bundleId?: number): Promise<void>Registers and activates a decorated component class

ComponentContext

Passed to @Activate methods and available during component lifecycle.

MethodSignatureDescription
getBundleContextgetBundleContext(): BundleContextReturns the owning bundle's context
getPropertiesgetProperties(): Record<string, any>Returns the component's properties
getServiceReferencegetServiceReference(): ServiceReference<any>Returns this component's service reference
getComponentNamegetComponentName(): stringReturns the component name
locateServicelocateService<S>(name: string): S | nullLooks up a bound service by reference name
locateServiceslocateServices<S>(name: string): S[]Looks up all bound services by reference name
disableComponentdisableComponent(name: string): voidDisables a component by name
enableComponentenableComponent(name: string): voidEnables a component by name

getDecoratorInfo

ts
import { getDecoratorInfo } from '@pandino/pandino';

const info = getDecoratorInfo(MyComponentClass);
// info.component, info.service, info.configuration, info.lifecycle, info.references

Returns a DecoratorInfo object with the following shape:

PropertyTypeDescription
componentComponentInfoComponent name, enabled, immediate, factory status
serviceServiceInfoService interfaces and scope
configurationConfigurationInfoConfiguration PID, policy, and properties
lifecycleLifecycleInfoNames of activate, deactivate, and modified methods
referencesReferenceDescriptor[]Array of reference descriptors
rawMetadataComponentDescriptor | nullThe full component descriptor, if present
customDecoratorsRecord<string, any>Custom class-level decorator metadata
customFieldDecoratorsRecord<string, Record<string, any>>Custom field-level decorator metadata
customMethodDecoratorsRecord<string, Record<string, any>>Custom method-level decorator metadata

Constants

ExportTypeDescription
BUNDLE_STATESobjectNumeric constants for bundle states
SERVICE_EVENT_TYPESobjectNumeric constants for service event types

BUNDLE_STATES

KeyValueDescription
INSTALLED2Bundle has been installed
RESOLVED4Bundle dependencies are resolved
STARTING8Bundle is starting
ACTIVE32Bundle is running
STOPPING16Bundle is stopping
UNINSTALLED1Bundle has been uninstalled

SERVICE_EVENT_TYPES

KeyValueDescription
REGISTERED1A service was registered
MODIFIED2A service's properties were modified
UNREGISTERING4A service is being unregistered
MODIFIED_ENDMATCH8A service was modified and no longer matches a listener's filter

Released under the Eclipse Public License 2.0.