pmcf 1.42.0 → 1.42.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.42.0",
3
+ "version": "1.42.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -43,7 +43,7 @@
43
43
  "pacc": "^3.3.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/node": "^22.13.2",
46
+ "@types/node": "^22.13.4",
47
47
  "ava": "^6.2.0",
48
48
  "c8": "^10.1.3",
49
49
  "documentation": "^14.0.3",
package/src/base.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import { getAttribute } from "pacc";
3
3
  import { typesByName } from "./types.mjs";
4
+ import { asArray } from "./utils.mjs";
4
5
 
5
6
  export class Base {
6
7
  owner;
@@ -46,10 +47,15 @@ export class Base {
46
47
  constructor(owner, data) {
47
48
  this.owner = owner;
48
49
 
49
- if (data) {
50
- this.name = data.name;
51
- if (data.description) {
52
- this.description = data.description;
50
+ switch (typeof data) {
51
+ case "string":
52
+ this.name = data;
53
+ break;
54
+ case "object": {
55
+ this.name = data.name;
56
+ if (data.description) {
57
+ this.description = data.description;
58
+ }
53
59
  }
54
60
  }
55
61
  }
@@ -62,9 +68,15 @@ export class Base {
62
68
  if (slot) {
63
69
  delete data[slotName];
64
70
  if (typeDef.collection) {
65
- for (const [objectName, objectData] of Object.entries(slot)) {
66
- objectData.name = objectName;
67
- new typesByName[typeDef.type](this, objectData);
71
+ if (Array.isArray(slot) || typeof slot === "string") {
72
+ for (const item of asArray(slot)) {
73
+ new typesByName[typeDef.type](this, item);
74
+ }
75
+ } else {
76
+ for (const [objectName, objectData] of Object.entries(slot)) {
77
+ objectData.name = objectName;
78
+ new typesByName[typeDef.type](this, objectData);
79
+ }
68
80
  }
69
81
  } else {
70
82
  this[typeDef.type] = new typesByName[typeDef.type](this, slot);
package/src/network.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Owner } from "./owner.mjs";
2
- import { asArray } from "./utils.mjs";
2
+ import { Subnet } from "./subnet.mjs";
3
3
  import { addType } from "./types.mjs";
4
4
 
5
5
  export class Network extends Owner {
@@ -20,11 +20,6 @@ export class Network extends Owner {
20
20
  constructor(owner, data) {
21
21
  super(owner, data);
22
22
 
23
- if (data.subnets) {
24
- this.addSubnets(data.subnets);
25
- delete data.subnets;
26
- }
27
-
28
23
  if (data.bridge) {
29
24
  this.bridge = owner.addBridge(this, data.bridge);
30
25
  delete data.bridge;
@@ -48,10 +43,10 @@ export class Network extends Owner {
48
43
  return super.networkNamed(name);
49
44
  }
50
45
 
51
- addSubnets(value) {
52
- for (const address of asArray(value)) {
53
- const subnet = this.addSubnet(address);
54
- subnet.networks.add(this);
46
+ addObject(object) {
47
+ super.addObject(object);
48
+ if (object instanceof Subnet) {
49
+ object.networks.add(this);
55
50
  }
56
51
  }
57
52
 
@@ -60,32 +55,6 @@ export class Network extends Owner {
60
55
  }
61
56
 
62
57
  set bridge(bridge) {
63
- for (const network of bridge) {
64
- if (network instanceof Network && network !== this) {
65
- for (const subnet of this.subnets()) {
66
- for (const otherSubnet of network.subnets()) {
67
- if (
68
- subnet !== otherSubnet &&
69
- subnet.address === otherSubnet.address
70
- ) {
71
- /*console.log(
72
- "SHARE SUBNETS",
73
- subnet.owner.toString(),
74
- otherSubnet.owner.toString()
75
- );*/
76
-
77
- otherSubnet.owner.addObject(subnet);
78
- for (const n of otherSubnet.networks) {
79
- subnet.networks.add(n);
80
- }
81
-
82
- //console.log(subnet.toString(),[...subnet.networks].map(n=>n.toString()));
83
- }
84
- }
85
- }
86
- }
87
- }
88
-
89
58
  this.#bridge = bridge;
90
59
  }
91
60
 
package/src/owner.mjs CHANGED
@@ -23,7 +23,7 @@ export class Owner extends Base {
23
23
  networks: { type: "network", collection: true },
24
24
  hosts: { type: "host", collection: true },
25
25
  clusters: { type: "cluster", collection: true },
26
- /* subnets: { type: "subnet", collection: true },*/
26
+ subnets: { type: "subnet", collection: true },
27
27
  dns: { type: "dns", collection: false }
28
28
  };
29
29
  }
@@ -66,7 +66,6 @@ export class Owner extends Base {
66
66
  }
67
67
 
68
68
  named(name) {
69
- //console.log("NAMED", this.#membersByType.keys());
70
69
  for (const slot of this.#membersByType.values()) {
71
70
  const object = slot.get(name);
72
71
  if (object) {
@@ -106,9 +105,9 @@ export class Owner extends Base {
106
105
  this._addObject(object.typeName, object.fullName, object);
107
106
  }
108
107
 
109
- async service(filter) {
108
+ service(filter) {
110
109
  let best;
111
- for await (const service of this.services(filter)) {
110
+ for (const service of this.services(filter)) {
112
111
  if (!best || service.priority < best.priority) {
113
112
  best = service;
114
113
  }
@@ -117,9 +116,9 @@ export class Owner extends Base {
117
116
  return best;
118
117
  }
119
118
 
120
- async *services(filter) {
121
- for await (const host of this.hosts()) {
122
- for await (const service of host.services(filter)) {
119
+ *services(filter) {
120
+ for (const host of this.hosts()) {
121
+ for (const service of host.services(filter)) {
123
122
  yield service;
124
123
  }
125
124
  }
@@ -164,13 +163,7 @@ export class Owner extends Base {
164
163
  const { cidr } = normalizeCIDR(address);
165
164
 
166
165
  if (cidr) {
167
- let subnet = this.subnetNamed(cidr);
168
-
169
- if (!subnet) {
170
- subnet = new Subnet(this, { name: cidr });
171
- }
172
-
173
- return subnet;
166
+ return this.subnetNamed(cidr) || new Subnet(this, cidr);
174
167
  }
175
168
  }
176
169
 
@@ -229,7 +222,10 @@ export class Owner extends Base {
229
222
  _resolveBridges() {
230
223
  for (const bridge of this.#bridges) {
231
224
  //this.info(bridgeToJSON(bridge));
232
- for (const network of bridge) {
225
+
226
+ const subnets = new Map();
227
+
228
+ for (let network of bridge) {
233
229
  if (typeof network === "string") {
234
230
  const other = this.networkNamed(network);
235
231
 
@@ -237,16 +233,31 @@ export class Owner extends Base {
237
233
  bridge.delete(network);
238
234
  bridge.add(other);
239
235
  other.bridge = bridge;
236
+ network = other;
240
237
  } else {
241
238
  this.error(`Unresolvabale bridge network`, network);
242
239
  }
243
240
  }
241
+
242
+ // enshure only one subnet address in the bridge
243
+ for (const subnet of network.subnets()) {
244
+ const present = subnets.get(subnet.address);
245
+ if (present) {
246
+ subnet.owner.addObject(present);
247
+
248
+ for (const n of subnet.networks) {
249
+ present.networks.add(n);
250
+ }
251
+ } else {
252
+ subnets.set(subnet.address, subnet);
253
+ }
254
+ }
244
255
  }
245
256
  }
246
257
  }
247
258
 
248
- async *networkAddresses() {
249
- for await (const host of this.hosts()) {
259
+ *networkAddresses() {
260
+ for (const host of this.hosts()) {
250
261
  for (const networkAddresses of host.networkAddresses()) {
251
262
  yield networkAddresses;
252
263
  }
package/src/subnet.mjs CHANGED
@@ -13,20 +13,16 @@ export class Subnet extends Base {
13
13
  return "subnet";
14
14
  }
15
15
 
16
- constructor(owner, data) {
17
- const { cidr } = normalizeCIDR(data.name);
16
+ constructor(owner, address) {
17
+ const { cidr } = normalizeCIDR(address);
18
18
 
19
19
  if (!cidr) {
20
20
  const error = Error(`Invalid address`);
21
- error.address = data.name;
21
+ error.address = address;
22
22
  throw error;
23
23
  }
24
24
 
25
- data.name = cidr;
26
-
27
- super(owner, data);
28
-
29
- Object.assign(this, data);
25
+ super(owner, cidr);
30
26
 
31
27
  owner.addObject(this);
32
28
  }
@@ -7,7 +7,6 @@ export class Network extends Owner {
7
7
  set bridge(bridge: any);
8
8
  get bridge(): any;
9
9
  get network(): this;
10
- addSubnets(value: any): void;
11
10
  #private;
12
11
  }
13
12
  import { Owner } from "./owner.mjs";
package/types/owner.d.mts CHANGED
@@ -12,6 +12,10 @@ export class Owner extends Base {
12
12
  type: string;
13
13
  collection: boolean;
14
14
  };
15
+ subnets: {
16
+ type: string;
17
+ collection: boolean;
18
+ };
15
19
  dns: {
16
20
  type: string;
17
21
  collection: boolean;
@@ -29,8 +33,8 @@ export class Owner extends Base {
29
33
  typeList(typeName: any): any;
30
34
  _addObject(typeName: any, fullName: any, object: any): void;
31
35
  addObject(object: any): void;
32
- service(filter: any): Promise<any>;
33
- services(filter: any): AsyncGenerator<any, void, unknown>;
36
+ service(filter: any): any;
37
+ services(filter: any): Generator<any, void, unknown>;
34
38
  locationNamed(name: any): any;
35
39
  locations(): any;
36
40
  hostNamed(name: any): any;
@@ -45,7 +49,7 @@ export class Owner extends Base {
45
49
  clusters(): any;
46
50
  addBridge(network: any, destinationNetworks: any): any;
47
51
  _resolveBridges(): void;
48
- networkAddresses(): AsyncGenerator<any, void, unknown>;
52
+ networkAddresses(): Generator<any, void, unknown>;
49
53
  domains(): Generator<any, void, unknown>;
50
54
  #private;
51
55
  }