pmcf 1.42.2 → 1.43.1

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.
@@ -15,7 +15,7 @@ const host = await root.load(hostName, { type: Host });
15
15
  await generateNetworkDefs(host, options.output);
16
16
  await generateMachineInfo(host, options.output);
17
17
  await copySshKeys(host, options.output);
18
- await generateKnownHosts(root.hosts(), join(options.output, "root", ".ssh"));
18
+ await generateKnownHosts(host.owner.hosts(), join(options.output, "root", ".ssh"));
19
19
 
20
20
  console.log("provides", "host", ...host.provides);
21
21
  console.log("depends", `location-${host.location.name}`, ...host.depends);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.42.2",
3
+ "version": "1.43.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -9,19 +9,21 @@ export class Base {
9
9
  description;
10
10
 
11
11
  static get typeName() {
12
- return "base";
12
+ return this.typeDefinition.name;
13
13
  }
14
14
 
15
15
  static get typeDefinition() {
16
16
  return {
17
- // name: { type: "string", collection: false }
17
+ name: "base",
18
+ properties: {
19
+ /* name: { type: "string" },
20
+ description: { type: "string" },
21
+ directory: { type: "string" },
22
+ owner: {}*/
23
+ }
18
24
  };
19
25
  }
20
26
 
21
- static get pluralTypeName() {
22
- return this.typeName + "s";
23
- }
24
-
25
27
  static get nameLookupName() {
26
28
  return this.typeName + "Named";
27
29
  }
@@ -62,7 +64,7 @@ export class Base {
62
64
 
63
65
  read(data) {
64
66
  for (const [slotName, typeDef] of Object.entries(
65
- this.constructor.typeDefinition
67
+ this.constructor.typeDefinition.properties
66
68
  )) {
67
69
  const slot = data[slotName];
68
70
  if (slot) {
@@ -79,7 +81,9 @@ export class Base {
79
81
  }
80
82
  }
81
83
  } else {
82
- this[typeDef.type] = new typesByName[typeDef.type](this, slot);
84
+ // if (typeDef.type) {
85
+ this[typeDef.type] = new typesByName[typeDef.type](this, slot);
86
+ // }
83
87
  }
84
88
  }
85
89
  }
package/src/cluster.mjs CHANGED
@@ -6,8 +6,12 @@ export class Cluster extends Owner {
6
6
  addType(this);
7
7
  }
8
8
 
