pmcf 1.41.0 → 1.42.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/package.json +1 -1
- package/src/base.mjs +26 -0
- package/src/host.mjs +9 -21
- package/src/owner.mjs +16 -24
- package/types/base.d.mts +2 -0
- package/types/host.d.mts +10 -0
- package/types/owner.d.mts +19 -2
package/package.json
CHANGED
package/src/base.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { getAttribute } from "pacc";
|
|
3
|
+
import { typesByName } from "./types.mjs";
|
|
3
4
|
|
|
4
5
|
export class Base {
|
|
5
6
|
owner;
|
|
@@ -10,6 +11,12 @@ export class Base {
|
|
|
10
11
|
return "base";
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
static get typeDefinition() {
|
|
15
|
+
return {
|
|
16
|
+
// name: { type: "string", collection: false }
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
static get pluralTypeName() {
|
|
14
21
|
return this.typeName + "s";
|
|
15
22
|
}
|
|
@@ -47,6 +54,25 @@ export class Base {
|
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
|
|
57
|
+
read(data) {
|
|
58
|
+
for (const [slotName, typeDef] of Object.entries(
|
|
59
|
+
this.constructor.typeDefinition
|
|
60
|
+
)) {
|
|
61
|
+
const slot = data[slotName];
|
|
62
|
+
if (slot) {
|
|
63
|
+
delete data[slotName];
|
|
64
|
+
if (typeDef.collection) {
|
|
65
|
+
for (const [objectName, objectData] of Object.entries(slot)) {
|
|
66
|
+
objectData.name = objectName;
|
|
67
|
+
new typesByName[typeDef.type](this, objectData);
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
this[typeDef.type] = new typesByName[typeDef.type](this, slot);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
50
76
|
forOwner(owner) {
|
|
51
77
|
if (this.owner !== owner) {
|
|
52
78
|
// @ts-ignore
|
package/src/host.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Base } from "./base.mjs";
|
|
2
2
|
import { Network } from "./network.mjs";
|
|
3
|
-
import { Service } from "./service.mjs";
|
|
4
3
|
import {
|
|
5
4
|
asArray,
|
|
6
5
|
isIPv4Address,
|
|
@@ -32,6 +31,13 @@ export class Host extends Base {
|
|
|
32
31
|
return "host";
|
|
33
32
|
}
|
|
34
33
|
|
|
34
|
+
static get typeDefinition() {
|
|
35
|
+
return {
|
|
36
|
+
networkInterfaces: { type: "network_interface", collection: true },
|
|
37
|
+
services: { type: "service", collection: true }
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
static async prepareData(root, data) {
|
|
36
42
|
if (data.extends) {
|
|
37
43
|
data.extends = await Promise.all(
|
|
@@ -86,32 +92,14 @@ export class Host extends Base {
|
|
|
86
92
|
delete data.provides;
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
if (data.services) {
|
|
90
|
-
for (const [name, sd] of Object.entries(data.services)) {
|
|
91
|
-
sd.name = name;
|
|
92
|
-
new Service(this, sd);
|
|
93
|
-
}
|
|
94
|
-
delete data.services;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (data.networkInterfaces) {
|
|
98
|
-
for (const [name, iface] of Object.entries(data.networkInterfaces)) {
|
|
99
|
-
iface.name = name;
|
|
100
|
-
new NetworkInterface(this, iface);
|
|
101
|
-
}
|
|
102
|
-
delete data.networkInterfaces;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
95
|
for (const host of this.extends) {
|
|
106
96
|
for (const service of host.services()) {
|
|
107
97
|
service.forOwner(this);
|
|
108
98
|
}
|
|
109
|
-
|
|
110
|
-
/*for (const ni of host.networkInterfaces.values()) {
|
|
111
|
-
ni.forOwner(this);
|
|
112
|
-
}*/
|
|
113
99
|
}
|
|
114
100
|
|
|
101
|
+
this.read(data);
|
|
102
|
+
|
|
115
103
|
Object.assign(this, data);
|
|
116
104
|
|
|
117
105
|
owner.addObject(this);
|
package/src/owner.mjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { asArray, normalizeCIDR } from "./utils.mjs";
|
|
2
2
|
import { Base } from "./base.mjs";
|
|
3
3
|
import { Subnet } from "./subnet.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { addType, typesByName } from "./types.mjs";
|
|
4
|
+
import { addType } from "./types.mjs";
|
|
6
5
|
|
|
7
6
|
export class Owner extends Base {
|
|
8
7
|
#membersByType = new Map();
|
|
9
8
|
#bridges = new Set();
|
|
10
|
-
#dns;
|
|
11
9
|
#administratorEmail;
|
|
12
10
|
domain;
|
|
13
11
|
ntp = { servers: [] };
|
|
@@ -20,17 +18,19 @@ export class Owner extends Base {
|
|
|
20
18
|
return "owner";
|
|
21
19
|
}
|
|
22
20
|
|
|
21
|
+
static get typeDefinition() {
|
|
22
|
+
return {
|
|
23
|
+
networks: { type: "network", collection: true },
|
|
24
|
+
hosts: { type: "host", collection: true },
|
|
25
|
+
clusters: { type: "cluster", collection: true },
|
|
26
|
+
/* subnets: { type: "subnet", collection: true },*/
|
|
27
|
+
dns: { type: "dns", collection: false }
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
constructor(owner, data = {}) {
|
|
24
32
|
super(owner, data);
|
|
25
33
|
|
|
26
|
-
let dns;
|
|
27
|
-
if (data.dns) {
|
|
28
|
-
dns = data.dns;
|
|
29
|
-
delete data.dns;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.#dns = new DNSService(this, dns);
|
|
33
|
-
|
|
34
34
|
if (data.administratorEmail) {
|
|
35
35
|
this.#administratorEmail = data.administratorEmail;
|
|
36
36
|
delete data.administratorEmail;
|
|
@@ -46,15 +46,7 @@ export class Owner extends Base {
|
|
|
46
46
|
delete data.ntp;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
const networks = data.networks;
|
|
51
|
-
delete data.networks;
|
|
52
|
-
|
|
53
|
-
for (const [name, data] of Object.entries(networks)) {
|
|
54
|
-
data.name = name;
|
|
55
|
-
new typesByName.network(this, data);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
49
|
+
this.read(data);
|
|
58
50
|
|
|
59
51
|
owner?.addObject(this);
|
|
60
52
|
}
|
|
@@ -73,10 +65,6 @@ export class Owner extends Base {
|
|
|
73
65
|
return false;
|
|
74
66
|
}
|
|
75
67
|
|
|
76
|
-
get dns() {
|
|
77
|
-
return this.#dns;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
68
|
named(name) {
|
|
81
69
|
//console.log("NAMED", this.#membersByType.keys());
|
|
82
70
|
for (const slot of this.#membersByType.values()) {
|
|
@@ -92,6 +80,10 @@ export class Owner extends Base {
|
|
|
92
80
|
return typeSlot?.get(name) || this.owner?.typeNamed(typeName, name);
|
|
93
81
|
}
|
|
94
82
|
|
|
83
|
+
typeObject(typeName) {
|
|
84
|
+
return this.#membersByType.get(typeName);
|
|
85
|
+
}
|
|
86
|
+
|
|
95
87
|
typeList(typeName) {
|
|
96
88
|
const typeSlot = this.#membersByType.get(typeName);
|
|
97
89
|
if (typeSlot) {
|
package/types/base.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export function extractFrom(object: any): {};
|
|
2
2
|
export class Base {
|
|
3
3
|
static get typeName(): string;
|
|
4
|
+
static get typeDefinition(): {};
|
|
4
5
|
static get pluralTypeName(): string;
|
|
5
6
|
static get nameLookupName(): string;
|
|
6
7
|
static get typeFileName(): string;
|
|
@@ -11,6 +12,7 @@ export class Base {
|
|
|
11
12
|
owner: any;
|
|
12
13
|
name: any;
|
|
13
14
|
description: any;
|
|
15
|
+
read(data: any): void;
|
|
14
16
|
forOwner(owner: any): any;
|
|
15
17
|
get typeName(): any;
|
|
16
18
|
get root(): any;
|
package/types/host.d.mts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
export class Host extends Base {
|
|
2
|
+
static get typeDefinition(): {
|
|
3
|
+
networkInterfaces: {
|
|
4
|
+
type: string;
|
|
5
|
+
collection: boolean;
|
|
6
|
+
};
|
|
7
|
+
services: {
|
|
8
|
+
type: string;
|
|
9
|
+
collection: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
2
12
|
static prepareData(root: any, data: any): Promise<typeof Host>;
|
|
3
13
|
postinstall: any[];
|
|
4
14
|
_traverse(...args: any[]): boolean;
|
package/types/owner.d.mts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
export class Owner extends Base {
|
|
2
|
+
static get typeDefinition(): {
|
|
3
|
+
networks: {
|
|
4
|
+
type: string;
|
|
5
|
+
collection: boolean;
|
|
6
|
+
};
|
|
7
|
+
hosts: {
|
|
8
|
+
type: string;
|
|
9
|
+
collection: boolean;
|
|
10
|
+
};
|
|
11
|
+
clusters: {
|
|
12
|
+
type: string;
|
|
13
|
+
collection: boolean;
|
|
14
|
+
};
|
|
15
|
+
dns: {
|
|
16
|
+
type: string;
|
|
17
|
+
collection: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
2
20
|
constructor(owner: any, data?: {});
|
|
3
21
|
domain: any;
|
|
4
22
|
ntp: {
|
|
5
23
|
servers: any[];
|
|
6
24
|
};
|
|
7
25
|
_traverse(...args: any[]): boolean;
|
|
8
|
-
get dns(): DNSService;
|
|
9
26
|
named(name: any): any;
|
|
10
27
|
typeNamed(typeName: any, name: any): any;
|
|
28
|
+
typeObject(typeName: any): any;
|
|
11
29
|
typeList(typeName: any): any;
|
|
12
30
|
_addObject(typeName: any, fullName: any, object: any): void;
|
|
13
31
|
addObject(object: any): void;
|
|
@@ -32,4 +50,3 @@ export class Owner extends Base {
|
|
|
32
50
|
#private;
|
|
33
51
|
}
|
|
34
52
|
import { Base } from "./base.mjs";
|
|
35
|
-
import { DNSService } from "./dns.mjs";
|