pmcf 1.27.2 → 1.28.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.27.2",
3
+ "version": "1.28.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -43,7 +43,7 @@
43
43
  "pacc": "^3.1.9"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/node": "^22.10.10",
46
+ "@types/node": "^22.12.0",
47
47
  "ava": "^6.2.0",
48
48
  "c8": "^10.1.3",
49
49
  "documentation": "^14.0.3",
package/src/base.mjs CHANGED
@@ -43,6 +43,7 @@ export class Base {
43
43
 
44
44
  withOwner(owner) {
45
45
  if (this.owner !== owner) {
46
+ // @ts-ignore
46
47
  return new this.constructor(owner, this);
47
48
  }
48
49
 
@@ -50,6 +51,7 @@ export class Base {
50
51
  }
51
52
 
52
53
  get typeName() {
54
+ // @ts-ignore
53
55
  return this.constructor.typeName;
54
56
  }
55
57
 
package/src/cluster.mjs CHANGED
@@ -4,4 +4,10 @@ export class Cluster extends Owner {
4
4
  static get typeName() {
5
5
  return "cluster";
6
6
  }
7
+
8
+ constructor(owner, data) {
9
+ super(owner, data);
10
+
11
+ owner.addCluster(this);
12
+ }
7
13
  }
package/src/model.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  normalizeIPAddress
8
8
  } from "./utils.mjs";
9
9
  import { Base } from "./base.mjs";
10
- import { Owner } from "./owner.mjs";
10
+ import { Owner, Network, Subnet } from "./owner.mjs";
11
11
  import { Service } from "./service.mjs";
12
12
  import { Cluster } from "./cluster.mjs";
13
13
  import { DNSService } from "./dns.mjs";
@@ -169,73 +169,6 @@ export class Location extends Owner {
169
169
  }
170
170
  }
171
171
 