9
- static get typeName() {
10
- return "cluster";
9
+ static get typeDefinition() {
10
+ return {
11
+ name: "cluster",
12
+ extends: "owner",
13
+ properties: {}
14
+ };
11
15
  }
12
16
 
13
17
  constructor(owner, data) {
package/src/dns.mjs CHANGED
@@ -14,9 +14,19 @@ export class DNSService extends Base {
14
14
  static {
15
15
  addType(this);
16
16
  }
17
-
18
- static get typeName() {
19
- return "dns";
17
+
18
+ static get typeDefinition() {
19
+ return {
20
+ name: "dns",
21
+ properties: {
22
+ /*recordTTL: {},
23
+ soaUpdates: {},
24
+ hasSVRRecords: {},
25
+ hasCatalog: {},
26
+ forwardsTo: {},
27
+ allowedUpdates: {}*/
28
+ }
29
+ };
20
30
  }
21
31
 
22
32
  constructor(owner, data) {
package/src/host.mjs CHANGED
@@ -27,14 +27,21 @@ export class Host extends Base {
27
27
  addType(this);
28
28
  }
29
29
 
30
- static get typeName() {
31
- return "host";
32
- }
33
-
34
30
  static get typeDefinition() {
35
31
  return {
36
- networkInterfaces: { type: "network_interface", collection: true },
37
- services: { type: "service", collection: true }
32
+ name: "host",
33
+ extends: "base",
34
+ properties: {
35
+ networkInterfaces: { type: "network_interface", collection: true },
36
+ services: { type: "service", collection: true }
37
+ /*os: {},
38
+ distribution: {},
39
+ deployment: {},
40
+ master: { },
41
+ model: {},
42
+ replaces: { },
43
+ depends: { }*/
44
+ }
38
45
  };
39
46
  }
40
47
 
@@ -299,8 +306,24 @@ export class NetworkInterface extends Base {
299
306
  addType(this);
300
307
  }
301
308
 
302
- static get typeName() {
303
- return "network_interface";
309
+ static get typeDefinition() {
310
+ return {
311
+ name: "network_interface",
312
+ extends: "base",
313
+ properties: {
314
+ /*
315
+ arpbridge: {},
316
+ hwaddr: {},
317
+ network: {},
318
+ gateway: {},
319
+ ssid: {},
320
+ psk: {},
321
+ scope: {},
322
+ metric: {},
323
+ kind: {},
324
+ ipAddresses: {}*/
325
+ }
326
+ };
304
327
  }
305
328
 
306
329
  #ipAddresses = new Map();
@@ -379,7 +402,7 @@ export class NetworkInterface extends Base {
379
402
  subnetForAddress(address) {
380
403
  return (
381
404
  this.network?.subnetForAddress(address) ||
382
- this.owner.owner.subnetForAddress(address)
405
+ this.host.owner.subnetForAddress(address)
383
406
  );
384
407
  }
385
408
 
@@ -404,8 +427,8 @@ export class NetworkInterface extends Base {
404
427
  }
405
428
 
406
429
  get ipAddressesWithPrefixLength() {
407
- return [...this.ipAddresses].map(address =>
408
- this.addressWithPrefixLength(address)
430
+ return [...this.#ipAddresses].map(
431
+ ([address, subnet]) => `${address}/${subnet?.prefixLength}`
409
432
  );
410
433
  }
411
434
 
@@ -417,10 +440,6 @@ export class NetworkInterface extends Base {
417
440
  return [...this.ipAddresses].filter(a => isIPv6Address(a));
418
441
  }
419
442
 
420
- get prefixLength() {
421
- return this.network?.prefixLength;
422
- }
423
-
424
443
  get host() {
425
444
  return this.owner;
426
445
  }
package/src/location.mjs CHANGED
@@ -6,8 +6,18 @@ export class Location extends Owner {
6
6
  addType(this);
7
7
  }
8
8
 
9
- static get typeName() {
10
- return "location";
9
+ static get typeDefinition() {
10
+ return {
11
+ name: "location",
12
+ extends: "owner",
13
+ properties: {
14
+ networks: { type: "network", collection: true },
15
+ hosts: { type: "host", collection: true },
16
+ clusters: { type: "cluster", collection: true },
17
+ subnets: { type: "subnet", collection: true },
18
+ dns: { type: "dns", collection: false }
19
+ }
20
+ };
11
21
  }
12
22
 
13
23
  get location() {
package/src/network.mjs CHANGED
@@ -13,8 +13,24 @@ export class Network extends Owner {
13
13
  addType(this);
14
14
  }
15
15
 
16
- static get typeName() {
17
- return "network";
16
+ static get typeDefinition() {
17
+ return {
18
+ name: "network",
19
+ extends: "owner",
20
+ properties: {
21
+ networks: { type: "network", collection: true },
22
+ hosts: { type: "host", collection: true },
23
+ clusters: { type: "cluster", collection: true },
24
+ subnets: { type: "subnet", collection: true },
25
+ dns: { type: "dns", collection: false }
26
+
27
+ /* kind: {},
28
+ scope: {},
29
+ metric: {},
30
+ bridge: {},
31
+ gateway: {}*/
32
+ }
33
+ };
18
34
  }
19
35
 
20
36
  constructor(owner, data) {
package/src/owner.mjs CHANGED
@@ -14,17 +14,17 @@ export class Owner extends Base {
14
14
  addType(this);
15
15
  }
16
16
 
17
- static get typeName() {
18
- return "owner";
19
- }
20
-
21
17
  static get typeDefinition() {
22
18
  return {
23
- networks: { type: "network", collection: true },
24
- hosts: { type: "host", collection: true },
25
- clusters: { type: "cluster", collection: true },
26
- subnets: { type: "subnet", collection: true },
27
- dns: { type: "dns", collection: false }
19
+ name: "owner",
20
+ extends: "base",
21
+ properties: {
22
+ networks: { type: "network", collection: true },
23
+ hosts: { type: "host", collection: true },
24
+ clusters: { type: "cluster", collection: true },
25
+ subnets: { type: "subnet", collection: true },
26
+ dns: { type: "dns", collection: false }
27
+ }
28
28
  };
29
29
  }
30
30
 
@@ -165,6 +165,16 @@ export class Owner extends Base {
165
165
  if (cidr) {
166
166
  return this.subnetNamed(cidr) || new Subnet(this, cidr);
167
167
  }
168
+
169
+ const subnets = [...this.subnets()];
170
+ if (subnets.length === 1) {
171
+ return subnets[0];
172
+ }
173
+
174
+ this.error(
175
+ `Address without subnet ${address}`,
176
+ [...this.subnets()].map(s => s.address)
177
+ );
168
178
  }
169
179
 
170
180
  subnetForAddress(address) {
package/src/root.mjs CHANGED
@@ -10,8 +10,13 @@ export class Root extends Location {
10
10
  addType(this);
11
11
  }
12
12
 
13
- static get typeName() {
14
- return "root";
13
+ static get typeDefinition() {
14
+ return {
15
+ name: "root",
16
+ extends: "location",
17
+ properties: {
18
+ }
19
+ };
15
20
  }
16
21
 
17
22
  constructor(directory) {
package/src/service.mjs CHANGED
@@ -26,8 +26,22 @@ export class Service extends Base {
26
26
  addType(this);
27
27
  }
28
28
 
29
- static get typeName() {
30
- return "service";
29
+ static get typeDefinition() {
30
+ return {
31
+ name: "service",
32
+ extends: "base",
33
+ properties: {
34
+ /*ipAddresses: {},
35
+ addresses: {},
36
+ port: {},
37
+ protocol: {},
38
+ alias: {},
39
+ type: {},
40
+ master: {},
41
+ priority: {},
42
+ weight: {}*/
43
+ }
44
+ };
31
45
  }
32
46
 
33
47
  constructor(owner, data) {
package/src/subnet.mjs CHANGED
@@ -9,8 +9,18 @@ export class Subnet extends Base {
9
9
  addType(this);
10
10
  }
11
11
 
12
- static get typeName() {
13
- return "subnet";
12
+ static get typeDefinition() {
13
+ return {
14
+ name: "subnet",
15
+ extends: "base",
16
+ properties: {
17
+ /*
18
+ address: {},
19
+ networks: { type: "network", collection true },
20
+ prefixLength: { type: "number", writeable: false }
21
+ */
22
+ }
23
+ };
14
24
  }
15
25
 
16
26
  constructor(owner, address) {
package/src/types.mjs CHANGED
@@ -1,6 +1,10 @@
1
1
  export function addType(clazz) {
2
2
  types.push(clazz);
3
- typesByName[clazz.typeName] = clazz;
3
+
4
+ const typeDefinition = clazz.typeDefinition;
5
+ typeDefinition.clazz = clazz;
6
+
7
+ typesByName[typeDefinition.name] = clazz;
4
8
  }
5
9
 
6
10
  export const types = [];
package/src/utils.mjs CHANGED
@@ -137,15 +137,23 @@ export function normalizeCIDR(address) {
137
137
  prefix = "fe80::";
138
138
  prefixLength = 64;
139
139
  } else {
140
+ const definition = isIPv4Address(prefix) ? ipv4 : ipv6;
141
+ let n = _encode(definition, prefix);
142
+
140
143
  if (prefixLength) {
141
- const definition = isIPv4Address(prefix) ? ipv4 : ipv6;
142
- let n = _encode(definition, prefix);
143
144
  n = n & (definition.mask << BigInt(definition.length - prefixLength));
144
145
  prefix = _decode(definition, n, prefixLength);
145
146
  } else {
146
- return {};
147
+ if (n === IPV4_LOCALHOST) {
148
+ prefixLength = 8;
149
+ prefix = _decode(definition, n, prefixLength);
150
+ } else {
151
+ return {};
152
+ }
147
153
  }
148
154
  }
149
155
 
150
156
  return { prefix, prefixLength, cidr: `${prefix}/${prefixLength}` };
151
157
  }
158
+
159
+ const IPV4_LOCALHOST = _encode(ipv4,'127.0.0.1')
package/types/base.d.mts CHANGED
@@ -1,8 +1,10 @@
1
1
  export function extractFrom(object: any): {};
2
2
  export class Base {
3
3
  static get typeName(): string;
4
- static get typeDefinition(): {};
5
- static get pluralTypeName(): string;
4
+ static get typeDefinition(): {
5
+ name: string;
6
+ properties: {};
7
+ };
6
8
  static get nameLookupName(): string;
7
9
  static get typeFileName(): string;
8
10
  static get fileNameGlob(): string;
@@ -1,4 +1,9 @@
1
1
  export class Cluster extends Owner {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: string;
5
+ properties: {};
6
+ };
2
7
  constructor(owner: any, data: any);
3
8
  }
4
9
  import { Owner } from "./owner.mjs";
package/types/host.d.mts CHANGED
@@ -1,12 +1,16 @@
1
1
  export class Host extends Base {
2
2
  static get typeDefinition(): {
3
- networkInterfaces: {
4
- type: string;
5
- collection: boolean;
6
- };
7
- services: {
8
- type: string;
9
- collection: boolean;
3
+ name: string;
4
+ extends: string;
5
+ properties: {
6
+ networkInterfaces: {
7
+ type: string;
8
+ collection: boolean;
9
+ };
10
+ services: {
11
+ type: string;
12
+ collection: boolean;
13
+ };
10
14
  };
11
15
  };
12
16
  static prepareData(root: any, data: any): Promise<typeof Host>;
@@ -52,6 +56,11 @@ export class Host extends Base {
52
56
  #private;
53
57
  }
54
58
  export class NetworkInterface extends Base {
59
+ static get typeDefinition(): {
60
+ name: string;
61
+ extends: string;
62
+ properties: {};
63
+ };
55
64
  arpbridge: any;
56
65
  hwaddr: any;
57
66
  set network(networkOrName: any);
@@ -66,7 +75,6 @@ export class NetworkInterface extends Base {
66
75
  get ipAddressesWithPrefixLength(): string[];
67
76
  get ipv4Addresses(): any[];
68
77
  get ipv6Addresses(): any[];
69
- get prefixLength(): any;
70
78
  get scope(): any;
71
79
  get metric(): any;
72
80
  get ssid(): any;
package/types/owner.d.mts CHANGED
@@ -1,24 +1,28 @@
1
1
  export class Owner extends Base {
2
2
  static get typeDefinition(): {
3
- networks: {
4
- type: string;
5
- collection: boolean;
6
- };
7
- hosts: {
8
- type: string;
9
- collection: boolean;
10
- };
11
- clusters: {
12
- type: string;
13
- collection: boolean;
14
- };
15
- subnets: {
16
- type: string;
17
- collection: boolean;
18
- };
19
- dns: {
20
- type: string;
21
- collection: boolean;
3
+ name: string;
4
+ extends: string;
5
+ properties: {
6
+ networks: {
7
+ type: string;
8
+ collection: boolean;
9
+ };
10
+ hosts: {
11
+ type: string;
12
+ collection: boolean;
13
+ };
14
+ clusters: {
15
+ type: string;
16
+ collection: boolean;
17
+ };
18
+ subnets: {
19
+ type: string;
20
+ collection: boolean;
21
+ };
22
+ dns: {
23
+ type: string;
24
+ collection: boolean;
25
+ };
22
26
  };
23
27
  };
24
28
  constructor(owner: any, data?: {});
package/types/root.d.mts CHANGED
@@ -1,4 +1,9 @@
1
1
  export class Root extends Location {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: string;
5
+ properties: {};
6
+ };
2
7
  constructor(directory: any);
3
8
  get fullName(): string;
4
9
  get root(): this;
@@ -1,4 +1,9 @@
1
1
  export class Service extends Base {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: string;
5
+ properties: {};
6
+ };
2
7
  alias: any;
3
8
  get protocol(): any;
4
9
  get srvPrefix(): string;
@@ -1,4 +1,9 @@
1
1
  export class Subnet extends Base {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: string;
5
+ properties: {};
6
+ };
2
7
  networks: Set<any>;
3
8
  matchesAddress(address: any): any;
4
9
  get isLinkLocal(): any;