Skip to content

Commit b689004

Browse files
Added types for docker-api (#3128)
* Added types for docker-api * Fixed linter * Fix tests
1 parent 5ef70a7 commit b689004

File tree

2 files changed

+55
-35
lines changed

2 files changed

+55
-35
lines changed

packages/controller/test/lib/testObjects.ts

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,27 @@ export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, cont
1010
const namespace = 'testObject.0';
1111
const testId = `${namespace}.test2`;
1212

13-
it(`${testName}should create and read object`, done => {
13+
it(`${testName}should create and read object`, async (): Promise<void> => {
1414
const objects = context.objects;
15-
objects.setObject(
16-
testId,
17-
{
18-
type: 'state',
19-
common: {
20-
type: 'string',
21-
name: 'test2',
22-
read: true,
23-
write: true,
24-
role: 'state',
25-
},
26-
native: {},
27-
},
28-
(err, res) => {
29-
expect(err).to.be.not.ok;
30-
expect(res).to.be.ok;
31-
expect(res!.id).to.be.equal(testId);
32-
33-
objects.getObject(testId, (err, obj) => {
34-
expect(err).to.be.not.ok;
35-
expect(obj).to.be.ok;
36-
expect(obj!.common.name).to.be.equal('test2');
37-
expect(obj!._id).to.be.equal(testId);
38-
console.log(JSON.stringify(obj));
39-
done();
40-
});
15+
const res = await objects.setObjectAsync(testId, {
16+
type: 'state',
17+
common: {
18+
type: 'string',
19+
name: 'test2',
20+
read: true,
21+
write: true,
22+
role: 'state',
4123
},
42-
);
24+
native: {},
25+
});
26+
expect(res).to.be.ok;
27+
expect(res!.id).to.be.equal(testId);
28+
29+
const obj = await objects.getObjectAsync(testId);
30+
expect(obj).to.be.ok;
31+
expect(obj!.common.name).to.be.equal('test2');
32+
expect(obj!._id).to.be.equal(testId);
33+
console.log(JSON.stringify(obj));
4334
});
4435

4536
it(`${testName}should create object async`, done => {

packages/types-dev/objects.d.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ declare global {
8989
type Host = `system.host.${string}`;
9090
// Guaranteed repository object
9191
type Repository = 'system.repositories';
92+
// Guaranteed repository object
93+
type DockerConfigs = 'system.dockers';
9294
// Guaranteed config objects
9395
type Config = 'system.certificates';
9496
// Guaranteed system config objects
@@ -147,13 +149,15 @@ declare global {
147149
? RepositoryObject
148150
: T extends ObjectIDs.SystemConfig
149151
? SystemConfigObject
150-
: T extends ObjectIDs.Config
151-
? OtherObject & { type: 'config' }
152-
: T extends ObjectIDs.AdapterScoped
153-
? AdapterScopedObject
154-
: Read extends 'read'
155-
? ioBroker.Object
156-
: AnyObject;
152+
: T extends ObjectIDs.DockerConfigs
153+
? DockerApiObject
154+
: T extends ObjectIDs.Config
155+
? OtherObject & { type: 'config' }
156+
: T extends ObjectIDs.AdapterScoped
157+
? AdapterScopedObject
158+
: Read extends 'read'
159+
? ioBroker.Object
160+
: AnyObject;
157161

158162
type Languages = 'en' | 'de' | 'ru' | 'pt' | 'nl' | 'fr' | 'it' | 'es' | 'pl' | 'uk' | 'zh-cn';
159163
type Translated = { en: string } & { [lang in Languages]?: string };
@@ -1104,6 +1108,31 @@ declare global {
11041108
common: RepositoryCommon;
11051109
}
11061110

1111+
interface DockerApiConfig {
1112+
socketPath?: string;
1113+
host?: string;
1114+
port?: number | string;
1115+
username?: string;
1116+
/** Filename, name in ioBroker certificate or base64 certificate */
1117+
ca?: string;
1118+
cert?: string;
1119+
key?: string;
1120+
protocol?: 'https' | 'http';
1121+
}
1122+
1123+
/** Docker API configuration */
1124+
interface DockerApiObject extends BaseObject {
1125+
_id: ObjectIDs.DockerConfigs;
1126+
type: 'config';
1127+
native: {
1128+
dockerApis: {
1129+
[configName: string]: DockerApiConfig;
1130+
};
1131+
};
1132+
// Make it possible to narrow the object type using the custom property
1133+
common: ObjectCommon & { custom?: undefined };
1134+
}
1135+
11071136
interface InstanceObject extends Omit<AdapterObject, 'type'>, BaseObject {
11081137
_id: ObjectIDs.Instance;
11091138
type: 'instance';

0 commit comments

Comments
 (0)