172
- export class Network extends Owner {
173
- kind;
174
- scope;
175
- metric;
176
- ipv4;
177
- subnet;
178
- bridge;
179
-
180
- static get typeName() {
181
- return "network";
182
- }
183
-
184
- constructor(owner, data) {
185
- super(owner, data);
186
-
187
- let bridge;
188
- if (data.bridge) {
189
- bridge = data.bridge;
190
- delete data.bridge;
191
- }
192
-
193
- Object.assign(this, data);
194
-
195
- const subnetAddress = this.subnetAddress;
196
-
197
- if (subnetAddress) {
198
- let subnet = owner.subnet(subnetAddress);
199
- if (!subnet) {
200
- subnet = new Subnet(owner, { name: subnetAddress });
201
- }
202
-
203
- this.subnet = subnet;
204
- subnet.networks.add(this);
205
- }
206
-
207
- owner.addNetwork(this);
208
-
209
- this.bridge = owner.addBridge(this, bridge);
210
- }
211
-
212
- get netmask() {
213
- const m = this.ipv4?.match(/\/(\d+)$/);
214
- if (m) {
215
- return parseInt(m[1]);
216
- }
217
- }
218
-
219
- get subnetAddress() {
220
- if (this.ipv4) {
221
- const [addr, bits] = this.ipv4.split(/\//);
222
- const parts = addr.split(/\./);
223
- return parts.slice(0, bits / 8).join(".");
224
- }
225
- }
226
-
227
- get propertyNames() {
228
- return [
229
- ...super.propertyNames,
230
- "kind",
231
- "ipv4",
232
- "netmask",
233
- "scope",
234
- "metric",
235
- "bridge"
236
- ];
237
- }
238
- }
239
172
 
240
173
  export class Host extends Base {
241
174
  networkInterfaces = {};
@@ -655,25 +588,6 @@ export class NetworkInterface extends Base {
655
588
  }
656
589
  }
657
590
 
658
- export class Subnet extends Base {
659
- networks = new Set();
660
-
661
- static get typeName() {
662
- return "subnet";
663
- }
664
-
665
- constructor(owner, data) {
666
- super(owner, data);
667
-
668
- Object.assign(this, data);
669
-
670
- owner.addSubnet(this);
671
- }
672
-
673
- get address() {
674
- return this.name;
675
- }
676
- }
677
591
 
678
592
  const _types = [Location, Network, Subnet, Host, Cluster, Service, DNSService];
679
593
  const _typesByName = Object.fromEntries(_types.map(t => [t.typeName, t]));
package/src/owner.mjs CHANGED
@@ -5,6 +5,7 @@ import { DNSService } from "./dns.mjs";
5
5
 
6
6
  export class Owner extends Base {
7
7
  #hosts = new Map();
8
+ #clusters = new Map();
8
9
  #networks = new Map();
9
10
  #subnets = new Map();
10
11
  #bridges = new Set();
@@ -46,6 +47,10 @@ export class Owner extends Base {
46
47
  host._traverse(...args);
47
48
  }
48
49
 
50
+ for (const cluster of this.#clusters.values()) {
51
+ cluster._traverse(...args);
52
+ }
53
+
49
54
  return true;
50
55
  }
51
56
 
@@ -71,6 +76,11 @@ export class Owner extends Base {
71
76
  this.addObject(host);
72
77
  }
73
78
 
79
+ addCluster(cluster) {
80
+ this.#clusters.set(cluster.name, cluster);
81
+ this.addObject(cluster);
82
+ }
83
+
74
84
  async service(filter) {
75
85
  let best;
76
86
  for await (const service of this.services(filter)) {
@@ -91,6 +101,7 @@ export class Owner extends Base {
91
101
  }
92
102
 
93
103
  networkNamed(name) {
104
+ //console.log(this.toString(), name, this.#networks.keys());
94
105
  return this.#networks.get(name);
95
106
  }
96
107
 
@@ -197,3 +208,91 @@ export class Owner extends Base {
197
208
  };
198
209
  }
199
210
  }
211
+
212
+ export class Network extends Owner {
213
+ kind;
214
+ scope;
215
+ metric;
216
+ ipv4;
217
+ subnet;
218
+ bridge;
219
+
220
+ static get typeName() {
221
+ return "network";
222
+ }
223
+
224
+ constructor(owner, data) {
225
+ super(owner, data);
226
+
227
+ let bridge;
228
+ if (data.bridge) {
229
+ bridge = data.bridge;
230
+ delete data.bridge;
231
+ }
232
+
233
+ Object.assign(this, data);
234
+
235
+ const subnetAddress = this.subnetAddress;
236
+
237
+ if (subnetAddress) {
238
+ let subnet = owner.subnet(subnetAddress);
239
+ if (!subnet) {
240
+ subnet = new Subnet(owner, { name: subnetAddress });
241
+ }
242
+
243
+ this.subnet = subnet;
244
+ subnet.networks.add(this);
245
+ }
246
+
247
+ owner.addNetwork(this);
248
+
249
+ this.bridge = owner.addBridge(this, bridge);
250
+ }
251
+
252
+ get netmask() {
253
+ const m = this.ipv4?.match(/\/(\d+)$/);
254
+ if (m) {
255
+ return parseInt(m[1]);
256
+ }
257
+ }
258
+
259
+ get subnetAddress() {
260
+ if (this.ipv4) {
261
+ const [addr, bits] = this.ipv4.split(/\//);
262
+ const parts = addr.split(/\./);
263
+ return parts.slice(0, bits / 8).join(".");
264
+ }
265
+ }
266
+
267
+ get propertyNames() {
268
+ return [
269
+ ...super.propertyNames,
270
+ "kind",
271
+ "ipv4",
272
+ "netmask",
273
+ "scope",
274
+ "metric",
275
+ "bridge"
276
+ ];
277
+ }
278
+ }
279
+
280
+ export class Subnet extends Base {
281
+ networks = new Set();
282
+
283
+ static get typeName() {
284
+ return "subnet";
285
+ }
286
+
287
+ constructor(owner, data) {
288
+ super(owner, data);
289
+
290
+ Object.assign(this, data);
291
+
292
+ owner.addSubnet(this);
293
+ }
294
+
295
+ get address() {
296
+ return this.name;
297
+ }
298
+ }
package/src/service.mjs CHANGED
@@ -71,6 +71,7 @@ export class Service extends Base {
71
71
  if (this.#ipAddresses) {
72
72
  data.ipAddresses = this.#ipAddresses;
73
73
  }
74
+ // @ts-ignore
74
75
  return new this.constructor(owner, data);
75
76
  }
76
77
 
package/types/model.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export class World extends Owner {
2
2
  static get types(): {
3
- [k: string]: typeof DNSService | typeof Cluster | typeof Service | typeof Host | typeof Network | typeof Subnet;
3
+ [k: string]: typeof DNSService | typeof Network | typeof Subnet | typeof Cluster | typeof Service | typeof Host;
4
4
  };
5
5
  constructor(directory: any);
6
6
  get fullName(): string;
@@ -16,16 +16,6 @@ export class World extends Owner {
16
16
  export class Location extends Owner {
17
17
  get location(): this;
18
18
  }
19
- export class Network extends Owner {
20
- kind: any;
21
- scope: any;
22
- metric: any;
23
- ipv4: any;
24
- subnet: any;
25
- bridge: any;
26
- get netmask(): number;
27
- get subnetAddress(): any;
28
- }
29
19
  export class Host extends Base {
30
20
  static prepareData(world: any, data: any): Promise<typeof Host>;
31
21
  networkInterfaces: {};
@@ -81,12 +71,10 @@ export class NetworkInterface extends Base {
81
71
  get kind(): any;
82
72
  #private;
83
73
  }
84
- export class Subnet extends Base {
85
- networks: Set<any>;
86
- get address(): any;
87
- }
88
74
  import { Owner } from "./owner.mjs";
89
75
  import { DNSService } from "./dns.mjs";
76
+ import { Network } from "./owner.mjs";
77
+ import { Subnet } from "./owner.mjs";
90
78
  import { Cluster } from "./cluster.mjs";
91
79
  import { Service } from "./service.mjs";
92
80
  import { Base } from "./base.mjs";
package/types/owner.d.mts CHANGED
@@ -8,6 +8,7 @@ export class Owner extends Base {
8
8
  hosts(): AsyncGenerator<any, void, unknown>;
9
9
  addObject(object: any): void;
10
10
  addHost(host: any): void;
11
+ addCluster(cluster: any): void;
11
12
  service(filter: any): Promise<any>;
12
13
  services(filter: any): AsyncGenerator<any, void, unknown>;
13
14
  networkNamed(name: any): any;
@@ -27,5 +28,19 @@ export class Owner extends Base {
27
28
  };
28
29
  #private;
29
30
  }
31
+ export class Network extends Owner {
32
+ kind: any;
33
+ scope: any;
34
+ metric: any;
35
+ ipv4: any;
36
+ subnet: any;
37
+ bridge: any;
38
+ get netmask(): number;
39
+ get subnetAddress(): any;
40
+ }
41
+ export class Subnet extends Base {
42
+ networks: Set<any>;
43
+ get address(): any;
44
+ }
30
45
  import { Base } from "./base.mjs";
31
46
  import { DNSService } from "./dns.mjs";