pmcf 1.6.0 → 1.6.1

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.6.0",
3
+ "version": "1.6.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -117,6 +117,7 @@ export class Owner extends Base {
117
117
  #hosts = new Map();
118
118
  #networks = new Map();
119
119
  #subnets = new Map();
120
+ #bridges = new Set();
120
121
 
121
122
  async *hosts() {
122
123
  for (const host of this.#hosts.values()) {
@@ -142,6 +143,46 @@ export class Owner extends Base {
142
143
  this.#networks.set(network.name, network);
143
144
  }
144
145
 
146
+ addBridge(network, destinationNetworks) {
147
+ console.log(
148
+ "BRIDGE",
149
+ network.name,
150
+ destinationNetworks.map(n => (this.network(n) ? n : `(${n})`))
151
+ );
152
+
153
+ let bridge;
154
+
155
+ for (bridge of this.#bridges) {
156
+ if (bridge.has(network.name)) {
157
+ bridge.delete(network.name);
158
+ bridge.add(network);
159
+
160
+ console.log(
161
+ "REPLACE",
162
+ network.name,
163
+ [...bridge].map(n => n.name||`(${n})`)
164
+ );
165
+
166
+ break;
167
+ }
168
+
169
+ if (bridge.has(network)) {
170
+ break;
171
+ }
172
+ }
173
+
174
+ if (!bridge) {
175
+ bridge = new Set([network]);
176
+ this.#bridges.add(bridge);
177
+ }
178
+
179
+ for (const name of destinationNetworks) {
180
+ bridge.add(this.network(name) || name);
181
+ }
182
+
183
+ return bridge;
184
+ }
185
+
145
186
  addSubnet(subnet) {
146
187
  this.#subnets.set(subnet.name, subnet);
147
188
  }
@@ -159,6 +200,7 @@ export class Owner extends Base {
159
200
  ...super.toJSON(),
160
201
  networks: [...this.#networks.keys()].sort(),
161
202
  subnets: [...this.#subnets.keys()].sort(),
203
+ bridges: [...this.#bridges.keys()].sort(),
162
204
  hosts: [...this.#hosts.keys()].sort()
163
205
  };
164
206
  }
@@ -299,22 +341,6 @@ export class Location extends Owner {
299
341
  data.name = name;
300
342
  new Network(this, data);
301
343
  }
302
-
303
- /*
304
- for (const network of this.#networks.values()) {
305
- if (network.bridges) {
306
- network.bridges = new Set(
307
- network.bridges.map(b => {
308
- const n = this.network(b);
309
- if (!n) {
310
- console.error(`No network named ${b}`);
311
- }
312
- return n;
313
- })
314
- );
315
- }
316
- }
317
- */
318
344
  }
319
345
  }
320
346
 
@@ -383,6 +409,7 @@ export class Network extends Owner {
383
409
  metric;
384
410
  ipv4;
385
411
  subnet;
412
+ bridge;
386
413
 
387
414
  static get typeName() {
388
415
  return "network";
@@ -391,6 +418,12 @@ export class Network extends Owner {
391
418
  constructor(owner, data) {
392
419
  super(owner, data);
393
420
 
421
+ let bridges;
422
+ if (data.bridges) {
423
+ bridges = data.bridges;
424
+ delete data.bridges;
425
+ }
426
+
394
427
  Object.assign(this, data);
395
428
 
396
429
  const subnetAddress = this.subnetAddress;
@@ -406,6 +439,10 @@ export class Network extends Owner {
406
439
  }
407
440
 
408
441
  owner.addNetwork(this);
442
+
443
+ if (bridges) {
444
+ this.bridge = owner.addBridge(this, bridges);
445
+ }
409
446
  }
410
447
 
411
448
  get ipv4_netmask() {
@@ -424,7 +461,14 @@ export class Network extends Owner {
424
461
  }
425
462
 
426
463
  get propertyNames() {
427
- return [...super.propertyNames, "kind", "ipv4", "scope", "metric"];
464
+ return [
465
+ ...super.propertyNames,
466
+ "kind",
467
+ "ipv4",
468
+ "scope",
469
+ "metric",
470
+ "bridge"
471
+ ];
428
472
  }
429
473
  }
430
474
 
package/types/model.d.mts CHANGED
@@ -29,12 +29,14 @@ export class Owner extends Base {
29
29
  network(name: any): any;
30
30
  networks(): AsyncGenerator<any, void, unknown>;
31
31
  addNetwork(network: any): void;
32
+ addBridge(network: any, destinationNetworks: any): any;
32
33
  addSubnet(subnet: any): void;
33
34
  subnet(name: any): any;
34
35
  subnets(): MapIterator<any>;
35
36
  toJSON(): {
36
37
  networks: any[];
37
38
  subnets: any[];
39
+ bridges: any[];
38
40
  hosts: any[];
39
41
  };
40
42
  #private;
@@ -77,6 +79,7 @@ export class Network extends Owner {
77
79
  metric: any;
78
80
  ipv4: any;
79
81
  subnet: any;
82
+ bridge: any;
80
83
  get ipv4_netmask(): any;
81
84
  get subnetAddress(): any;
82
85
  }