pmcf 1.59.0 → 1.59.2

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.59.0",
3
+ "version": "1.59.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -203,8 +203,22 @@ export class Base {
203
203
  }
204
204
  }
205
205
 
206
+ named(name)
207
+ {
208
+ }
209
+
206
210
  typeNamed(typeName, name) {
207
- return this.owner?.typeNamed(typeName, name);
211
+ if (this.owner) {
212
+ const object = this.owner.typeNamed(typeName, name); // TODO split
213
+ if(object) {
214
+ return object;
215
+ }
216
+ }
217
+
218
+ const object = this.named(name);
219
+ if(object?.typeName === typeName) {
220
+ return object;
221
+ }
208
222
  }
209
223
 
210
224
  addObject(object) {
package/src/cluster.mjs CHANGED
@@ -15,8 +15,8 @@ const ClusterTypeDefinition = {
15
15
  };
16
16
 
17
17
  export class Cluster extends Owner {
18
- masters = new Set();
19
- backups = new Set();
18
+ #masters = new Set();
19
+ #backups = new Set();
20
20
 
21
21
  static {
22
22
  addType(this);
@@ -31,6 +31,26 @@ export class Cluster extends Owner {
31
31
  this.read(data, ClusterTypeDefinition);
32
32
  }
33
33
 
34
+ set masters(value)
35
+ {
36
+ this.#masters.add(value);
37
+ }
38
+
39
+ get masters()
40
+ {
41
+ return this.#masters;
42
+ }
43
+
44
+ set backups(value)
45
+ {
46
+ this.#backups.add(value);
47
+ }
48
+
49
+ get backups()
50
+ {
51
+ return this.#backups;
52
+ }
53
+
34
54
  get packageName() {
35
55
  return `${this.constructor.typeDefinition.name}-${this.owner.name}-${this.name}`;
36
56
  }
@@ -51,7 +71,7 @@ export class Cluster extends Owner {
51
71
  " auth_pass pass1234",
52
72
  " }",
53
73
  " virtual_ipaddress {",
54
- " 192.168.1.250",
74
+ ` ${ni.rawAddress}`,
55
75
  " }",
56
76
  "}"
57
77
  ];
package/src/host.mjs CHANGED
@@ -431,6 +431,10 @@ export class NetworkInterface extends Base {
431
431
  }
432
432
  }
433
433
 
434
+ get rawAddress() {
435
+ return this.rawAddresses[0];
436
+ }
437
+
434
438
  get rawAddresses() {
435
439
  return [...this.#ipAddresses].map(([address]) => address);
436
440
  }
package/src/owner.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { asArray, normalizeCIDR } from "./utils.mjs";
1
+ import { asIterator, normalizeCIDR } from "./utils.mjs";
2
2
  import { Base } from "./base.mjs";
3
3
  import { Subnet } from "./subnet.mjs";
4
4
  import { addType } from "./types.mjs";
@@ -90,17 +90,17 @@ export class Owner extends Base {
90
90
  }
91
91
 
92
92
  typeNamed(typeName, name) {
93
- const localName = name[0] === "/" ? name.substring(this.fullName.length + 1) : name;
94
-
95
93
  const typeSlot = this.#membersByType.get(typeName);
96
94
  if (typeSlot) {
97
- const object = typeSlot.get(localName);
95
+ const object = typeSlot.get(
96
+ name[0] === "/" ? name.substring(this.fullName.length + 1) : name
97
+ );
98
98
  if (object) {
99
99
  return object;
100
100
  }
101
101
  }
102
102
 
103
- return super.typeNamed(typeName, localName); // TODO use name
103
+ return super.typeNamed(typeName, name);
104
104
  }
105
105
 
106
106
  typeObject(typeName) {
@@ -223,13 +223,15 @@ export class Owner extends Base {
223
223
  this.#bridges.add(bridge);
224
224
  }
225
225
 
226
- for (const name of asArray(destinationNetworks)) {
227
- const other = this.networkNamed(name);
226
+ for (const nameOrNetwork of asIterator(destinationNetworks)) {
227
+ const other = nameOrNetwork instanceof Owner ? nameOrNetwork : this.networkNamed(nameOrNetwork);
228
228
  if (other) {
229
- bridge.add(other);
230
- other.bridge = bridge;
229
+ if (!bridge.has(other)) {
230
+ bridge.add(other);
231
+ other.bridge = bridge;
232
+ }
231
233
  } else {
232
- bridge.add(name);
234
+ bridge.add(nameOrNetwork);
233
235
  this.finalize(() => this._resolveBridges());
234
236
  }
235
237
  }
package/src/utils.mjs CHANGED
@@ -33,6 +33,17 @@ export function asArray(value) {
33
33
  return Array.isArray(value) ? value : value === undefined ? [] : [value];
34
34
  }
35
35
 
36
+ export function asIterator(value)
37
+ {
38
+ if(value === undefined) { return []; }
39
+
40
+ if(typeof value[Symbol.iterator] === 'function') {
41
+ return value;
42
+ }
43
+
44
+ return asArray(value);
45
+ }
46
+
36
47
  export function isIPv4Address(address) {
37
48
  return address.indexOf(".") >= 0;
38
49
  }
package/types/base.d.mts CHANGED
@@ -46,6 +46,7 @@ export class Base {
46
46
  name: string;
47
47
  ownerFor(property: any, data: any): any;
48
48
  read(data: any, type: any): void;
49
+ named(name: any): void;
49
50
  typeNamed(typeName: any, name: any): any;
50
51
  addObject(object: any): any;
51
52
  forOwner(owner: any): any;
@@ -371,7 +371,10 @@ export class Cluster extends Owner {
371
371
  };
372
372
  };
373
373
  };
374
- masters: Set<any>;
375
- backups: Set<any>;
374
+ set masters(value: Set<any>);
375
+ get masters(): Set<any>;
376
+ set backups(value: Set<any>);
377
+ get backups(): Set<any>;
378
+ #private;
376
379
  }
377
380
  import { Owner } from "./owner.mjs";
package/types/host.d.mts CHANGED
@@ -310,6 +310,7 @@ export class NetworkInterface extends Base {
310
310
  addSubnet(address: any): any;
311
311
  set ipAddresses(value: Map<any, any>);
312
312
  get ipAddresses(): Map<any, any>;
313
+ get rawAddress(): any;
313
314
  get rawAddresses(): any[];
314
315
  get cidrAddresses(): any[];
315
316
  get rawIPv4Addresses(): any[];
package/types/utils.d.mts CHANGED
@@ -2,6 +2,7 @@ export function writeLines(dir: any, name: any, lines: any): Promise<void>;
2
2
  export function sectionLines(sectionName: any, values: any): string[];
3
3
  export function bridgeToJSON(bridge: any): any[];
4
4
  export function asArray(value: any): any[];
5
+ export function asIterator(value: any): any;
5
6
  export function isIPv4Address(address: any): boolean;
6
7
  export function isIPv6Address(address: any): boolean;
7
8
  export function isLinkLocal(address: any): any;