@kronos-integration/service 10.4.55 → 10.4.57
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/README.md +12 -8
- package/package.json +25 -17
- package/src/endpoints-mixin.mjs +7 -2
- package/src/initialization-context.mjs +6 -6
- package/src/service-config.mjs +1 -1
- package/src/service-provider-mixin.mjs +5 -5
- package/src/service.mjs +3 -0
- package/types/endpoints-mixin.d.mts +7 -0
- package/types/initialization-context.d.mts +4 -0
- package/types/module.d.mts +8 -0
- package/types/service-config.d.mts +40 -0
- package/types/service-consumer-mixin.d.mts +8 -0
- package/types/service-logger.d.mts +7 -0
- package/types/service-provider-mixin.d.mts +83 -0
- package/types/service.d.mts +152 -0
- package/types/standalone-service-provider.d.mts +38 -0
- package/types/util.d.mts +1 -0
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/@kronos-integration/service)
|
|
2
2
|
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
3
|
+
[](https://typescriptlang.org)
|
|
3
4
|
[](https://bundlejs.com/?q=@kronos-integration/service)
|
|
4
5
|
[](https://npmjs.org/package/@kronos-integration/service)
|
|
5
6
|
[](https://github.com/Kronos-Integration/service/issues)
|
|
@@ -46,6 +47,7 @@ Base service implementation
|
|
|
46
47
|
* [Parameters](#parameters-7)
|
|
47
48
|
* [Service](#service)
|
|
48
49
|
* [Parameters](#parameters-8)
|
|
50
|
+
* [Properties](#properties-1)
|
|
49
51
|
* [extendetName](#extendetname)
|
|
50
52
|
* [stateChanged](#statechanged)
|
|
51
53
|
* [Parameters](#parameters-9)
|
|
@@ -82,9 +84,7 @@ Manages endpoints in a container.
|
|
|
82
84
|
|
|
83
85
|
### Parameters
|
|
84
86
|
|
|
85
|
-
* `superclass`
|
|
86
|
-
|
|
87
|
-
Returns **Class** extended class
|
|
87
|
+
* `superclass`  
|
|
88
88
|
|
|
89
89
|
## endpoints
|
|
90
90
|
|
|
@@ -97,8 +97,8 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
|
|
|
97
97
|
**Extends Service**
|
|
98
98
|
|
|
99
99
|
Config providing service.
|
|
100
|
-
Dispatches config requests to services
|
|
101
|
-
|
|
100
|
+
Dispatches config requests to services.
|
|
101
|
+
Also preserves them until a maching service becomes avaliable.
|
|
102
102
|
|
|
103
103
|
### Properties
|
|
104
104
|
|
|
@@ -111,7 +111,7 @@ Deliver configuration for a given service.
|
|
|
111
111
|
#### Parameters
|
|
112
112
|
|
|
113
113
|
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** service name
|
|
114
|
-
* `config` **[
|
|
114
|
+
* `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
115
115
|
|
|
116
116
|
### clearPreserved
|
|
117
117
|
|
|
@@ -200,8 +200,8 @@ By default a service provider has two build in services
|
|
|
200
200
|
### Parameters
|
|
201
201
|
|
|
202
202
|
* `superclass`  
|
|
203
|
-
* `serviceLoggerClass`
|
|
204
|
-
* `serviceConfigClass`
|
|
203
|
+
* `serviceLoggerClass` (optional, default `ServiceLogger`)
|
|
204
|
+
* `serviceConfigClass` (optional, default `ServiceConfig`)
|
|
205
205
|
|
|
206
206
|
## Service
|
|
207
207
|
|
|
@@ -243,6 +243,10 @@ All services have at least three endpoints:
|
|
|
243
243
|
* `config.endpoints` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** will be merged with the build in ones
|
|
244
244
|
* `ic` **InitializationContext** 
|
|
245
245
|
|
|
246
|
+
### Properties
|
|
247
|
+
|
|
248
|
+
* `endpoints` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
249
|
+
|
|
246
250
|
### extendetName
|
|
247
251
|
|
|
248
252
|
Used in human readable state messages.
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/service",
|
|
3
|
-
"version": "10.4.
|
|
3
|
+
"version": "10.4.57",
|
|
4
4
|
"publishConfig": {
|
|
5
|
-
"access": "public"
|
|
5
|
+
"access": "public",
|
|
6
|
+
"provenance": true
|
|
6
7
|
},
|
|
7
8
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
+
".": {
|
|
10
|
+
"default": "./src/module.mjs"
|
|
11
|
+
}
|
|
9
12
|
},
|
|
10
13
|
"description": "Base service implementation",
|
|
11
14
|
"contributors": [
|
|
@@ -20,33 +23,37 @@
|
|
|
20
23
|
],
|
|
21
24
|
"license": "BSD-2-Clause",
|
|
22
25
|
"scripts": {
|
|
26
|
+
"prepare": "npm run prepare:typescript",
|
|
27
|
+
"prepare:typescript": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types --resolveJsonModule -t esnext -m esnext --module nodenext --moduleResolution nodenext --rootDir src ./src**/*.mjs",
|
|
23
28
|
"test": "npm run test:ava",
|
|
24
29
|
"test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
|
|
25
30
|
"cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
|
|
26
31
|
"docs": "documentation readme --section=API ./src/**/*.mjs",
|
|
27
|
-
"lint": "npm run lint:docs",
|
|
28
|
-
"lint:docs": "documentation lint ./src/**/*.mjs"
|
|
32
|
+
"lint": "npm run lint:docs && npm run lint:typescript",
|
|
33
|
+
"lint:docs": "documentation lint ./src/**/*.mjs",
|
|
34
|
+
"lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
|
|
29
35
|
},
|
|
30
36
|
"dependencies": {
|
|
31
|
-
"@kronos-integration/endpoint": "^9.4
|
|
32
|
-
"@kronos-integration/interceptor": "^10.
|
|
33
|
-
"loglevel-mixin": "^7.
|
|
37
|
+
"@kronos-integration/endpoint": "^9.5.4",
|
|
38
|
+
"@kronos-integration/interceptor": "^10.3.0",
|
|
39
|
+
"loglevel-mixin": "^7.2.2",
|
|
34
40
|
"model-attributes": "^4.2.2",
|
|
35
|
-
"remove-sensible-values": "^1.
|
|
36
|
-
"statetransition-mixin": "^8.0
|
|
41
|
+
"remove-sensible-values": "^1.3.1",
|
|
42
|
+
"statetransition-mixin": "^8.1.0"
|
|
37
43
|
},
|
|
38
44
|
"devDependencies": {
|
|
39
|
-
"ava": "^6.
|
|
40
|
-
"c8": "^9.
|
|
41
|
-
"documentation": "^14.0.
|
|
42
|
-
"semantic-release": "^
|
|
45
|
+
"ava": "^6.1.2",
|
|
46
|
+
"c8": "^9.1.0",
|
|
47
|
+
"documentation": "^14.0.3",
|
|
48
|
+
"semantic-release": "^23.0.8",
|
|
49
|
+
"typescript": "^5.4.5"
|
|
43
50
|
},
|
|
44
51
|
"engines": {
|
|
45
|
-
"node": ">=20.
|
|
52
|
+
"node": ">=20.12.2"
|
|
46
53
|
},
|
|
47
54
|
"repository": {
|
|
48
55
|
"type": "git",
|
|
49
|
-
"url": "https://github.com/Kronos-Integration/service"
|
|
56
|
+
"url": "git+https://github.com/Kronos-Integration/service.git"
|
|
50
57
|
},
|
|
51
58
|
"bugs": {
|
|
52
59
|
"url": "https://github.com/Kronos-Integration/service/issues"
|
|
@@ -55,7 +62,8 @@
|
|
|
55
62
|
"template": {
|
|
56
63
|
"inheritFrom": [
|
|
57
64
|
"arlac77/template-arlac77-github",
|
|
58
|
-
"arlac77/template-kronos-component"
|
|
65
|
+
"arlac77/template-kronos-component",
|
|
66
|
+
"arlac77/template-typescript"
|
|
59
67
|
]
|
|
60
68
|
}
|
|
61
69
|
}
|
package/src/endpoints-mixin.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Endpoint,
|
|
2
3
|
SendEndpoint,
|
|
3
4
|
SendEndpointDefault,
|
|
4
5
|
SendReceiveEndpoint,
|
|
@@ -7,12 +8,13 @@ import {
|
|
|
7
8
|
ReceiveEndpointDefault,
|
|
8
9
|
ReceiveEndpointSelfConnectedDefault
|
|
9
10
|
} from "@kronos-integration/endpoint";
|
|
11
|
+
import { InitializationContext } from "./initialization-context.mjs";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Endpoint accessor mixin.
|
|
13
15
|
* Manages endpoints in a container.
|
|
14
|
-
* @param {
|
|
15
|
-
* @return {
|
|
16
|
+
* @param {new() => superclass} superclass class to be extended
|
|
17
|
+
* @return {new() => superclass} extended class
|
|
16
18
|
*/
|
|
17
19
|
export function EndpointsMixin(superclass) {
|
|
18
20
|
return class EndpointsMixin extends superclass {
|
|
@@ -41,6 +43,7 @@ export function EndpointsMixin(superclass) {
|
|
|
41
43
|
* @param {string} name of the endpoint
|
|
42
44
|
* @param {Object} definition endpoints definition
|
|
43
45
|
* @param {string|Function} definition.receive name of method or property
|
|
46
|
+
* @param {Endpoint} definition.connected
|
|
44
47
|
* @param {InitializationContext} ic
|
|
45
48
|
* @return {Object} suitable to pass as options to the endpoint factory
|
|
46
49
|
*/
|
|
@@ -75,6 +78,8 @@ export function EndpointsMixin(superclass) {
|
|
|
75
78
|
* @param {any} definition.receive defined will result in a ReceiveEndpoint
|
|
76
79
|
* @param {boolean} definition.out true will result in a SendEndpoint
|
|
77
80
|
* @param {boolean} definition.default true will result in a (Send|Receive)DefaultEndpoint
|
|
81
|
+
* @param {boolean} definition.multi true will result in a MultiSendEndpoint
|
|
82
|
+
* @param {Endpoint[]|string} definition.connected true will result in a MultiSendEndpoint
|
|
78
83
|
* @param {InitializationContext} ic
|
|
79
84
|
* @return {Object} endpoint factory
|
|
80
85
|
*/
|
|
@@ -21,9 +21,9 @@ export const InitializationContext = LogLevelMixin(
|
|
|
21
21
|
*/
|
|
22
22
|
class InitializationContext {
|
|
23
23
|
|
|
24
|
-
outstandingServices = new Map();
|
|
25
|
-
outstandingFactories = new Map();
|
|
26
|
-
outstandingEndpointConnections = new Map();
|
|
24
|
+
/** @type {Map<string,Promise<Service>>} */ outstandingServices = new Map();
|
|
25
|
+
/** @type {Map<string,Promise<Function>>} */ outstandingFactories = new Map();
|
|
26
|
+
/** @type {Map<string,Promise<Endpoint>>} */ outstandingEndpointConnections = new Map();
|
|
27
27
|
|
|
28
28
|
constructor(serviceProvider, options) {
|
|
29
29
|
this.serviceProvider = serviceProvider;
|
|
@@ -32,7 +32,7 @@ export const InitializationContext = LogLevelMixin(
|
|
|
32
32
|
/**
|
|
33
33
|
* Forward to the serviceProvider.
|
|
34
34
|
* @param {string} level the log level
|
|
35
|
-
* @param {Object}
|
|
35
|
+
* @param {Object} args log content
|
|
36
36
|
*/
|
|
37
37
|
log(level, ...args) {
|
|
38
38
|
if (this.serviceProvider) {
|
|
@@ -162,7 +162,7 @@ export const InitializationContext = LogLevelMixin(
|
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
164
|
*
|
|
165
|
-
* @param {string|
|
|
165
|
+
* @param {string|(new() => type)} type name if type
|
|
166
166
|
*/
|
|
167
167
|
async getServiceFactory(type) {
|
|
168
168
|
const sp = this.serviceProvider;
|
|
@@ -230,7 +230,7 @@ export const InitializationContext = LogLevelMixin(
|
|
|
230
230
|
* - otherwise declare this action as a new outstanding service declaration
|
|
231
231
|
* @param {Object} config
|
|
232
232
|
* @param {string} name service name
|
|
233
|
-
* @return {Service}
|
|
233
|
+
* @return {Promise<Service|undefined>}
|
|
234
234
|
*/
|
|
235
235
|
async declareService(config, name) {
|
|
236
236
|
const sp = this.serviceProvider;
|
package/src/service-config.mjs
CHANGED
|
@@ -25,7 +25,7 @@ export class ServiceConfig extends Service {
|
|
|
25
25
|
/**
|
|
26
26
|
* Deliver configuration for a given service.
|
|
27
27
|
* @param {string} name service name
|
|
28
|
-
* @param {
|
|
28
|
+
* @param {Object} config
|
|
29
29
|
*/
|
|
30
30
|
async configFor(name, config) {
|
|
31
31
|
this.trace(`configFor ${name}`);
|
|
@@ -9,8 +9,8 @@ import { InitializationContext } from "./initialization-context.mjs";
|
|
|
9
9
|
* By default a service provider has two build in services
|
|
10
10
|
* 'logger' and 'config'.
|
|
11
11
|
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
12
|
+
* @param {new(Object,InitializationContext) => serviceLoggerClass} serviceLoggerClass where the logging houtd go
|
|
13
|
+
* @param {new(Object,InitializationContext) => serviceConfigClass} serviceConfigClass where the config comes from
|
|
14
14
|
*/
|
|
15
15
|
export function ServiceProviderMixin(
|
|
16
16
|
superclass,
|
|
@@ -106,8 +106,8 @@ export function ServiceProviderMixin(
|
|
|
106
106
|
* Registers a interceptor factory for later use by
|
|
107
107
|
* @see {instantiateInterceptor}.
|
|
108
108
|
*
|
|
109
|
-
* @param {
|
|
110
|
-
* @returns {
|
|
109
|
+
* @param {new() => factory} factory
|
|
110
|
+
* @returns {new() => factory} factory
|
|
111
111
|
*/
|
|
112
112
|
registerInterceptorFactory(factory) {
|
|
113
113
|
this.interceptorFactories[factory.name] = factory;
|
|
@@ -181,7 +181,7 @@ export function ServiceProviderMixin(
|
|
|
181
181
|
* If a service for the name is already present and it has a matching type
|
|
182
182
|
* then its configure() is called and returned.
|
|
183
183
|
* Otherwise a new service will be created eventually replacing an already existing service with the same name.
|
|
184
|
-
* @param {object}
|
|
184
|
+
* @param {object} configs with
|
|
185
185
|
* name - the service name
|
|
186
186
|
* type - the service factory name - defaults to config.name
|
|
187
187
|
* @return {Promise<Object>} resolving to the declared services
|
package/src/service.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
setAttributes
|
|
7
7
|
} from "model-attributes";
|
|
8
8
|
import { EndpointsMixin } from "./endpoints-mixin.mjs";
|
|
9
|
+
import { InitializationContext } from "./initialization-context.mjs";
|
|
9
10
|
|
|
10
11
|
const _ca = createAttributes({
|
|
11
12
|
description: {
|
|
@@ -78,6 +79,8 @@ const ssfDefault = {
|
|
|
78
79
|
* @param {string} config.description human readable description
|
|
79
80
|
* @param {Object} config.endpoints will be merged with the build in ones
|
|
80
81
|
* @param {InitializationContext} ic
|
|
82
|
+
*
|
|
83
|
+
* @property {Object} endpoints
|
|
81
84
|
*/
|
|
82
85
|
export class Service extends EndpointsMixin(
|
|
83
86
|
StateTransitionMixin(
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoint accessor mixin.
|
|
3
|
+
* Manages endpoints in a container.
|
|
4
|
+
* @param {new() => superclass} superclass class to be extended
|
|
5
|
+
* @return {new() => superclass} extended class
|
|
6
|
+
*/
|
|
7
|
+
export function EndpointsMixin(superclass: new () => new () => any): new () => new () => any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./service.mjs";
|
|
2
|
+
export * from "./service-logger.mjs";
|
|
3
|
+
export * from "./service-config.mjs";
|
|
4
|
+
export * from "./service-provider-mixin.mjs";
|
|
5
|
+
export * from "./endpoints-mixin.mjs";
|
|
6
|
+
export * from "./standalone-service-provider.mjs";
|
|
7
|
+
export * from "./service-consumer-mixin.mjs";
|
|
8
|
+
export * from "./initialization-context.mjs";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge from b into a.
|
|
3
|
+
* When *a* and *b* are arrays of values only the none duplicates are appendend to *a*.
|
|
4
|
+
* @param {any} a
|
|
5
|
+
* @param {any} b
|
|
6
|
+
* @return {any} merged b into a
|
|
7
|
+
*/
|
|
8
|
+
export function merge(a: any, b: any): any;
|
|
9
|
+
/**
|
|
10
|
+
* Config providing service.
|
|
11
|
+
* Dispatches config requests to services.
|
|
12
|
+
* Also preserves them until a maching service becomes avaliable.
|
|
13
|
+
* @property {Map<string,Object>} preservedConfigs values for services not already established
|
|
14
|
+
*/
|
|
15
|
+
export class ServiceConfig extends Service {
|
|
16
|
+
preservedConfigs: Map<any, any>;
|
|
17
|
+
/**
|
|
18
|
+
* Deliver configuration for a given service.
|
|
19
|
+
* @param {string} name service name
|
|
20
|
+
* @param {Object} config
|
|
21
|
+
*/
|
|
22
|
+
configFor(name: string, config: any): Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Forget about preserved config of a service.
|
|
25
|
+
* @param {string} name service name
|
|
26
|
+
*/
|
|
27
|
+
clearPreserved(name: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Set config entry.
|
|
30
|
+
* @param {string} key path to the value
|
|
31
|
+
* @param {any} value
|
|
32
|
+
*/
|
|
33
|
+
configureValue(key: string, value: any): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {Array|Object} config
|
|
37
|
+
*/
|
|
38
|
+
configure(config: any[] | any): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
import { Service } from "./service.mjs";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assign services based on a configuration.
|
|
3
|
+
* @param {Object} target object
|
|
4
|
+
* @param {Object} config service defintion
|
|
5
|
+
* @param {Object} provider service provider
|
|
6
|
+
* @param {boolean} waitUntilFactoryPresent
|
|
7
|
+
*/
|
|
8
|
+
export function defineServiceConsumerProperties(target: any, config: any, provider: any, waitUntilFactoryPresent: boolean): Promise<any[]>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provide services and hold service configuration.
|
|
3
|
+
* By default a service provider has two build in services
|
|
4
|
+
* 'logger' and 'config'.
|
|
5
|
+
*
|
|
6
|
+
* @param {new(Object,InitializationContext) => serviceLoggerClass} serviceLoggerClass where the logging houtd go
|
|
7
|
+
* @param {new(Object,InitializationContext) => serviceConfigClass} serviceConfigClass where the config comes from
|
|
8
|
+
*/
|
|
9
|
+
export function ServiceProviderMixin(superclass: any, serviceLoggerClass?: new (Object, InitializationContext) => new (Object: any, InitializationContext: any) => any, serviceConfigClass?: new (Object, InitializationContext) => new (Object: any, InitializationContext: any) => any): {
|
|
10
|
+
new (config: any, ic?: any): {
|
|
11
|
+
[x: string]: any;
|
|
12
|
+
listeners: {};
|
|
13
|
+
interceptorFactories: {};
|
|
14
|
+
serviceFactories: {};
|
|
15
|
+
services: {};
|
|
16
|
+
ic: any;
|
|
17
|
+
emit(name: any, ...args: any[]): void;
|
|
18
|
+
addListener(name: any, listener: any): void;
|
|
19
|
+
removeListener(name: any, listener: any): void;
|
|
20
|
+
/**
|
|
21
|
+
* By default be our own owner.
|
|
22
|
+
* @return this
|
|
23
|
+
*/
|
|
24
|
+
readonly owner: any;
|
|
25
|
+
/**
|
|
26
|
+
* We are the service provider.
|
|
27
|
+
* @return {boolean} true
|
|
28
|
+
*/
|
|
29
|
+
readonly isServiceProvider: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Register service or interceptor factories.
|
|
32
|
+
*
|
|
33
|
+
* @param {Function[]} factories
|
|
34
|
+
*/
|
|
35
|
+
registerFactories(factories: Function[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* Registers a interceptor factory for later use by
|
|
38
|
+
* @see {instantiateInterceptor}.
|
|
39
|
+
*
|
|
40
|
+
* @param {new() => factory} factory
|
|
41
|
+
* @returns {new() => factory} factory
|
|
42
|
+
*/
|
|
43
|
+
registerInterceptorFactory(factory: new () => new () => any): new () => new () => any;
|
|
44
|
+
unregisterInterceptorFactory(factory: any): void;
|
|
45
|
+
/**
|
|
46
|
+
* Instanciates an interceptor from its definition data.
|
|
47
|
+
* @see {interceptorFactories}
|
|
48
|
+
* @param {Object} definition data
|
|
49
|
+
* @returns {Interceptor}
|
|
50
|
+
*/
|
|
51
|
+
instantiateInterceptor(definition: any): Interceptor;
|
|
52
|
+
serviceStateChanged(service: any, oldState: any, newState: any): void;
|
|
53
|
+
registerServiceFactory(factory: any): Promise<any>;
|
|
54
|
+
unregisterServiceFactory(factory: any): Promise<void>;
|
|
55
|
+
registerService(service: any): Promise<any>;
|
|
56
|
+
unregisterService(serviceName: any): Promise<void>;
|
|
57
|
+
readonly serviceNames: string[];
|
|
58
|
+
getService(name: any): any;
|
|
59
|
+
declareService(config: any): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Add a new service based on its configuration.
|
|
62
|
+
* If a service for the name is already present and it has a matching type
|
|
63
|
+
* then its configure() is called and returned.
|
|
64
|
+
* Otherwise a new service will be created eventually replacing an already existing service with the same name.
|
|
65
|
+
* @param {object} configs with
|
|
66
|
+
* name - the service name
|
|
67
|
+
* type - the service factory name - defaults to config.name
|
|
68
|
+
* @return {Promise<Object>} resolving to the declared services
|
|
69
|
+
*/
|
|
70
|
+
declareServices(configs: object): Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Start all registered services which hanving autostart set.
|
|
73
|
+
*/
|
|
74
|
+
_start(): Promise<any[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Stop all services.
|
|
77
|
+
* @return {Promise} that resolves when all services are stopped
|
|
78
|
+
*/
|
|
79
|
+
_stop(): Promise<any>;
|
|
80
|
+
};
|
|
81
|
+
[x: string]: any;
|
|
82
|
+
};
|
|
83
|
+
import { Interceptor } from "@kronos-integration/interceptor";
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
declare const Service_base: new () => new () => any;
|
|
2
|
+
/**
|
|
3
|
+
* Service
|
|
4
|
+
* The initial state is 'stopped'.
|
|
5
|
+
* All services have at least three endpoints:
|
|
6
|
+
* - log _out_: log events
|
|
7
|
+
* - config _in_: configuration request
|
|
8
|
+
* - command _in_: administrative actions to be executed by the step
|
|
9
|
+
* @param {Object} config
|
|
10
|
+
* @param {string} config.name
|
|
11
|
+
* @param {string} config.logLevel
|
|
12
|
+
* @param {boolean} config.autostart defaults to false
|
|
13
|
+
* @param {string} config.description human readable description
|
|
14
|
+
* @param {Object} config.endpoints will be merged with the build in ones
|
|
15
|
+
* @param {InitializationContext} ic
|
|
16
|
+
*
|
|
17
|
+
* @property {Object} endpoints
|
|
18
|
+
*/
|
|
19
|
+
export class Service extends Service_base {
|
|
20
|
+
static get description(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Meta information for the config attributes.
|
|
23
|
+
* - default optional default value of the attribute
|
|
24
|
+
* - needsRestart optional modification requires a service restart
|
|
25
|
+
* - setter(newValue,attribute) optional function to be used if simple value assignment is not enough
|
|
26
|
+
* The Service class only defines the logLevel, and start/stop/restart timeout attribute
|
|
27
|
+
* @return {Object}
|
|
28
|
+
*/
|
|
29
|
+
static get configurationAttributes(): any;
|
|
30
|
+
/**
|
|
31
|
+
* Definition of the predefined endpoints.
|
|
32
|
+
* - log _out_
|
|
33
|
+
* - config _in_
|
|
34
|
+
* @return {Object} predefined endpoints
|
|
35
|
+
*/
|
|
36
|
+
static get endpoints(): any;
|
|
37
|
+
constructor(config: any, ic: any);
|
|
38
|
+
owner: any;
|
|
39
|
+
logLevel: any;
|
|
40
|
+
instantiateInterceptor(options: any): any;
|
|
41
|
+
get configurationAttributes(): any;
|
|
42
|
+
get type(): string;
|
|
43
|
+
set description(desc: any);
|
|
44
|
+
get description(): any;
|
|
45
|
+
/**
|
|
46
|
+
* Used in human readable state messages.
|
|
47
|
+
* Besides the actual service name it may contain additional short hints.
|
|
48
|
+
* @return {string}
|
|
49
|
+
*/
|
|
50
|
+
get extendetName(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Called when the service state changes.
|
|
53
|
+
* Emits a serviceStateChanged event to the owner.
|
|
54
|
+
* @param {string} oldState
|
|
55
|
+
* @param {string} newState
|
|
56
|
+
*/
|
|
57
|
+
stateChanged(origin: any, oldState: string, newState: string): void;
|
|
58
|
+
stateTransitionRejection(rejected: any, newState: any): any;
|
|
59
|
+
/**
|
|
60
|
+
* Called when state transition is not allowed.
|
|
61
|
+
* @param {string} action originating action name
|
|
62
|
+
* @throws always
|
|
63
|
+
*/
|
|
64
|
+
rejectWrongState(action: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Deliver transition timeout.
|
|
67
|
+
* @param {Object} transition
|
|
68
|
+
* @return {number} milliseconds before throwing for a long running transition
|
|
69
|
+
*/
|
|
70
|
+
timeoutForTransition(transition: any): number;
|
|
71
|
+
/**
|
|
72
|
+
* Opens all endpoint connections.
|
|
73
|
+
*/
|
|
74
|
+
_start(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Closes all endpoint connections.
|
|
77
|
+
*/
|
|
78
|
+
_stop(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Restart action.
|
|
81
|
+
* default implementation does a _stop() and a _start()
|
|
82
|
+
* @return {Promise} fulfills after start
|
|
83
|
+
*/
|
|
84
|
+
_restart(): Promise<any>;
|
|
85
|
+
/**
|
|
86
|
+
* Restarts if in running mode.
|
|
87
|
+
* Otherwise does nothing.
|
|
88
|
+
* @returns {Promise} resolves when restart is done (or immediate if no restart triggered)
|
|
89
|
+
*/
|
|
90
|
+
restartIfRunning(): Promise<any>;
|
|
91
|
+
/**
|
|
92
|
+
* Mapping of properties used in toString.
|
|
93
|
+
* @return {Object}
|
|
94
|
+
*/
|
|
95
|
+
get toStringAttributes(): any;
|
|
96
|
+
/**
|
|
97
|
+
* Base service is not a provider.
|
|
98
|
+
* @return {boolean} false
|
|
99
|
+
*/
|
|
100
|
+
get isServiceProvider(): boolean;
|
|
101
|
+
toJSON(): any;
|
|
102
|
+
/**
|
|
103
|
+
* Deliver json representation.
|
|
104
|
+
* @param {Object} options
|
|
105
|
+
* @param {boolean} options.includeRuntimeInfo include runtime informtion like state
|
|
106
|
+
* @param {boolean} options.includeDefaults include default endpoints
|
|
107
|
+
* @param {boolean} options.includeName include name of the service
|
|
108
|
+
* @param {boolean} options.includeConfig include config attributes
|
|
109
|
+
* @param {boolean} options.includePrivate include private config attributes
|
|
110
|
+
* @return {Object} json representation
|
|
111
|
+
*/
|
|
112
|
+
toJSONWithOptions(options: {
|
|
113
|
+
includeRuntimeInfo: boolean;
|
|
114
|
+
includeDefaults: boolean;
|
|
115
|
+
includeName: boolean;
|
|
116
|
+
includeConfig: boolean;
|
|
117
|
+
includePrivate: boolean;
|
|
118
|
+
}): any;
|
|
119
|
+
/**
|
|
120
|
+
* Should we start when beeing registered.
|
|
121
|
+
* @return {boolean} false
|
|
122
|
+
*/
|
|
123
|
+
get autostart(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Takes attribute values from config parameters
|
|
126
|
+
* and copies them over to the object.
|
|
127
|
+
* Copying is done according to configurationAttributes.
|
|
128
|
+
* Which means we loop over all configuration attributes.
|
|
129
|
+
* and then for each attribute decide if we use the default, call a setter function
|
|
130
|
+
* or simply assign the attribute value.
|
|
131
|
+
* @param {Object} config
|
|
132
|
+
* @return {Set} of modified attributes
|
|
133
|
+
*/
|
|
134
|
+
_configure(config: any): Set<any>;
|
|
135
|
+
/**
|
|
136
|
+
* Use new configuration.
|
|
137
|
+
* Internally calls _configure(config) as the constructor does.
|
|
138
|
+
* If attribute with needsRestart are touched the restartIfRunning method
|
|
139
|
+
* will be called.
|
|
140
|
+
* @param {Object} config
|
|
141
|
+
* @return {Promise} fillfills when config is applied
|
|
142
|
+
*/
|
|
143
|
+
configure(config: any): Promise<any>;
|
|
144
|
+
/**
|
|
145
|
+
* Adds service name to the log event.
|
|
146
|
+
* @param {string} level the log level
|
|
147
|
+
* @param {Object} arg log content
|
|
148
|
+
*/
|
|
149
|
+
log(level: string, arg: any): void;
|
|
150
|
+
#private;
|
|
151
|
+
}
|
|
152
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
declare const StandaloneServiceProvider_base: {
|
|
2
|
+
new (config: any, ic?: any): {
|
|
3
|
+
[x: string]: any;
|
|
4
|
+
listeners: {};
|
|
5
|
+
interceptorFactories: {};
|
|
6
|
+
serviceFactories: {};
|
|
7
|
+
services: {};
|
|
8
|
+
ic: any;
|
|
9
|
+
emit(name: any, ...args: any[]): void;
|
|
10
|
+
addListener(name: any, listener: any): void;
|
|
11
|
+
removeListener(name: any, listener: any): void;
|
|
12
|
+
readonly owner: any;
|
|
13
|
+
readonly isServiceProvider: boolean;
|
|
14
|
+
registerFactories(factories: Function[]): void;
|
|
15
|
+
registerInterceptorFactory(factory: new () => any): new () => new () => any;
|
|
16
|
+
unregisterInterceptorFactory(factory: any): void;
|
|
17
|
+
instantiateInterceptor(definition: any): import("@kronos-integration/interceptor").Interceptor;
|
|
18
|
+
serviceStateChanged(service: any, oldState: any, newState: any): void;
|
|
19
|
+
registerServiceFactory(factory: any): Promise<any>;
|
|
20
|
+
unregisterServiceFactory(factory: any): Promise<void>;
|
|
21
|
+
registerService(service: any): Promise<any>;
|
|
22
|
+
unregisterService(serviceName: any): Promise<void>;
|
|
23
|
+
readonly serviceNames: string[];
|
|
24
|
+
getService(name: any): any;
|
|
25
|
+
declareService(config: any): Promise<any>;
|
|
26
|
+
declareServices(configs: any): Promise<any>;
|
|
27
|
+
_start(): Promise<any[]>;
|
|
28
|
+
_stop(): Promise<any>;
|
|
29
|
+
};
|
|
30
|
+
[x: string]: any;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Simple service manager (for examples and testing only).
|
|
34
|
+
*/
|
|
35
|
+
export class StandaloneServiceProvider extends StandaloneServiceProvider_base {
|
|
36
|
+
static get description(): string;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
package/types/util.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function keyValue2Object(key: any, value: any): {};
|