@lakutata/dbus 2.3.1 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +253 -25
- package/dist/cjs/adapters/DBusEntrypoint.d.ts +89 -0
- package/dist/cjs/adapters/DBusEntrypoint.js +280 -0
- package/dist/cjs/channel/DBusChannel.d.ts +36 -0
- package/dist/cjs/channel/DBusChannel.js +70 -0
- package/dist/cjs/components/DBusClientComponent.d.ts +494 -0
- package/dist/cjs/components/DBusClientComponent.js +272 -0
- package/dist/cjs/components/DBusObjectManager.d.ts +164 -0
- package/dist/cjs/components/DBusObjectManager.js +200 -0
- package/dist/cjs/context/DBusContext.d.ts +52 -0
- package/dist/cjs/context/DBusContext.js +68 -0
- package/dist/cjs/decorators/DBusInterface.d.ts +74 -0
- package/dist/cjs/decorators/DBusInterface.js +63 -0
- package/dist/cjs/decorators/DBusMethod.d.ts +115 -0
- package/dist/cjs/decorators/DBusMethod.js +20 -0
- package/dist/cjs/exports/DBus.d.ts +11 -0
- package/dist/cjs/exports/DBus.js +42 -0
- package/dist/cjs/lib/DBusClientOptions.d.ts +30 -0
- package/dist/cjs/lib/Declarations.d.ts +187 -0
- package/dist/cjs/lib/Declarations.js +113 -0
- package/dist/cjs/lib/Names.d.ts +35 -0
- package/dist/cjs/lib/Names.js +80 -0
- package/dist/cjs/lib/Signature.d.ts +14 -0
- package/dist/cjs/lib/Signature.js +53 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/DBusContextParams.d.ts +22 -0
- package/dist/cjs/types/DBusContextParams.js +2 -0
- package/dist/esm/adapters/DBusEntrypoint.js +274 -0
- package/dist/esm/channel/DBusChannel.js +67 -0
- package/dist/esm/components/DBusClientComponent.js +267 -0
- package/dist/esm/components/DBusObjectManager.js +197 -0
- package/dist/esm/context/DBusContext.js +64 -0
- package/dist/esm/decorators/DBusInterface.js +60 -0
- package/dist/esm/decorators/DBusMethod.js +17 -0
- package/dist/esm/exports/DBus.js +12 -0
- package/dist/esm/lib/DBusClientOptions.js +1 -0
- package/dist/esm/lib/Declarations.js +107 -0
- package/dist/esm/lib/Names.js +73 -0
- package/dist/esm/lib/Signature.js +49 -0
- package/dist/esm/types/DBusContextParams.js +1 -0
- package/dist/types/adapters/DBusEntrypoint.d.ts +89 -0
- package/dist/types/channel/DBusChannel.d.ts +36 -0
- package/dist/types/components/DBusClientComponent.d.ts +494 -0
- package/dist/types/components/DBusObjectManager.d.ts +164 -0
- package/dist/types/context/DBusContext.d.ts +52 -0
- package/dist/types/decorators/DBusInterface.d.ts +74 -0
- package/dist/types/decorators/DBusMethod.d.ts +115 -0
- package/dist/types/exports/DBus.d.ts +11 -0
- package/dist/types/lib/DBusClientOptions.d.ts +30 -0
- package/dist/types/lib/Declarations.d.ts +187 -0
- package/dist/types/lib/Names.d.ts +35 -0
- package/dist/types/lib/Signature.d.ts +14 -0
- package/dist/types/types/DBusContextParams.d.ts +22 -0
- package/package.json +38 -39
- package/CHANGELOG.md +0 -153
- package/dist/CommonExports.d.ts +0 -2
- package/dist/CommonExports.d.ts.map +0 -1
- package/dist/CommonExports.js +0 -44
- package/dist/ComponentExports.d.ts +0 -2
- package/dist/ComponentExports.d.ts.map +0 -1
- package/dist/ComponentExports.js +0 -5
- package/dist/ProviderExports.d.ts +0 -2
- package/dist/ProviderExports.d.ts.map +0 -1
- package/dist/ProviderExports.js +0 -5
- package/dist/components/DBusClientComponent.d.ts +0 -75
- package/dist/components/DBusClientComponent.d.ts.map +0 -1
- package/dist/components/DBusClientComponent.js +0 -125
- package/dist/interfaces/DBusClientOptions.d.ts +0 -7
- package/dist/interfaces/DBusClientOptions.d.ts.map +0 -1
- package/dist/providers/DBusClientProvider.d.ts +0 -75
- package/dist/providers/DBusClientProvider.d.ts.map +0 -1
- package/dist/providers/DBusClientProvider.js +0 -125
- package/dist/tests/DBusTest.spec.d.ts +0 -2
- package/dist/tests/DBusTest.spec.d.ts.map +0 -1
- package/dist/tests/DBusTest.spec.js +0 -26
- package/dist/tests/Test.d.ts +0 -9
- package/dist/tests/Test.d.ts.map +0 -1
- package/dist/tests/Test.js +0 -80
- package/tsconfig.json +0 -7
- /package/dist/{interfaces → cjs/lib}/DBusClientOptions.js +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BaseContext } from '@lakutata/entrypoint';
|
|
2
|
+
import { type DBusContextParams } from '../types/DBusContextParams.js';
|
|
3
|
+
/**
|
|
4
|
+
* The `type` of every {@link DBusContext}: `'DBUS'`. A middleware or an access rule shared by several transports tells
|
|
5
|
+
* the D-Bus calls apart with it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DBUS_CONTEXT_TYPE: string;
|
|
8
|
+
/**
|
|
9
|
+
* The context of a D-Bus method call: `this.context` of a controller action declared with `@DBusMethod` when a client
|
|
10
|
+
* calls it through {@link dbusEntrypoint}. The adapter creates one per call; its `data` is the call's input (the entries
|
|
11
|
+
* of its `a{sv}` dictionary). The variables of the object path template are not in the context: they are merged into
|
|
12
|
+
* the action's input, as the route parameters of HTTP.
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import {Controller} from 'lakutata/com/entrypoint'
|
|
16
|
+
* import {DBusContext, DBusInterface, DBusMethod} from '@lakutata/dbus'
|
|
17
|
+
*
|
|
18
|
+
* @DBusInterface('com.example.Manager', {path: '/com/example/Manager'})
|
|
19
|
+
* class ManagerController extends Controller {
|
|
20
|
+
* //Returns "com.example.Manager.Ping at /com/example/Manager"
|
|
21
|
+
* @DBusMethod('Ping', {returns: 's'})
|
|
22
|
+
* public async ping(): Promise<string> {
|
|
23
|
+
* const context: DBusContext = this.context as DBusContext
|
|
24
|
+
* return `${context.interface}.${context.member} at ${context.path}`
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class DBusContext<T extends Record<string, any> = {}> extends BaseContext<T> {
|
|
30
|
+
/**
|
|
31
|
+
* Always {@link DBUS_CONTEXT_TYPE} (`'DBUS'`).
|
|
32
|
+
*/
|
|
33
|
+
readonly type: string;
|
|
34
|
+
/**
|
|
35
|
+
* The object path the client called (`'/com/example/Devices/A1'`).
|
|
36
|
+
*/
|
|
37
|
+
readonly path: string;
|
|
38
|
+
/**
|
|
39
|
+
* The name of the interface the client called (`'com.example.Device'`).
|
|
40
|
+
*/
|
|
41
|
+
readonly interface: string;
|
|
42
|
+
/**
|
|
43
|
+
* The name of the method the client called (`'Status'`).
|
|
44
|
+
*/
|
|
45
|
+
readonly member: string;
|
|
46
|
+
/**
|
|
47
|
+
* Create the context of a method call, validating its properties.
|
|
48
|
+
* @param params The object path, the interface, the method and the input of the call.
|
|
49
|
+
* @throws {InvalidValueException} When a property is missing or invalid.
|
|
50
|
+
*/
|
|
51
|
+
constructor(params: DBusContextParams);
|
|
52
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DBusContext = exports.DBUS_CONTEXT_TYPE = void 0;
|
|
13
|
+
const core_1 = require("@lakutata/core");
|
|
14
|
+
const dto_1 = require("@lakutata/core/decorator/dto");
|
|
15
|
+
const entrypoint_1 = require("@lakutata/entrypoint");
|
|
16
|
+
/**
|
|
17
|
+
* The `type` of every {@link DBusContext}: `'DBUS'`. A middleware or an access rule shared by several transports tells
|
|
18
|
+
* the D-Bus calls apart with it.
|
|
19
|
+
*/
|
|
20
|
+
exports.DBUS_CONTEXT_TYPE = 'DBUS';
|
|
21
|
+
/**
|
|
22
|
+
* The context of a D-Bus method call: `this.context` of a controller action declared with `@DBusMethod` when a client
|
|
23
|
+
* calls it through {@link dbusEntrypoint}. The adapter creates one per call; its `data` is the call's input (the entries
|
|
24
|
+
* of its `a{sv}` dictionary). The variables of the object path template are not in the context: they are merged into
|
|
25
|
+
* the action's input, as the route parameters of HTTP.
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import {Controller} from 'lakutata/com/entrypoint'
|
|
29
|
+
* import {DBusContext, DBusInterface, DBusMethod} from '@lakutata/dbus'
|
|
30
|
+
*
|
|
31
|
+
* @DBusInterface('com.example.Manager', {path: '/com/example/Manager'})
|
|
32
|
+
* class ManagerController extends Controller {
|
|
33
|
+
* //Returns "com.example.Manager.Ping at /com/example/Manager"
|
|
34
|
+
* @DBusMethod('Ping', {returns: 's'})
|
|
35
|
+
* public async ping(): Promise<string> {
|
|
36
|
+
* const context: DBusContext = this.context as DBusContext
|
|
37
|
+
* return `${context.interface}.${context.member} at ${context.path}`
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
class DBusContext extends entrypoint_1.BaseContext {
|
|
43
|
+
/**
|
|
44
|
+
* Create the context of a method call, validating its properties.
|
|
45
|
+
* @param params The object path, the interface, the method and the input of the call.
|
|
46
|
+
* @throws {InvalidValueException} When a property is missing or invalid.
|
|
47
|
+
*/
|
|
48
|
+
constructor(params) {
|
|
49
|
+
super(params);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.DBusContext = DBusContext;
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, dto_1.Expect)(core_1.DTO.String().valid(exports.DBUS_CONTEXT_TYPE).default(exports.DBUS_CONTEXT_TYPE)),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], DBusContext.prototype, "type", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, dto_1.Expect)(core_1.DTO.String().required()),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], DBusContext.prototype, "path", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, dto_1.Expect)(core_1.DTO.String().required()),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], DBusContext.prototype, "interface", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, dto_1.Expect)(core_1.DTO.String().required()),
|
|
67
|
+
__metadata("design:type", String)
|
|
68
|
+
], DBusContext.prototype, "member", void 0);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Controller } from '@lakutata/entrypoint';
|
|
2
|
+
import { type DBusPropertyDefinition, type DBusSignalDefinition } from '../lib/Declarations.js';
|
|
3
|
+
/**
|
|
4
|
+
* The options of {@link DBusInterface}: where the interface is served, and its signals and properties.
|
|
5
|
+
*/
|
|
6
|
+
export type DBusInterfaceOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The object path of the interface. A path without variables (`'/com/example/Manager'`) is one object, exported
|
|
9
|
+
* while the adapter runs ({@link DBusObjectManager.removeObject} does not remove it). A template (`'/com/example/Devices/{sn}'`) serves the objects added with
|
|
10
|
+
* {@link DBusObjectManager.addObject} whose path matches it; its variables are merged into the input of the methods,
|
|
11
|
+
* as route parameters (they take precedence over the client's input). Its elements are letters, digits and `_`, or
|
|
12
|
+
* variables in braces; a variable matches one element.
|
|
13
|
+
*/
|
|
14
|
+
path: string;
|
|
15
|
+
/**
|
|
16
|
+
* The signals of the interface, declared with {@link defineDBusSignal} and emitted with
|
|
17
|
+
* {@link DBusObjectManager.emitSignal}.
|
|
18
|
+
* @default []
|
|
19
|
+
*/
|
|
20
|
+
signals?: DBusSignalDefinition<any>[];
|
|
21
|
+
/**
|
|
22
|
+
* The properties of the interface, declared with {@link defineDBusProperty} and set with
|
|
23
|
+
* {@link DBusObjectManager.setPropertyValue}.
|
|
24
|
+
* @default []
|
|
25
|
+
*/
|
|
26
|
+
properties?: DBusPropertyDefinition<any>[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Serve a controller as a D-Bus interface: its `@DBusMethod` actions are the interface's methods, and the signals and
|
|
30
|
+
* properties of the options are its other members, on the objects at `options.path`. The controllers declaring the same
|
|
31
|
+
* path are served by the same objects, each one interface; a subclass inherits the declaration of its parent class.
|
|
32
|
+
* The objects also implement `org.freedesktop.DBus.Properties`, `Introspectable` and `Peer`, and the root object `/`
|
|
33
|
+
* implements `ObjectManager`. Nothing is served until a {@link dbusEntrypoint} runs.
|
|
34
|
+
* @param name The name of the interface (`'com.example.Device'`): two or more elements separated by dots, made of
|
|
35
|
+
* letters, digits and `_`, not starting with a digit; 255 characters at most.
|
|
36
|
+
* @param options The object path (or template) of the interface, its signals and its properties.
|
|
37
|
+
* @returns The class decorator.
|
|
38
|
+
* @throws {TypeError} When the class is declared, if the name of the interface or the path is invalid.
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import {DTO} from 'lakutata'
|
|
42
|
+
* import {Controller} from 'lakutata/com/entrypoint'
|
|
43
|
+
* import {Expect, Return} from 'lakutata/decorator/dto'
|
|
44
|
+
* import {DBusInterface, DBusMethod, defineDBusProperty, defineDBusSignal} from '@lakutata/dbus'
|
|
45
|
+
*
|
|
46
|
+
* class DeviceSnDTO extends DTO {
|
|
47
|
+
* @Expect(DTO.String().required())
|
|
48
|
+
* public sn: string
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* class StatusDTO extends DTO {
|
|
52
|
+
* @Expect(DTO.String().required())
|
|
53
|
+
* public sn: string
|
|
54
|
+
*
|
|
55
|
+
* @Expect(DTO.Boolean().required())
|
|
56
|
+
* public online: boolean
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* export const DeviceChanged = defineDBusSignal('Changed', StatusDTO)
|
|
60
|
+
* export const DeviceState = defineDBusProperty<string>('State', 's', {initial: 'idle'})
|
|
61
|
+
*
|
|
62
|
+
* //Served by the objects /com/example/Devices/A1, /com/example/Devices/B2… added with DBusObjectManager
|
|
63
|
+
* @DBusInterface('com.example.Device', {path: '/com/example/Devices/{sn}', signals: [DeviceChanged], properties: [DeviceState]})
|
|
64
|
+
* export class DeviceController extends Controller {
|
|
65
|
+
* //The sn of the input is the one of the object path
|
|
66
|
+
* @DBusMethod('Status', DeviceSnDTO)
|
|
67
|
+
* @Return(StatusDTO)
|
|
68
|
+
* public async status(input: DeviceSnDTO): Promise<StatusDTO> {
|
|
69
|
+
* return {sn: input.sn, online: true} as StatusDTO
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function DBusInterface<ClassConstructor extends typeof Controller>(name: string, options: DBusInterfaceOptions): (target: ClassConstructor) => void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DBusInterface = DBusInterface;
|
|
4
|
+
const channel_1 = require("@lakutata/entrypoint/channel");
|
|
5
|
+
const Declarations_js_1 = require("../lib/Declarations.js");
|
|
6
|
+
/**
|
|
7
|
+
* Serve a controller as a D-Bus interface: its `@DBusMethod` actions are the interface's methods, and the signals and
|
|
8
|
+
* properties of the options are its other members, on the objects at `options.path`. The controllers declaring the same
|
|
9
|
+
* path are served by the same objects, each one interface; a subclass inherits the declaration of its parent class.
|
|
10
|
+
* The objects also implement `org.freedesktop.DBus.Properties`, `Introspectable` and `Peer`, and the root object `/`
|
|
11
|
+
* implements `ObjectManager`. Nothing is served until a {@link dbusEntrypoint} runs.
|
|
12
|
+
* @param name The name of the interface (`'com.example.Device'`): two or more elements separated by dots, made of
|
|
13
|
+
* letters, digits and `_`, not starting with a digit; 255 characters at most.
|
|
14
|
+
* @param options The object path (or template) of the interface, its signals and its properties.
|
|
15
|
+
* @returns The class decorator.
|
|
16
|
+
* @throws {TypeError} When the class is declared, if the name of the interface or the path is invalid.
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import {DTO} from 'lakutata'
|
|
20
|
+
* import {Controller} from 'lakutata/com/entrypoint'
|
|
21
|
+
* import {Expect, Return} from 'lakutata/decorator/dto'
|
|
22
|
+
* import {DBusInterface, DBusMethod, defineDBusProperty, defineDBusSignal} from '@lakutata/dbus'
|
|
23
|
+
*
|
|
24
|
+
* class DeviceSnDTO extends DTO {
|
|
25
|
+
* @Expect(DTO.String().required())
|
|
26
|
+
* public sn: string
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* class StatusDTO extends DTO {
|
|
30
|
+
* @Expect(DTO.String().required())
|
|
31
|
+
* public sn: string
|
|
32
|
+
*
|
|
33
|
+
* @Expect(DTO.Boolean().required())
|
|
34
|
+
* public online: boolean
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* export const DeviceChanged = defineDBusSignal('Changed', StatusDTO)
|
|
38
|
+
* export const DeviceState = defineDBusProperty<string>('State', 's', {initial: 'idle'})
|
|
39
|
+
*
|
|
40
|
+
* //Served by the objects /com/example/Devices/A1, /com/example/Devices/B2… added with DBusObjectManager
|
|
41
|
+
* @DBusInterface('com.example.Device', {path: '/com/example/Devices/{sn}', signals: [DeviceChanged], properties: [DeviceState]})
|
|
42
|
+
* export class DeviceController extends Controller {
|
|
43
|
+
* //The sn of the input is the one of the object path
|
|
44
|
+
* @DBusMethod('Status', DeviceSnDTO)
|
|
45
|
+
* @Return(StatusDTO)
|
|
46
|
+
* public async status(input: DeviceSnDTO): Promise<StatusDTO> {
|
|
47
|
+
* return {sn: input.sn, online: true} as StatusDTO
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
function DBusInterface(name, options) {
|
|
53
|
+
return (target) => {
|
|
54
|
+
(0, Declarations_js_1.setDBusInterfaceDeclaration)(target, {
|
|
55
|
+
interface: name,
|
|
56
|
+
path: options.path,
|
|
57
|
+
signals: options.signals ?? [],
|
|
58
|
+
properties: options.properties ?? []
|
|
59
|
+
});
|
|
60
|
+
//The methods of the controller are addressed at its interface and its path
|
|
61
|
+
(0, channel_1.setPrefix)(target, { dbus: { path: options.path, interface: name } });
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { DTO, MethodDecorator } from '@lakutata/core';
|
|
2
|
+
import type { Controller } from '@lakutata/entrypoint';
|
|
3
|
+
import { ActionOptions } from '@lakutata/entrypoint/channel';
|
|
4
|
+
import type { DBusContext } from '../context/DBusContext.js';
|
|
5
|
+
/**
|
|
6
|
+
* The options of {@link DBusMethod}: the options of a controller action (`name`, `description`, `acl`, `rule`,
|
|
7
|
+
* `groups`, `middlewares`), with the D-Bus type of the method's result.
|
|
8
|
+
*/
|
|
9
|
+
export type DBusMethodOptions = ActionOptions<DBusContext> & {
|
|
10
|
+
/**
|
|
11
|
+
* The type of the method's result: a DTO (a dictionary of variants, `a{sv}`) or a D-Bus signature (`'s'`, `'b'`,
|
|
12
|
+
* `'x'`, `'v'`…). Without it, the type comes from the method's `@Return` schema: an object is `a{sv}`, a string
|
|
13
|
+
* `s`, a boolean `b`, an integer or a bigint `x`, another number `d`, an array `av`, any other value a variant `v`.
|
|
14
|
+
* @default the type of the `@Return` schema; without `@Return`, the method has no result
|
|
15
|
+
*/
|
|
16
|
+
returns?: typeof DTO | string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Serve a controller action as a method of the D-Bus interface its controller declares with `@DBusInterface`. A method
|
|
20
|
+
* with a DTO takes one argument, a dictionary of variants (`a{sv}`) holding the DTO's properties; a method without one
|
|
21
|
+
* takes no argument. The input goes through the entrypoint's middlewares, the DTO validation and the access control,
|
|
22
|
+
* as in the other channels, and the variables of the object path template are merged into it.
|
|
23
|
+
*
|
|
24
|
+
* The result is encoded with the type of `returns` or of `@Return` (the dates as ISO strings, the `null` and
|
|
25
|
+
* `undefined` values left out, since a variant has no null); a method with neither returns nothing. An error thrown by
|
|
26
|
+
* the action is answered as a D-Bus error named after its `errno` (or its name), prefixed by the service name
|
|
27
|
+
* (`com.example.DeviceService.E_OFFLINE`), with its message; an `errno` already containing dots is used as it is.
|
|
28
|
+
* The same method may also carry the decorators of the other channels (`@ServiceAction`, `@GET`…).
|
|
29
|
+
* @param name The name of the method (`'Reboot'`): letters, digits and `_`, not starting with a digit; 255 characters at
|
|
30
|
+
* most. Unique in its interface.
|
|
31
|
+
* @returns The method decorator.
|
|
32
|
+
* @throws {TypeError} When the method is declared, if its name is invalid; when the adapter starts, if its controller
|
|
33
|
+
* has no `@DBusInterface`.
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import {DTO} from 'lakutata'
|
|
37
|
+
* import {Controller} from 'lakutata/com/entrypoint'
|
|
38
|
+
* import {Expect, Return} from 'lakutata/decorator/dto'
|
|
39
|
+
* import {DBusInterface, DBusMethod} from '@lakutata/dbus'
|
|
40
|
+
*
|
|
41
|
+
* class ConfigureDTO extends DTO {
|
|
42
|
+
* @Expect(DTO.String().required())
|
|
43
|
+
* public sn: string
|
|
44
|
+
*
|
|
45
|
+
* @Expect(DTO.Number().integer().min(0).optional())
|
|
46
|
+
* public retries?: number
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* @DBusInterface('com.example.Manager', {path: '/com/example/Manager'})
|
|
50
|
+
* export class ManagerController extends Controller {
|
|
51
|
+
* //No argument, returns a string (s)
|
|
52
|
+
* @DBusMethod('Ping', {returns: 's'})
|
|
53
|
+
* public async ping(): Promise<string> {
|
|
54
|
+
* return 'pong'
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* //One argument a{sv}, returns a dictionary a{sv} (the type of @Return)
|
|
58
|
+
* @DBusMethod('Configure', ConfigureDTO, {description: 'Configure a device'})
|
|
59
|
+
* @Return(ConfigureDTO)
|
|
60
|
+
* public async configure(input: ConfigureDTO): Promise<ConfigureDTO> {
|
|
61
|
+
* return input
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* //No result
|
|
65
|
+
* @DBusMethod('Reset')
|
|
66
|
+
* public async reset(): Promise<void> {
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function DBusMethod<ClassPrototype extends Controller, Method>(name: string): MethodDecorator<ClassPrototype, Method, any>;
|
|
72
|
+
/**
|
|
73
|
+
* Serve a controller action as a method of the D-Bus interface its controller declares with `@DBusInterface`: its input
|
|
74
|
+
* is the DTO, given by the client as one dictionary of variants (`a{sv}`); its result has the type of `@Return`.
|
|
75
|
+
* The input goes through the entrypoint's middlewares, the DTO validation and the access control, and the variables
|
|
76
|
+
* of the object path template are merged into it. An error thrown by the action is answered as a D-Bus error named
|
|
77
|
+
* after its `errno`, prefixed by the service name (`com.example.DeviceService.E_OFFLINE`).
|
|
78
|
+
* @param name The name of the method (`'Reboot'`): letters, digits and `_`, not starting with a digit; 255 characters at
|
|
79
|
+
* most. Unique in its interface.
|
|
80
|
+
* @param dtoConstructor The DTO of the method's input, given by the client as an `a{sv}` dictionary.
|
|
81
|
+
* @returns The method decorator.
|
|
82
|
+
* @throws {TypeError} When the method is declared, if its name is invalid; when the adapter starts, if its controller
|
|
83
|
+
* has no `@DBusInterface`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function DBusMethod<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(name: string, dtoConstructor: DTOConstructor): MethodDecorator<ClassPrototype, Method, any>;
|
|
86
|
+
/**
|
|
87
|
+
* Serve a controller action as a method of the D-Bus interface its controller declares with `@DBusInterface`, with
|
|
88
|
+
* action options: it takes no argument; its result has the type of `returns` or of `@Return`.
|
|
89
|
+
* The input goes through the entrypoint's middlewares, the DTO validation and the access control, and the variables
|
|
90
|
+
* of the object path template are merged into it. An error thrown by the action is answered as a D-Bus error named
|
|
91
|
+
* after its `errno`, prefixed by the service name (`com.example.DeviceService.E_OFFLINE`).
|
|
92
|
+
* @param name The name of the method (`'Reboot'`): letters, digits and `_`, not starting with a digit; 255 characters at
|
|
93
|
+
* most. Unique in its interface.
|
|
94
|
+
* @param options The options of the action, and the type of its result (`returns`).
|
|
95
|
+
* @returns The method decorator.
|
|
96
|
+
* @throws {TypeError} When the method is declared, if its name is invalid; when the adapter starts, if its controller
|
|
97
|
+
* has no `@DBusInterface`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function DBusMethod<ClassPrototype extends Controller, Method>(name: string, options: DBusMethodOptions): MethodDecorator<ClassPrototype, Method, any>;
|
|
100
|
+
/**
|
|
101
|
+
* Serve a controller action as a method of the D-Bus interface its controller declares with `@DBusInterface`, with
|
|
102
|
+
* action options: its input is the DTO, given by the client as one dictionary of variants (`a{sv}`); its result has the
|
|
103
|
+
* type of `returns` or of `@Return`.
|
|
104
|
+
* The input goes through the entrypoint's middlewares, the DTO validation and the access control, and the variables
|
|
105
|
+
* of the object path template are merged into it. An error thrown by the action is answered as a D-Bus error named
|
|
106
|
+
* after its `errno`, prefixed by the service name (`com.example.DeviceService.E_OFFLINE`).
|
|
107
|
+
* @param name The name of the method (`'Reboot'`): letters, digits and `_`, not starting with a digit; 255 characters at
|
|
108
|
+
* most. Unique in its interface.
|
|
109
|
+
* @param dtoConstructor The DTO of the method's input, given by the client as an `a{sv}` dictionary.
|
|
110
|
+
* @param options The options of the action, and the type of its result (`returns`).
|
|
111
|
+
* @returns The method decorator.
|
|
112
|
+
* @throws {TypeError} When the method is declared, if its name is invalid; when the adapter starts, if its controller
|
|
113
|
+
* has no `@DBusInterface`.
|
|
114
|
+
*/
|
|
115
|
+
export declare function DBusMethod<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(name: string, dtoConstructor: DTOConstructor, options: DBusMethodOptions): MethodDecorator<ClassPrototype, Method, any>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DBusMethod = DBusMethod;
|
|
4
|
+
const channel_1 = require("@lakutata/entrypoint/channel");
|
|
5
|
+
const DBusChannel_js_1 = require("../channel/DBusChannel.js");
|
|
6
|
+
const Signature_js_1 = require("../lib/Signature.js");
|
|
7
|
+
function DBusMethod(name, dtoConstructorOrOptions, options) {
|
|
8
|
+
return (target, propertyKey, descriptor) => {
|
|
9
|
+
const isDTO = typeof dtoConstructorOrOptions === 'function';
|
|
10
|
+
const { returns, ...actionOptions } = (isDTO ? options : dtoConstructorOrOptions) ?? {};
|
|
11
|
+
const [dtoConstructor, validatedOptions] = isDTO
|
|
12
|
+
? (0, channel_1.getActionDTOAndOptions)(dtoConstructorOrOptions, actionOptions)
|
|
13
|
+
: (0, channel_1.getActionDTOAndOptions)(actionOptions);
|
|
14
|
+
const pattern = { member: name };
|
|
15
|
+
if (returns !== undefined)
|
|
16
|
+
pattern.returns = typeof returns === 'string' ? returns : (0, Signature_js_1.schemaSignature)(returns);
|
|
17
|
+
(0, channel_1.registerControllerAction)(DBusChannel_js_1.DBusChannel, target, propertyKey, pattern, dtoConstructor, validatedOptions);
|
|
18
|
+
return descriptor;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { DBusChannel } from '../channel/DBusChannel.js';
|
|
2
|
+
export { DBusContext, DBUS_CONTEXT_TYPE } from '../context/DBusContext.js';
|
|
3
|
+
export { type DBusContextParams } from '../types/DBusContextParams.js';
|
|
4
|
+
export { DBusInterface, type DBusInterfaceOptions } from '../decorators/DBusInterface.js';
|
|
5
|
+
export { DBusMethod, type DBusMethodOptions } from '../decorators/DBusMethod.js';
|
|
6
|
+
export { defineDBusSignal, defineDBusProperty, type DBusSignalDefinition, type DBusPropertyDefinition, type DBusPropertyOptions, type DBusInterfaceDeclaration } from '../lib/Declarations.js';
|
|
7
|
+
export { dbusEntrypoint, type DBusEntrypointOptions } from '../adapters/DBusEntrypoint.js';
|
|
8
|
+
export { DBusObjectManager, type DBusPropertyWrite } from '../components/DBusObjectManager.js';
|
|
9
|
+
export { DBusClientComponent, buildDBusClientOptions } from '../components/DBusClientComponent.js';
|
|
10
|
+
export type { DBusClientOptions } from '../lib/DBusClientOptions.js';
|
|
11
|
+
export { DBus, DBusInterface as DBusRemoteInterface, DBusObject, DBusService, LocalInterface, LocalObject, LocalService, createDBusError, DBusSignedValue, DBusSignalEmitter, Signature, RequestNameFlags, RequestNameResultCode, type BusNameBasicInfo, type ConnectOpts, type DecodeOpts, type InvokeOpts } from 'dbus-sdk';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestNameResultCode = exports.RequestNameFlags = exports.Signature = exports.DBusSignalEmitter = exports.DBusSignedValue = exports.createDBusError = exports.LocalService = exports.LocalObject = exports.LocalInterface = exports.DBusService = exports.DBusObject = exports.DBusRemoteInterface = exports.DBus = exports.buildDBusClientOptions = exports.DBusClientComponent = exports.DBusObjectManager = exports.dbusEntrypoint = exports.defineDBusProperty = exports.defineDBusSignal = exports.DBusMethod = exports.DBusInterface = exports.DBUS_CONTEXT_TYPE = exports.DBusContext = exports.DBusChannel = void 0;
|
|
4
|
+
//The DBus channel: the controllers served as the interfaces of the DBus objects
|
|
5
|
+
var DBusChannel_js_1 = require("../channel/DBusChannel.js");
|
|
6
|
+
Object.defineProperty(exports, "DBusChannel", { enumerable: true, get: function () { return DBusChannel_js_1.DBusChannel; } });
|
|
7
|
+
var DBusContext_js_1 = require("../context/DBusContext.js");
|
|
8
|
+
Object.defineProperty(exports, "DBusContext", { enumerable: true, get: function () { return DBusContext_js_1.DBusContext; } });
|
|
9
|
+
Object.defineProperty(exports, "DBUS_CONTEXT_TYPE", { enumerable: true, get: function () { return DBusContext_js_1.DBUS_CONTEXT_TYPE; } });
|
|
10
|
+
var DBusInterface_js_1 = require("../decorators/DBusInterface.js");
|
|
11
|
+
Object.defineProperty(exports, "DBusInterface", { enumerable: true, get: function () { return DBusInterface_js_1.DBusInterface; } });
|
|
12
|
+
var DBusMethod_js_1 = require("../decorators/DBusMethod.js");
|
|
13
|
+
Object.defineProperty(exports, "DBusMethod", { enumerable: true, get: function () { return DBusMethod_js_1.DBusMethod; } });
|
|
14
|
+
var Declarations_js_1 = require("../lib/Declarations.js");
|
|
15
|
+
Object.defineProperty(exports, "defineDBusSignal", { enumerable: true, get: function () { return Declarations_js_1.defineDBusSignal; } });
|
|
16
|
+
Object.defineProperty(exports, "defineDBusProperty", { enumerable: true, get: function () { return Declarations_js_1.defineDBusProperty; } });
|
|
17
|
+
var DBusEntrypoint_js_1 = require("../adapters/DBusEntrypoint.js");
|
|
18
|
+
Object.defineProperty(exports, "dbusEntrypoint", { enumerable: true, get: function () { return DBusEntrypoint_js_1.dbusEntrypoint; } });
|
|
19
|
+
var DBusObjectManager_js_1 = require("../components/DBusObjectManager.js");
|
|
20
|
+
Object.defineProperty(exports, "DBusObjectManager", { enumerable: true, get: function () { return DBusObjectManager_js_1.DBusObjectManager; } });
|
|
21
|
+
//The DBus client
|
|
22
|
+
var DBusClientComponent_js_1 = require("../components/DBusClientComponent.js");
|
|
23
|
+
Object.defineProperty(exports, "DBusClientComponent", { enumerable: true, get: function () { return DBusClientComponent_js_1.DBusClientComponent; } });
|
|
24
|
+
Object.defineProperty(exports, "buildDBusClientOptions", { enumerable: true, get: function () { return DBusClientComponent_js_1.buildDBusClientOptions; } });
|
|
25
|
+
//The DBus SDK
|
|
26
|
+
var dbus_sdk_1 = require("dbus-sdk");
|
|
27
|
+
Object.defineProperty(exports, "DBus", { enumerable: true, get: function () { return dbus_sdk_1.DBus; } });
|
|
28
|
+
Object.defineProperty(exports, "DBusRemoteInterface", { enumerable: true, get: function () { return dbus_sdk_1.DBusInterface; } });
|
|
29
|
+
Object.defineProperty(exports, "DBusObject", { enumerable: true, get: function () { return dbus_sdk_1.DBusObject; } });
|
|
30
|
+
Object.defineProperty(exports, "DBusService", { enumerable: true, get: function () { return dbus_sdk_1.DBusService; } });
|
|
31
|
+
Object.defineProperty(exports, "LocalInterface", { enumerable: true, get: function () { return dbus_sdk_1.LocalInterface; } });
|
|
32
|
+
Object.defineProperty(exports, "LocalObject", { enumerable: true, get: function () { return dbus_sdk_1.LocalObject; } });
|
|
33
|
+
Object.defineProperty(exports, "LocalService", { enumerable: true, get: function () { return dbus_sdk_1.LocalService; } });
|
|
34
|
+
Object.defineProperty(exports, "createDBusError", { enumerable: true, get: function () { return dbus_sdk_1.createDBusError; } });
|
|
35
|
+
Object.defineProperty(exports, "DBusSignedValue", { enumerable: true, get: function () { return dbus_sdk_1.DBusSignedValue; } });
|
|
36
|
+
Object.defineProperty(exports, "DBusSignalEmitter", { enumerable: true, get: function () { return dbus_sdk_1.DBusSignalEmitter; } });
|
|
37
|
+
Object.defineProperty(exports, "Signature", { enumerable: true, get: function () { return dbus_sdk_1.Signature; } });
|
|
38
|
+
Object.defineProperty(exports, "RequestNameFlags", { enumerable: true, get: function () { return dbus_sdk_1.RequestNameFlags; } });
|
|
39
|
+
Object.defineProperty(exports, "RequestNameResultCode", { enumerable: true, get: function () { return dbus_sdk_1.RequestNameResultCode; } });
|
|
40
|
+
|
|
41
|
+
//The default of the entry: the entry itself (scripts/package-build/cjs-package.mjs)
|
|
42
|
+
if (!Object.prototype.hasOwnProperty.call(exports, 'default')) Object.defineProperty(exports, 'default', {value: exports})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DecodeOpts } from 'dbus-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* The options of {@link buildDBusClientOptions}: the bus a {@link DBusClientComponent} connects to, and how it decodes
|
|
4
|
+
* the replies.
|
|
5
|
+
*/
|
|
6
|
+
export interface DBusClientOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The address of the bus: `'unix:path=/var/run/dbus/system_bus_socket'` (the system bus),
|
|
9
|
+
* `'unix:path=/run/user/1000/bus'`, `'tcp:host=127.0.0.1,port=5555'`; the value of `DBUS_SESSION_BUS_ADDRESS` for
|
|
10
|
+
* the session bus.
|
|
11
|
+
*/
|
|
12
|
+
busAddress: string;
|
|
13
|
+
/**
|
|
14
|
+
* How long the connection to the bus may take, in milliseconds (a positive integer).
|
|
15
|
+
* @default 20000
|
|
16
|
+
*/
|
|
17
|
+
timeout?: number;
|
|
18
|
+
/**
|
|
19
|
+
* How long a call may wait for its reply, in milliseconds (a positive integer); a call's own `timeout` overrides it.
|
|
20
|
+
* @default dbus-sdk's default
|
|
21
|
+
*/
|
|
22
|
+
callTimeout?: number;
|
|
23
|
+
/**
|
|
24
|
+
* How the replies and the signals are decoded (`DecodeOpts` of `dbus-sdk`): `types` (`'none'`, `'variants'`,
|
|
25
|
+
* `'all'`: where the values keep their D-Bus types as typed values), `dictionaries` (`'object'` or `'map'`),
|
|
26
|
+
* `int64` (`'number'` or `'bigint'`).
|
|
27
|
+
* @default {int64: 'number'} (the 64-bit integers as numbers when they are safe integers, else bigints)
|
|
28
|
+
*/
|
|
29
|
+
decode?: DecodeOpts;
|
|
30
|
+
}
|