pmcf 1.5.1 → 1.5.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.
@@ -5,18 +5,16 @@ import { join } from "node:path";
5
5
  import { writeLines, sectionLines } from "../src/model.mjs";
6
6
  import { prepare } from "../src/cmd.mjs";
7
7
 
8
- const { world, args } = prepare();
8
+ const { world, args, options } = prepare();
9
9
 
10
10
  const hostName = args[0];
11
11
 
12
12
  const host = await world.host(hostName);
13
13
 
14
- const targetDir = args[1] || `pkg/host-${host.hostName}`;
15
-
16
- await generateNetworkDefs(host, targetDir);
17
- await generateMachineInfo(host, targetDir);
18
- await copySshKeys(host, targetDir);
19
- await generateKnownHosts(world.hosts(), join(targetDir, "root", ".ssh"));
14
+ await generateNetworkDefs(host, options.output);
15
+ await generateMachineInfo(host, options.output);
16
+ await copySshKeys(host, options.output);
17
+ await generateKnownHosts(world.hosts(), join(options.output, "root", ".ssh"));
20
18
 
21
19
  console.log("provides", "host", ...host.provides);
22
20
  console.log("depends", `location-${host.location.name}`, ...host.depends);
@@ -5,12 +5,11 @@ import { join } from "node:path";
5
5
  import { writeLines, sectionLines } from "../src/model.mjs";
6
6
  import { prepare } from "../src/cmd.mjs";
7
7
 
8
- const { world, args } = prepare();
8
+ const { world, args, options } = prepare();
9
9
 
10
10
  const location = await world.location(args[0] || "SW");
11
- const targetDir = args[1];
12
11
 
13
- await generateLocationDefs(location, targetDir);
12
+ await generateLocationDefs(location, options.output);
14
13
 
15
14
  console.log(
16
15
  "provides",
@@ -5,10 +5,9 @@ import { createHmac } from "node:crypto";
5
5
  import { writeLines } from "../src/model.mjs";
6
6
  import { prepare } from "../src/cmd.mjs";
7
7
 
8
- const { world, args } = prepare();
8
+ const { world, args, options } = prepare();
9
9
 
10
10
  const location = await world.location(args[0] || "SW");
11
- const targetDir = args[1] || `pkg/mf-named-${location.name}`;
12
11
  const ttl = location.dnsRecordTTL;
13
12
  const updates = [
14
13
  Math.ceil(Date.now() / 1000),
@@ -20,7 +19,7 @@ const updates = [
20
19
 
21
20
  const NAME_LEN = 35;
22
21
 
23
- await generateNamedDefs(location, targetDir);
22
+ await generateNamedDefs(location, options.output);
24
23
 
25
24
  console.log("depends", "mf-named");
26
25
  console.log("replaces", "mf-named-zones");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -69,7 +69,7 @@ export class Base {
69
69
  return this.owner.host;
70
70
  }
71
71
 
72
- network(name) {
72
+ async network(name) {
73
73
  return this.owner.network(name);
74
74
  }
75
75
 
@@ -161,7 +161,7 @@ export class World {
161
161
 
162
162
  type = await type.prepareData(this, data);
163
163
  object = new type(owner, data);
164
- this.#byName.set(data.name, object);
164
+ this.#byName.set(object.name, object);
165
165
  }
166
166
 
167
167
  return object;
@@ -217,6 +217,7 @@ export class World {
217
217
  }
218
218
 
219
219
  addHost(host) {}
220
+ addNetwork(network) {}
220
221
  network(name) {}
221
222
 
222
223
  async *subnets() {
@@ -487,10 +488,6 @@ export class Location extends Base {
487
488
  }
488
489
  }
489
490
 
490
- async load() {
491
- for await (const host of this.owner.hosts());
492
- }
493
-
494
491
  async *hosts() {
495
492
  for await (const host of this.owner.hosts()) {
496
493
  if (host.location === this) {
@@ -525,12 +522,7 @@ export class Location extends Base {
525
522
  }
526
523
  }
527
524
 
528
- network(name) {
529
- return this.#networks.get(name);
530
- }
531
-
532
525
  async *networkAddresses() {
533
- await this.load();
534
526
  for await (const host of this.hosts()) {
535
527
  for (const networkAddresses of host.networkAddresses()) {
536
528
  yield networkAddresses;
@@ -538,15 +530,17 @@ export class Location extends Base {
538
530
  }
539
531
  }
540
532
 
533
+ async network(name) {
534
+ return this.#networks.get(name);
535
+ }
536
+
541
537
  async *networks() {
542
- await this.load();
543
538
  for (const network of this.#networks.values()) {
544
539
  yield network;
545
540
  }
546
541
  }
547
542
 
548
543
  async *subnets() {
549
- await this.load();
550
544
  for (const subnet of this.#subnets.values()) {
551
545
  yield subnet;
552
546
  }
@@ -562,6 +556,11 @@ export class Location extends Base {
562
556
  return network;
563
557
  }
564
558
 
559
+ if(data instanceof Network) {
560
+ this.#networks.set(data.name, data);
561
+ return data;
562
+ }
563
+
565
564
  network = new Network(this, data);
566
565
  this.#networks.set(data.name, network);
567
566
 
@@ -605,7 +604,7 @@ export class Location extends Base {
605
604
  }
606
605
 
607
606
  get propertyNames() {
608
- return [...super.propertyNames, "domain"];
607
+ return [...super.propertyNames, "domain" /*, "hosts"*/];
609
608
  }
610
609
 
611
610
  toJSON() {
@@ -640,6 +639,8 @@ export class Network extends Base {
640
639
  this.ipv4_netmask = m[1];
641
640
  }
642
641
  }
642
+
643
+ owner.addNetwork(this);
643
644
  }
644
645
 
645
646
  get subnetAddress() {
@@ -808,8 +809,13 @@ function extractFrom(object, propertyNames) {
808
809
  const json = {};
809
810
  for (const p of propertyNames) {
810
811
  const value = object[p];
812
+
811
813
  if (value !== undefined) {
812
- json[p] = value;
814
+ if (value instanceof Base) {
815
+ json[p] = { name: object.name };
816
+ } else {
817
+ json[p] = value;
818
+ }
813
819
  }
814
820
  }
815
821
  return json;
package/types/model.d.mts CHANGED
@@ -14,7 +14,7 @@ export class Base {
14
14
  get world(): any;
15
15
  get location(): any;
16
16
  get host(): any;
17
- network(name: any): any;
17
+ network(name: any): Promise<any>;
18
18
  set directory(directory: any);
19
19
  get directory(): any;
20
20
  expand(object: any): any;
@@ -40,6 +40,7 @@ export class World {
40
40
  location(name: any): Promise<any>;
41
41
  host(name: any): Promise<any>;
42
42
  addHost(host: any): void;
43
+ addNetwork(network: any): void;
43
44
  network(name: any): void;
44
45
  subnets(): AsyncGenerator<any, void, unknown>;
45
46
  networkAddresses(): AsyncGenerator<{
@@ -84,7 +85,6 @@ export class Model extends Host {
84
85
  export class Location extends Base {
85
86
  domain: any;
86
87
  dns: any;
87
- load(): Promise<void>;
88
88
  hosts(): AsyncGenerator<any, void, unknown>;
89
89
  service(filter: any): Promise<any>;
90
90
  services(filter: any): AsyncGenerator<any, void, unknown>;