import { EventEmitter } from "node:events"; import { Duplex } from "node:stream"; //#region src/variant.d.ts /** * @class * A class to represent DBus variants for both the client and service * interfaces. The {@link ProxyInterface} and [`Interface`]{@link * module:interface~Interface} methods, signals, and properties will use this * type to represent variant types. The user should use this class directly for * sending variants to methods if their signature expects the type to be a * variant. * * @example * let str = new Variant('s', 'hello'); * let num = new Variant('d', 53); * let map = new Variant('a{ss}', { foo: 'bar' }); * let list = new Variant('as', [ 'foo', 'bar' ]); */ declare class Variant { signature: string; value: T; /** * Construct a new `Variant` with the given signature and value. * @param {string} signature - a DBus type signature for the `Variant`. * @param {any} value - the value of the `Variant` with type specified by the type signature. */ constructor(); constructor(signature: string, value: T); } //#endregion //#region src/introspect-types.d.ts interface IntrospectArg { $: { name?: string; direction?: string; type: string; }; } interface IntrospectAnnotation { $: { name: string; value: string; }; } interface IntrospectProperty { $: { name: string; type: string; access: string; }; annotation?: IntrospectAnnotation[]; } interface IntrospectMethod { $: { name: string; }; arg?: IntrospectArg[]; annotation?: IntrospectAnnotation[]; } interface IntrospectSignal { $: { name: string; }; arg?: IntrospectArg[]; annotation?: IntrospectAnnotation[]; } interface IntrospectInterface { $: { name: string; }; property?: IntrospectProperty[]; method?: IntrospectMethod[]; signal?: IntrospectSignal[]; annotation?: IntrospectAnnotation[]; } //#endregion //#region src/signature.d.ts interface SignatureNode { type: string; child: SignatureNode[]; } //#endregion //#region src/service/interface.d.ts type PropertyAccess = 'read' | 'write' | 'readwrite'; interface PropertyOptions { signature: string; access?: PropertyAccess; name?: string; disabled?: boolean; } interface MethodOptions { inSignature?: string; outSignature?: string; name?: string; disabled?: boolean; noReply?: boolean; } interface SignalOptions { signature?: string; name?: string; disabled?: boolean; } interface ConfigureMembersOptions { properties?: Record; methods?: Record; signals?: Record; } type InterfaceMethodFn = (...args: never[]) => unknown; interface PropertyOptionsResolved { signature: string; signatureTree: SignatureNode[]; access: PropertyAccess; name: string; disabled: boolean; } interface MethodOptionsResolved { inSignature: string; outSignature: string; inSignatureTree: SignatureNode[]; outSignatureTree: SignatureNode[]; name: string; disabled: boolean; noReply: boolean; fn: InterfaceMethodFn; } interface SignalOptionsResolved { signature: string; signatureTree: SignatureNode[]; name: string; disabled: boolean; fn: InterfaceMethodFn; } type PropertyDecoratorContext = ClassFieldDecoratorContext | ClassGetterDecoratorContext | ClassSetterDecoratorContext | ClassAccessorDecoratorContext; interface DualPropertyDecorator { (value: unknown, context: PropertyDecoratorContext): void; (target: object, propertyKey: string | symbol): void; } interface DualMethodDecorator { (value: InterfaceMethodFn, context: ClassMethodDecoratorContext): void; (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; } interface DualSignalDecorator { (value: T, context: ClassMethodDecoratorContext): T; (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; } /** * The `Interface` is an abstract class used for defining and exporting an * interface on a DBus name. You can override this class to make your own DBus * interfaces. Use the decorators within this module to define the * [properties]{@link module:interface.property}, [methods]{@link * module:interface.method}, and [signals]{@link module:interface.signal} that * the interface has. These will be advertised to users in the introspection * xml gotten by the `org.freedesktop.DBus.Introspect` method on the name. See * the documentation for the decorators for more information. The constructor * of the `Interface` should call `super()` with the name of the interface that * will be exported. * * @example * class MyInterface extends Interface { * constructor() { * super('org.test.interface_name'); * } * // define properties, methods, and signals with decorated functions * } * let bus = dbus.sessionBus(); * let name = await bus.requestName('org.test.bus_name'); * let iface = new MyInterface(); * name.export('/org/test/path', iface); */ interface InterfaceEmitterEvents { signal: [options: SignalOptionsResolved, result: unknown]; 'properties-changed': [changedProperties: Record, invalidatedProperties: string[]]; } declare class Interface extends EventEmitter { $name: string; $emitter: EventEmitter; $properties?: Record; $methods?: Record; $signals?: Record; /** * Create an interface. This should be called with the name of the interface * in the class that extends it. */ constructor(name: string); /** * An alternative to the decorator functions to configure * [`Interface`]{@link module:interface~Interface} DBus members when * decorators cannot be supported. * * *Calling this method twice on the same `Interface` or mixing this method * with the decorator interface will result in undefined behavior that may be * specified at a future time.* * * @static * @param members {Object} - Member configuration object. */ static configureMembers(members: ConfigureMembersOptions): void; /** * Emit the `PropertiesChanged` signal on an [`Interface`s]{@link * module:interface~Interface} associated standard * `org.freedesktop.DBus.Properties` interface with a map of new values and * invalidated properties. Pass the properties as JavaScript values. * * @static * @example * Interface.emitPropertiesChanged({ SomeProperty: 'bar' }, ['InvalidedProperty']); * * @param {module:interface~Interface} - the `Interface` to emit the `PropertiesChanged` signal on * @param {Object} - A map of property names and new property values that are changed. * @param {string[]} - A list of invalidated properties. */ static emitPropertiesChanged(iface: Interface, changedProperties: Record, invalidatedProperties?: string[]): void; $introspect(): IntrospectInterface; } //#endregion //#region src/message-type.d.ts interface MessageLike { type?: number; serial?: number | null; path?: string; interface?: string; member?: string; errorName?: string; replySerial?: number; destination?: string; sender?: string; signature?: string; body?: unknown[]; flags?: number; } /** * @class * A `Message` is a class used for sending and receiving messages through the * {@link MessageBus} with the low-level api. `Message`s can be constructed by * the user directly for method calls or with the static convenience methods on * this class for the other types of messages. `Message`s can be sent through a * connected MessageBus with {@link MessageBus#call} for method calls that * expect a reply from the server or {@link MessageBus#send} for messages that * do not expect a reply. See those methods for an example of how to use this * class. * * @see https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol * * @param {object} options - Options to construct this `Message` with. See the * corresponding member for more information. * @param {MessageType} [options.type={@link MessageType.METHOD_CALL}] * @param {int} [options.serial] * @param {string} [options.destination] * @param {string} [options.path] * @param {string} [options.interface] - Required for signals. * @param {string} [options.member] - Required for method calls and signals. * @param {string} [options.signature=''] * @param {Array} [options.body=[]] - Must match the signature. * @param {string} [options.errorName] - Must be a valid interface name. * Required for errors. * @param {string} [options.replySerial] - Required for errors and method returns. * @param {MessageFlags} [options.flags] */ declare class Message { type: number; _sent: boolean; private _serial; path: string; interface: string; member: string; errorName: string; replySerial: number | undefined; destination: string; sender: string; signature: string; body: unknown[]; flags: number; /** * Construct a new `Message` to send on the bus. */ constructor(msg: MessageLike); /** * @member {int} - The serial of the message to track through the bus. You * must use {@link MessageBus#newSerial} to get this serial. If not set, it * will be set automatically when the message is sent. */ get serial(): number | null; set serial(value: number | null); /** * Construct a new `Message` of type `ERROR` in reply to the given `Message`. * * @param {Message} msg - The `Message` this error is in reply to. * @param {string} errorName - The name of the error. Must be a valid * interface name. * @param {string} [errorText='An error occurred.'] - An error message for * the error. */ static newError(msg: Message, errorName: string, errorText?: string): Message; /** * Construct a new `Message` of type `METHOD_RETURN` in reply to the given * message. * * @param {Message} msg - The `Message` this `Message` is in reply to. * @param {string} signature - The signature for the message body. * @param {Array} body - The body of the message as an array of arguments. * Must match the signature. */ static newMethodReturn(msg: Message, signature?: string, body?: unknown[]): Message; /** * Construct a new `Message` of type `SIGNAL` to broadcast on the bus. * * @param {string} path - The object path of this signal. * @param {string} iface - The interface of this signal. * @param {string} signature - The signature of the message body. * @param {Array] body - The body of the message as an array of arguments. * Must match the signature. */ static newSignal(path: string, iface: string, name: string, signature?: string, body?: unknown[]): Message; } //#endregion //#region src/service/object.d.ts declare class ServiceObject { path: string; bus: ServiceBus; interfaces: Record; private _handlers; constructor(path: string, bus: ServiceBus); addInterface(iface: Interface): void; removeInterface(iface: Interface): void; introspect(): IntrospectInterface[]; static defaultInterfaces(): IntrospectInterface[]; } //#endregion //#region src/dbus-buffer.d.ts interface DBusBufferOptions { ayBuffer?: boolean; } //#endregion //#region src/message.d.ts interface RawMessage { serial?: number | null; type?: number; flags?: number; signature?: string; body?: unknown[]; path?: string; interface?: string; member?: string; errorName?: string; replySerial?: number; destination?: string; sender?: string; unixFd?: number; } //#endregion //#region src/service/types.d.ts interface ServiceBus { send(msg: Message): void; readonly _serviceObjects: Record; _getServiceObject(path: string): ServiceObject; _introspect(path: string): string; readonly _connection: { message(msg: RawMessage): void; }; _serial: number; } //#endregion //#region src/client/proxy-interface.d.ts interface ProxySignalInfo { name: string; signature: string; } interface ProxyMethodInfo { name: string; inSignature: string; outSignature: string; } interface ProxyPropertyInfo { name: string; type: string; access: string; } declare class ProxyListener { refcount: number; readonly fn: (msg: Message) => void; constructor(signal: ProxySignalInfo, iface: ProxyInterface); } /** * A class to represent a proxy to an interface exported on the bus to be used * by a client. A `ProxyInterface` is gotten by interface name from the {@link * ProxyObject} from the {@link MessageBus}. This class is constructed * dynamically based on the introspection data on the bus. The advertised * methods of the interface are exposed as class methods that take arguments * and return a Promsie that resolves to types specified by the type signature * of the DBus method. The `ProxyInterface` is an `EventEmitter` that emits * events with types that are specified by the type signature of the DBus * signal advertised on the bus when that signal is received. * * If an interface method call returns an error, `ProxyInterface` method call * will throw a {@link DBusError}. */ declare class ProxyInterface extends EventEmitter> { $name: string; $object: ProxyObject; $properties: ProxyPropertyInfo[]; $methods: ProxyMethodInfo[]; $signals: ProxySignalInfo[]; private readonly $listeners; /** * Create a new `ProxyInterface`. This constructor should not be called * directly. Use {@link ProxyObject#getInterface} to get a proxy interface. */ constructor(name: string, object: ProxyObject); _signalMatchRuleString(eventName: string): string; _getEventListener(signal: ProxySignalInfo): ProxyListener; static _fromXml(object: ProxyObject, xml: unknown): ProxyInterface | null; } type ClientInterface = ProxyInterface; //#endregion //#region src/client/proxy-object.d.ts type ObjectPath = string; /** * A class that represents a proxy to a DBus object. The `ProxyObject` contains * `ProxyInterface`s and a list of `node`s which are object paths of child * objects. A `ProxyObject` is created through {@link * MessageBus#getProxyObject} for a given well-known name and object path. * An interface can be gotten through {@link ProxyObject#getInterface} and can * be used to call methods and receive signals for that interface. */ declare class ProxyObject { bus: MessageBus; name: string; path: ObjectPath; nodes: ObjectPath[]; interfaces: Record; private readonly _parser; /** * Create a new `ProxyObject`. This constructor should not be called * directly. Use {@link MessageBus#getProxyObject} to get a proxy object. */ constructor(bus: MessageBus, name: string, path: string); /** * Get a {@link ProxyInterface} for the given interface name. * * @param name {string} - the interface name to get. * @throws {Error} Throws an error if the interface is not found on this object. */ getInterface(name: string): T; private _initXml; _init(xml?: string): Promise; _callMethod(iface: string, member: string, inSignature: string, outSignature: string, ...args: unknown[]): Promise; } //#endregion //#region src/stream-types.d.ts interface DBusStream extends Duplex { supportsUnixFd?: boolean; setNoDelay?(noDelay?: boolean): this; } //#endregion //#region src/handshake.d.ts type AuthMethod = 'EXTERNAL' | 'DBUS_COOKIE_SHA1' | 'ANONYMOUS'; interface HandshakeOptions { authMethods?: string[]; } //#endregion //#region src/connection.d.ts interface ConnectionOptions extends HandshakeOptions, DBusBufferOptions { busAddress?: string; negotiateUnixFd?: boolean; } interface SystemBusOptions { negotiateUnixFd?: boolean; } interface SessionBusOptions { authMethods?: AuthMethod[]; busAddress?: string; } interface DBusConnectionEvents { connect: []; message: [message: Message]; end: []; } declare class DBusConnection extends EventEmitter { stream?: DBusStream; guid?: string; state?: 'connected' | 'ended'; private readonly _messages; private readonly _opts; constructor(opts?: ConnectionOptions); private _wireStream; private _write; message(msg: RawMessage): void; end(): this; } //#endregion //#region src/bus.d.ts interface MessageBusEvents { connect: []; message: [message: Message]; } /** * @class * The `MessageBus` is a class for interacting with a DBus message bus capable * of requesting a service [`Name`]{@link module:interface~Name} to export an * [`Interface`]{@link module:interface~Interface}, or getting a proxy object * to interact with an existing name on the bus as a client. A `MessageBus` is * created with `dbus.sessionBus()` or `dbus.systemBus()` methods of the * dbus-next module. */ declare class MessageBus extends EventEmitter implements ServiceBus { name: string | null; /** * Create a new `MessageBus`. This constructor is not to be called directly. * Use `dbus.sessionBus()` or `dbus.systemBus()` to set up the connection to * the bus. */ constructor(conn: DBusConnection); /** * Get a {@link ProxyObject} on the bus for the given name and path for * interacting with a service as a client. */ getProxyObject(name: string, path: string, xml?: string): Promise; /** * Request a well-known name on the bus. */ requestName(name: string, flags?: number): Promise; /** * Release this name. Requests that the name should no longer be owned by the * {@link MessageBus}. */ releaseName(name: string): Promise; /** * Disconnect this `MessageBus` from the bus. */ disconnect(): void; /** * Get a new serial for this bus. */ newSerial(): number; addMethodHandler(fn: (msg: Message) => unknown): void; removeMethodHandler(fn: (msg: Message) => unknown): void; /** * Send a {@link Message} of type {@link MessageType.METHOD_CALL} to the bus * and wait for the reply. */ call(msg: Message): Promise; /** * Send a {@link Message} on the bus that does not expect a reply. */ send(msg: Message): void; /** * Export an [`Interface`]{@link module:interface~Interface} on the bus. */ export(path: string, iface: Interface): void; /** * Unexport an `Interface` on the bus. */ unexport(path: string, iface?: Interface | null): void; } //#endregion //#region src/library-options.d.ts declare const setBigIntCompat: (val: boolean) => void; //#endregion //#region src/constants.d.ts /** * @class * * A flag enum for {@link MessageBus#requestName} to configure the name request * options. * * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#bus-messages-request-name} */ declare class NameFlag { /** * This name allows other clients to replace it as the name owner on a request. * * @memberof NameFlag * @static * @constant */ static readonly ALLOW_REPLACEMENT = 1; /** * This request should replace an existing name if that name allows * replacement. * * @memberof NameFlag * @static * @constant */ static readonly REPLACE_EXISTING = 2; /** * This request should not enter the queue of clients requesting this name if * it is taken. * * @memberof NameFlag * @static * @constant */ static readonly DO_NOT_QUEUE = 4; } /** * @class * * An enum for the return value of {@link MessageBus#requestName} to indicate * the status of the name request. * * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#bus-messages-request-name} */ declare class RequestNameReply { /** * The application trying to request ownership of a name is already the owner * of it. * * @memberof RequestNameReply * @static * @constant */ static readonly PRIMARY_OWNER = 1; /** * The name already had an owner, `DBUS_NAME_FLAG_DO_NOT_QUEUE` was not * specified, and either the current owner did not specify * `DBUS_NAME_FLAG_ALLOW_REPLACEMENT` or the requesting application did not * specify `DBUS_NAME_FLAG_REPLACE_EXISTING`. * * @memberof RequestNameReply * @static * @constant */ static readonly IN_QUEUE = 2; /** * The name already has an owner, `DBUS_NAME_FLAG_DO_NOT_QUEUE` was specified, * and either `DBUS_NAME_FLAG_ALLOW_REPLACEMENT` was not specified by the * current owner, or `DBUS_NAME_FLAG_REPLACE_EXISTING` was not specified by the * requesting application. * * @memberof RequestNameReply * @static * @constant */ static readonly EXISTS = 3; /** * The application trying to request ownership of a name is already the owner * of it. * * @memberof RequestNameReply * @static * @constant */ static readonly ALREADY_OWNER = 4; } /** * @class * * An enum for the return value of {@link MessageBus#releaseName} to indicate * the status of the release name request. * * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#bus-messages-release-name} */ declare class ReleaseNameReply { /** * The caller has released his claim on the given name. Either the caller was * the primary owner of the name, and the name is now unused or taken by * somebody waiting in the queue for the name, or the caller was waiting in the * queue for the name and has now been removed from the queue. * * @memberof ReleaseNameReply * @static * @constant */ static readonly RELEASED = 1; /** * The given name does not exist on this bus. * * @memberof ReleaseNameReply * @static * @constant */ static readonly NON_EXISTENT = 2; /** * The caller was not the primary owner of this name, and was also not waiting * in the queue to own this name. * * @memberof ReleaseNameReply * @static * @constant */ static readonly NOT_OWNER = 3; } /** * @class * * An enum value for the {@link Message} `type` member to indicate the type of message. * * @see https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol */ declare class MessageType { /** * The message is a method call. * * @memberof MessageType * @static * @constant */ static readonly METHOD_CALL = 1; /** * The message is a method return to a previous call. * * @memberof MessageType * @static * @constant */ static readonly METHOD_RETURN = 2; /** * The message is an error reply. * * @memberof MessageType * @static * @constant */ static readonly ERROR = 3; /** * The message is a signal. * * @memberof MessageType * @static * @constant */ static readonly SIGNAL = 4; } /** * @class * * An flag enum for the {@link Message} `flags` member to configure behavior * for message processing. * * @see https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol */ declare class MessageFlag { /** * No reply is expected from this message. * * @memberof MessageFlag * @static * @constant */ static readonly NO_REPLY_EXPECTED = 1; /** * This message should not autostart a service. * * @memberof MessageFlag * @static * @constant */ static readonly NO_AUTO_START = 2; } //#endregion //#region src/errors.d.ts /** * An error that can be thrown from DBus [`Interface`]{@link * module:interface~Interface} [methods]{@link module:interface.method} and * [property]{@link module:interface.property} getters and setters to return * the error to the client. * * This class will also be thrown by {@link ProxyInterface} method calls when * the interface method returns an error to the method call. * * @param {string} type - The type of error. Must be a valid DBus member name. * @param {string} text - The error text. Will be seen by the client. */ declare class DBusError extends Error { type: string; text: string; reply: unknown; /** * Construct a new `DBusError` with the given type and text. */ constructor(type: string, text?: string, reply?: unknown); } //#endregion //#region src/guards.d.ts type Assert = (value: unknown) => asserts value is T; declare namespace validators_d_exports { export { assertBusNameValid, assertInterfaceNameValid, assertMemberNameValid, assertObjectPathValid, isBusNameValid, isInterfaceNameValid, isMemberNameValid, isObjectPathValid }; } /** * Validate the string as a valid bus name. * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus} * * @static * @param {string} name - The name to validate as a valid bus name. * @returns {boolean} - Whether the string is a valid bus name. */ declare const isBusNameValid: (name: unknown) => name is string; /** * Throws an error if the given string is not a valid bus name. * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus} * * @static * @param {string} name - The name to validate as a bus name. */ declare const assertBusNameValid: Assert; /** * Validate the string as a valid object path. * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path} * * @static * @param {string} path - The string to validate as an object path. * @returns {boolean} - Whether the string is a valid object path. */ declare const isObjectPathValid: (path: unknown) => path is string; /** * Throws an error if the given string is not a valid object path. * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path} * * @static * @param {string} path - The string to validate as an object path. * @returns {boolean} - Whether the string is a valid object path. */ declare const assertObjectPathValid: Assert; /** * Validate the string as a valid interface name. * see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface} * * @static * @param {string} name - The string to validate as an interface name. * @returns {boolean} - Whether the string is a valid interface name. */ declare const isInterfaceNameValid: (name: unknown) => name is string; /** * Throws an error if the given string is not a valid interface name. * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface} * * @static * @param {string} name - The string to validate as an interface name. */ declare const assertInterfaceNameValid: Assert; /** * Validate the string is a valid member name * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface} * * @static * @param {string} name - The string to validate as a member name. * @returns {boolean} - Whether the string is a valid member name. */ declare const isMemberNameValid: (name: unknown) => name is string; /** * Throws an error if the string is not a valid member name. * @see {@link https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface} * * @static * @param {string} name - The string to validate as a member name. */ declare const assertMemberNameValid: Assert; //#endregion //#region src/index.d.ts /** * Create a new {@link MessageBus} client on the DBus system bus to connect to * interfaces or request service names. Connects to the socket specified by the * `DBUS_SYSTEM_BUS_ADDRESS` environment variable or * `unix:path=/var/run/dbus/system_bus_socket`. */ declare const systemBus: (opts?: ConnectionOptions) => MessageBus; /** * Create a new {@link MessageBus} client on the DBus session bus to connect to * interfaces or request service names. */ declare const sessionBus: (opts?: ConnectionOptions) => MessageBus; declare const interfaceNs: { ACCESS_READ: PropertyAccess; ACCESS_WRITE: PropertyAccess; ACCESS_READWRITE: PropertyAccess; property: (options: PropertyOptions) => DualPropertyDecorator; method: (options?: MethodOptions) => DualMethodDecorator; signal: (options?: SignalOptions) => DualSignalDecorator; Interface: typeof Interface; }; //#endregion export { type AuthMethod, type ClientInterface, type ConnectionOptions, DBusError, type Interface, Message, MessageBus, MessageFlag, type MessageLike, MessageType, type MethodOptions, NameFlag, type ObjectPath, type PropertyAccess, type PropertyOptions, type ProxyInterface, type ProxyObject, ReleaseNameReply, RequestNameReply, type SessionBusOptions, type SignalOptions, type SystemBusOptions, Variant, interfaceNs as interface, sessionBus, setBigIntCompat, systemBus, validators_d_exports as validators }; //# sourceMappingURL=index.d.mts.map