pmcf 1.6.3 → 1.8.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.3",
3
+ "version": "1.8.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -103,6 +103,10 @@ export class Base {
103
103
  error(...args) {
104
104
  console.error(`${this.toString()}:`, ...args);
105
105
  }
106
+
107
+ info(...args) {
108
+ console.info(`${this.toString()}:`, ...args);
109
+ }
106
110
 
107
111
  toString() {
108
112
  return this.typeName + ":" + (this.owner?.name || "") + "/" + this.name;
@@ -168,14 +172,53 @@ export class Owner extends Base {
168
172
  this.#bridges.add(bridge);
169
173
  }
170
174
 
171
- for (const name of destinationNetworks) {
172
- bridge.add(this.network(name) || name);
175
+ for (const name of asArray(destinationNetworks)) {
176
+ const other = this.network(name);
177
+ if (other) {
178
+ bridge.add(other);
179
+ other.bridge = bridge;
180
+ } else {
181
+ bridge.add(name);
182
+ this.resolveLater(() => this._resolveBridges());
183
+ }
173
184
  }
174
185
 
175
186
  return bridge;
176
187
  }
177
188
  }
178
189
 
190
+ _resolveBridges() {
191
+ for (const bridge of this.#bridges) {
192
+ console.log(bridgeToJSON(bridge));
193
+ for (const network of bridge) {
194
+ if (typeof network === "string") {
195
+ const other = this.network(network);
196
+
197
+ if (other) {
198
+ bridge.delete(network);
199
+ bridge.add(other);
200
+ other.bridge = bridge;
201
+ console.log("RESOLVE", network, other, bridgeToJSON(bridge));
202
+ } else {
203
+ this.error(`Unresolvabale bridge network`, network);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ #resolveActions = [];
211
+
212
+ resolveLater(action) {
213
+ this.#resolveActions.push(action);
214
+ }
215
+
216
+ resolve() {
217
+ for (const action of this.#resolveActions) {
218
+ action();
219
+ }
220
+ }
221
+
179
222
  addSubnet(subnet) {
180
223
  this.#subnets.set(subnet.name, subnet);
181
224
  }
@@ -409,10 +452,10 @@ export class Network extends Owner {
409
452
  constructor(owner, data) {
410
453
  super(owner, data);
411
454
 
412
- let bridges;
413
- if (data.bridges) {
414
- bridges = data.bridges;
415
- delete data.bridges;
455
+ let bridge;
456
+ if (data.bridge) {
457
+ bridge = data.bridge;
458
+ delete data.bridge;
416
459
  }
417
460
 
418
461
  Object.assign(this, data);
@@ -431,7 +474,7 @@ export class Network extends Owner {
431
474
 
432
475
  owner.addNetwork(this);
433
476
 
434
- this.bridge = owner.addBridge(this, bridges);
477
+ this.bridge = owner.addBridge(this, bridge);
435
478
  }
436
479
 
437
480
  get ipv4_netmask() {
@@ -842,3 +885,7 @@ function extractFrom(object, propertyNames) {
842
885
  function bridgeToJSON(bridge) {
843
886
  return [...bridge].map(n => n.name || `(${n})`).sort();
844
887
  }
888
+
889
+ function asArray(value) {
890
+ return Array.isArray(value) ? value : value === undefined ? [] : [value];
891
+ }
package/types/model.d.mts CHANGED
@@ -19,6 +19,7 @@ export class Base {
19
19
  get directory(): any;
20
20
  expand(object: any): any;
21
21
  error(...args: any[]): void;
22
+ info(...args: any[]): void;
22
23
  toString(): string;
23
24
  get propertyNames(): string[];
24
25
  toJSON(): {};
@@ -31,6 +32,9 @@ export class Owner extends Base {
31
32
  networks(): AsyncGenerator<any, void, unknown>;
32
33
  addNetwork(network: any): void;
33
34
  addBridge(network: any, destinationNetworks: any): any;
35
+ _resolveBridges(): void;
36
+ resolveLater(action: any): void;
37
+ resolve(): void;
34
38
  addSubnet(subnet: any): void;
35
39
  subnet(name: any): any;
36
40
  subnets(): MapIterator<any>;