pmcf 1.6.2 → 1.7.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.6.2",
3
+ "version": "1.7.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -168,7 +168,7 @@ export class Owner extends Base {
168
168
  this.#bridges.add(bridge);
169
169
  }
170
170
 
171
- for (const name of destinationNetworks) {
171
+ for (const name of asArray(destinationNetworks)) {
172
172
  bridge.add(this.network(name) || name);
173
173
  }
174
174
 
@@ -243,7 +243,7 @@ export class World extends Owner {
243
243
 
244
244
  type = await type.prepareData(this, data);
245
245
  object = new type(owner, data);
246
- this.#byName.set(object.name, object);
246
+ this.addObject(object);
247
247
  }
248
248
 
249
249
  return object;
@@ -259,6 +259,10 @@ export class World extends Owner {
259
259
  }
260
260
  }
261
261
 
262
+ addObject(object) {
263
+ this.#byName.set(object.name, object);
264
+ }
265
+
262
266
  async named(name) {
263
267
  await this.load();
264
268
  return this.#byName.get(name);
@@ -298,12 +302,6 @@ export class World extends Owner {
298
302
  return this._loadType(name, Host);
299
303
  }
300
304
 
301
- async *subnets() {
302
- for await (const location of this.locations()) {
303
- yield* location.subnets();
304
- }
305
- }
306
-
307
305
  async *networkAddresses() {
308
306
  for await (const host of this.hosts()) {
309
307
  for (const networkAddresses of host.networkAddresses()) {
@@ -411,10 +409,10 @@ export class Network extends Owner {
411
409
  constructor(owner, data) {
412
410
  super(owner, data);
413
411
 
414
- let bridges;
415
- if (data.bridges) {
416
- bridges = data.bridges;
417
- delete data.bridges;
412
+ let bridge;
413
+ if (data.bridge) {
414
+ bridge = data.bridge;
415
+ delete data.bridge;
418
416
  }
419
417
 
420
418
  Object.assign(this, data);
@@ -433,7 +431,7 @@ export class Network extends Owner {
433
431
 
434
432
  owner.addNetwork(this);
435
433
 
436
- this.bridge = owner.addBridge(this, bridges);
434
+ this.bridge = owner.addBridge(this, bridge);
437
435
  }
438
436
 
439
437
  get ipv4_netmask() {
@@ -844,3 +842,7 @@ function extractFrom(object, propertyNames) {
844
842
  function bridgeToJSON(bridge) {
845
843
  return [...bridge].map(n => n.name || `(${n})`).sort();
846
844
  }
845
+
846
+ function asArray(value) {
847
+ return Array.isArray(value) ? value : value === undefined ? [] : [value];
848
+ }
package/types/model.d.mts CHANGED
@@ -50,13 +50,13 @@ export class World extends Owner {
50
50
  get world(): this;
51
51
  _loadType(name: any, type: any): Promise<any>;
52
52
  load(): Promise<void>;
53
+ addObject(object: any): void;
53
54
  named(name: any): Promise<any>;
54
55
  locations(): AsyncGenerator<Location, void, unknown>;
55
56
  hosts(): AsyncGenerator<Host, void, unknown>;
56
57
  domains(): AsyncGenerator<any, void, unknown>;
57
58
  location(name: any): Promise<any>;
58
59
  host(name: any): Promise<any>;
59
- subnets(): AsyncGenerator<any, void, unknown>;
60
60
  networkAddresses(): AsyncGenerator<{
61
61
  address: any;
62
62
  networkInterface: any;