pmcf 1.19.0 → 1.20.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.19.0",
3
+ "version": "1.20.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -40,7 +40,7 @@
40
40
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "^22.10.9",
43
+ "@types/node": "^22.10.10",
44
44
  "ava": "^6.2.0",
45
45
  "c8": "^10.1.3",
46
46
  "documentation": "^14.0.3",
package/src/model.mjs CHANGED
@@ -87,7 +87,7 @@ export class Base {
87
87
  }
88
88
 
89
89
  get fullName() {
90
- return this.owner ? join(this.owner.fullName, this.name) : this.name;
90
+ return this.owner?.fullName ? join(this.owner.fullName, this.name) : this.name;
91
91
  }
92
92
 
93
93
  expand(object) {
@@ -114,6 +114,29 @@ export class Base {
114
114
  return object;
115
115
  }
116
116
 
117
+ #finalize;
118
+
119
+ finalize(action) {
120
+ if (!this.#finalize) {
121
+ this.#finalize = [];
122
+ }
123
+ this.#finalize.push(action);
124
+ }
125
+
126
+ execFinalize() {
127
+ if (this.#finalize) {
128
+ //this.info("finalize");
129
+ let i = 0;
130
+ for (const action of this.#finalize) {
131
+ if (action) {
132
+ this.#finalize[i] = undefined;
133
+ action();
134
+ }
135
+ i++;
136
+ }
137
+ }
138
+ }
139
+
117
140
  error(...args) {
118
141
  console.error(`${this.toString()}:`, ...args);
119
142
  }
@@ -166,6 +189,18 @@ export class Owner extends Base {
166
189
  }
167
190
  }
168
191
  Object.assign(this, data);
192
+
193
+ this.finalize(() => {
194
+ for (const network of this.#networks.values()) {
195
+ network.execFinalize();
196
+ }
197
+ });
198
+
199
+ this.finalize(() => {
200
+ for (const host of this.#hosts.values()) {
201
+ host.execFinalize();
202
+ }
203
+ });
169
204
  }
170
205
 
171
206
  get dns() {
@@ -248,7 +283,7 @@ export class Owner extends Base {
248
283
  other.bridge = bridge;
249
284
  } else {
250
285
  bridge.add(name);
251
- this.resolveLater(() => this._resolveBridges());
286
+ this.finalize(() => this._resolveBridges());
252
287
  }
253
288
  }
254
289
 
@@ -284,18 +319,6 @@ export class Owner extends Base {
284
319
  }
285
320
  }
286
321
 
287
- #resolveActions = [];
288
-
289
- resolveLater(action) {
290
- this.#resolveActions.push(action);
291
- }
292
-
293
- resolve() {
294
- for (const action of this.#resolveActions) {
295
- action();
296
- }
297
- }
298
-
299
322
  addSubnet(subnet) {
300
323
  this.#subnets.set(subnet.name, subnet);
301
324
  }
@@ -414,6 +437,8 @@ export class World extends Owner {
414
437
  await this.load(name, { type });
415
438
  }
416
439
  }
440
+
441
+ this.execFinalize();
417
442
  }
418
443
 
419
444
  addObject(object) {
@@ -676,6 +701,12 @@ export class Host extends Base {
676
701
  }
677
702
 
678
703
  owner.addHost(this);
704
+
705
+ this.finalize(() => {
706
+ for (const ni of Object.values(this.networkInterfaces)) {
707
+ ni.execFinalize();
708
+ }
709
+ });
679
710
  }
680
711
 
681
712
  get deployment() {
@@ -777,7 +808,7 @@ export class Host extends Base {
777
808
  addNetworkInterface(networkInterface) {
778
809
  this.networkInterfaces[networkInterface.name] = networkInterface;
779
810
 
780
- if(networkInterface.network) {
811
+ if (networkInterface.network) {
781
812
  networkInterface.network.addHost(this);
782
813
  }
783
814
  }
@@ -841,9 +872,9 @@ export class NetworkInterface extends Base {
841
872
  #metric;
842
873
  #ssid;
843
874
  #psk;
875
+ #network;
844
876
  arpbridge;
845
877
  hwaddr;
846
- network;
847
878
 
848
879
  constructor(owner, data) {
849
880
  super(owner, data);
@@ -866,18 +897,20 @@ export class NetworkInterface extends Base {
866
897
  }
867
898
 
868
899
  if (data.network) {
869
- const network = owner.owner.network(data.network);
900
+ let network = owner.owner.network(data.network);
870
901
 
871
902
  if (network) {
872
- data.network = network;
903
+ this.network = network;
873
904
  } else {
874
- this.error("Missing network", data.network);
905
+ network = data.network;
906
+ this.finalize(() => (this.network = network));
875
907
  }
908
+
909
+ delete data.network;
910
+ } else if (owner.owner instanceof Network) {
911
+ this.network = owner.owner;
876
912
  }
877
- else if(owner.owner instanceof Network) {
878
- data.network = owner.owner;
879
- }
880
-
913
+
881
914
  Object.assign(this, data);
882
915
 
883
916
  owner.addNetworkInterface(this);
@@ -885,6 +918,25 @@ export class NetworkInterface extends Base {
885
918
  //this.arpbridge = owner.addARPBridge(this, data.arpbridge);
886
919
  }
887
920
 
921
+ get network() {
922
+ return this.#network;
923
+ }
924
+
925
+ set network(networkOrName) {
926
+ if (!(networkOrName instanceof Network)) {
927
+ let network = this.owner.owner.network(networkOrName);
928
+
929
+ if (network) {
930
+ this.#network = network;
931
+ return;
932
+ } else {
933
+ this.error("Unknown network", networkOrName);
934
+ }
935
+ }
936
+
937
+ this.#network = networkOrName;
938
+ }
939
+
888
940
  get host() {
889
941
  return this.owner;
890
942
  }
package/types/model.d.mts CHANGED
@@ -19,6 +19,8 @@ export class Base {
19
19
  get directory(): any;
20
20
  get fullName(): any;
21
21
  expand(object: any): any;
22
+ finalize(action: any): void;
23
+ execFinalize(): void;
22
24
  error(...args: any[]): void;
23
25
  info(...args: any[]): void;
24
26
  toString(): string;
@@ -43,8 +45,6 @@ export class Owner extends Base {
43
45
  addBridge(network: any, destinationNetworks: any): any;
44
46
  _resolveBridges(): void;
45
47
  networkAddresses(): AsyncGenerator<any, void, unknown>;
46
- resolveLater(action: any): void;
47
- resolve(): void;
48
48
  addSubnet(subnet: any): void;
49
49
  subnet(name: any): any;
50
50
  subnets(): MapIterator<any>;
@@ -126,7 +126,8 @@ export class Host extends Base {
126
126
  export class NetworkInterface extends Base {
127
127
  arpbridge: any;
128
128
  hwaddr: any;
129
- network: any;
129
+ set network(networkOrName: any);
130
+ get network(): any;
130
131
  get scope(): any;
131
132
  get metric(): any;
132
133
  get ssid(): any;