pmcf 2.20.1 → 2.21.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "2.20.1",
3
+ "version": "2.21.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,7 +38,7 @@
38
38
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
39
39
  },
40
40
  "dependencies": {
41
- "ip-utilties": "^1.1.1",
41
+ "ip-utilties": "^1.2.0",
42
42
  "npm-pkgbuild": "^18.0.1",
43
43
  "pacc": "^3.4.0",
44
44
  "pkg-dir": "^8.0.0"
@@ -2,6 +2,7 @@ import { writeFile, mkdir } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { writeLines, sectionLines } from "../src/utils.mjs";
4
4
  import { addHook } from "./hooks.mjs";
5
+ import { cidrAddresses } from "./network-support.mjs";
5
6
 
6
7
  export async function generateMachineInfo(host, packageData) {
7
8
  const etcDir = join(packageData.dir, "etc");
@@ -40,7 +41,7 @@ export async function generateNetworkDefs(host, packageData) {
40
41
 
41
42
  const networkSections = [sectionLines("Match", { Name: ni.name })];
42
43
 
43
- for (const Address of ni.cidrAddresses) {
44
+ for (const Address of cidrAddresses(ni.networkAddresses())) {
44
45
  networkSections.push(
45
46
  "",
46
47
  sectionLines("Address", {
package/src/host.mjs CHANGED
@@ -435,16 +435,6 @@ export class Host extends Base {
435
435
  return [...this.networkAddresses()].map(na => na.address);
436
436
  }
437
437
 
438
- get cidrAddress() {
439
- return this.cidrAddresses[0];
440
- }
441
-
442
- get cidrAddresses() {
443
- return [...this.networkAddresses()].map(({ address, subnet }) =>
444
- formatCIDR(address, subnet.prefixLength)
445
- );
446
- }
447
-
448
438
  async publicKey(type = "ed25519") {
449
439
  return readFile(join(this.directory, `ssh_host_${type}_key.pub`), "utf8");
450
440
  }
package/src/module.mjs CHANGED
@@ -10,6 +10,7 @@ export * from "./root.mjs";
10
10
  export * from "./address.mjs";
11
11
  export * from "./subnet.mjs";
12
12
  export * from "./network.mjs";
13
+ export * from "./network-support.mjs";
13
14
  export * from "./network-interface.mjs";
14
15
  export * from "./host.mjs";
15
16
  export * from "./types.mjs";
@@ -3,7 +3,8 @@ import {
3
3
  isIPv6,
4
4
  formatCIDR,
5
5
  hasWellKnownSubnet,
6
- normalizeIP
6
+ normalizeIP,
7
+ familyIP
7
8
  } from "ip-utilties";
8
9
  import { Base } from "./base.mjs";
9
10
  import { Subnet } from "./subnet.mjs";
@@ -18,6 +19,7 @@ import { addType } from "./types.mjs";
18
19
  * @typedef {object} NetworkAddress
19
20
  * @property {NetworkInterface} networkInterface
20
21
  * @property {string|Uint8Array|Uint16Array} address
22
+ * @property {string} family
21
23
  * @property {Subnet} subnet
22
24
  * @property {Set<string>} domainNames
23
25
  */
@@ -72,62 +74,39 @@ class SkeletonNetworkInterface extends Base {
72
74
  }
73
75
 
74
76
  /**
75
- *
77
+ *
76
78
  * @param {object} filter
77
- * @return {Iterable<NetworkAddress>}
79
+ * @return {Iterable<NetworkAddress>}
78
80
  */
79
- *networkAddresses(filter=(n)=>true) {
81
+ *networkAddresses(filter = n => true) {
80
82
  for (const [address, subnet] of this.ipAddresses) {
81
83
  const networkAddress = {
82
84
  networkInterface: this,
83
85
  domainNames: this.domainNames,
84
86
  address,
87
+ family: familyIP(address),
85
88
  subnet
86
89
  };
87
90
 
88
- if(filter(networkAddress)) {
91
+ if (filter(networkAddress)) {
89
92
  yield networkAddress;
90
93
  }
91
94
  }
92
95
  }
93
96
 
94
- get rawAddress() {
95
- return this.rawAddresses[0];
96
- }
97
-
98
- get rawIPv4Address() {
99
- return this.rawAddresses.filter(a => isIPv4(a))[0];
100
- }
101
-
102
- get rawIPv6Address() {
103
- return this.rawAddresses.filter(a => isIPv6(a))[0];
97
+ networkAddress(filter) {
98
+ for (const a of this.networkAddresses(filter)) {
99
+ return a;
100
+ }
104
101
  }
105
102
 
106
- get cidrAddress() {
107
- return this.cidrAddresses[0];
103
+ get rawAddress() {
104
+ return this.rawAddresses[0];
108
105
  }
109
106
 
110
107
  get rawAddresses() {
111
108
  return [...this.ipAddresses].map(([address]) => address);
112
109
  }
113
-
114
- get rawIPv4Addresses() {
115
- return [...this.ipAddresses]
116
- .filter(([address]) => isIPv4(address))
117
- .map(([address]) => address);
118
- }
119
-
120
- get rawIPv6Addresses() {
121
- return [...this.ipAddresses]
122
- .filter(([address]) => isIPv6(address))
123
- .map(([address]) => address);
124
- }
125
-
126
- get cidrAddresses() {
127
- return [...this.ipAddresses].map(([address, subnet]) =>
128
- formatCIDR(address, subnet.prefixLength)
129
- );
130
- }
131
110
  }
132
111
 
133
112
  export const NetworkInterfaceTypeDefinition = {
@@ -1,3 +1,5 @@
1
+ import { formatCIDR } from "ip-utilties";
2
+
1
3
  export const networkProperties = {
2
4
  scope: {
3
5
  type: "string",
@@ -23,7 +25,12 @@ export const networkProperties = {
23
25
  metric: { type: "number", collection: false, writeable: true, default: 1004 },
24
26
  MTU: { type: "number", collection: false, writeable: true, default: 1500 },
25
27
  gateway: { type: "host", collection: false, writeable: true },
26
- multicastDNS: { type: "boolean", collection: false, writeable: true, default: false }
28
+ multicastDNS: {
29
+ type: "boolean",
30
+ collection: false,
31
+ writeable: true,
32
+ default: false
33
+ }
27
34
  };
28
35
 
29
36
  export const networkAddressProperties = {
@@ -33,3 +40,9 @@ export const networkAddressProperties = {
33
40
  rawAddresses: { type: "string", collection: true, writeable: false },
34
41
  rawAddress: { type: "string", collection: false, writeable: false }
35
42
  };
43
+
44
+ export function cidrAddresses(networkAddresses) {
45
+ return [...networkAddresses].map(na =>
46
+ formatCIDR(na.address, na.subnet.prefixLength)
47
+ );
48
+ }
@@ -209,7 +209,7 @@ export class DHCPService extends Service {
209
209
  .map(([k, networkInterface]) => {
210
210
  return {
211
211
  "hw-address": k,
212
- "ip-address": networkInterface.rawIPv4Address,
212
+ "ip-address": networkInterface.networkAddress(n => n.family === "IPv4").address,
213
213
  hostname: networkInterface.hostName
214
214
  };
215
215
  })
package/types/host.d.mts CHANGED
@@ -235,8 +235,6 @@ export class Host extends Base {
235
235
  networkAddresses(filter: any): Generator<any, void, any>;
236
236
  get rawAddress(): any;
237
237
  get rawAddresses(): any[];
238
- get cidrAddress(): any;
239
- get cidrAddresses(): any[];
240
238
  publicKey(type?: string): Promise<string>;
241
239
  preparePackages(dir: any): AsyncGenerator<{
242
240
  dir: any;
@@ -10,6 +10,7 @@ export * from "./root.mjs";
10
10
  export * from "./address.mjs";
11
11
  export * from "./subnet.mjs";
12
12
  export * from "./network.mjs";
13
+ export * from "./network-support.mjs";
13
14
  export * from "./network-interface.mjs";
14
15
  export * from "./host.mjs";
15
16
  export * from "./types.mjs";
@@ -688,6 +688,7 @@ export class LoopbackNetworkInterface extends SkeletonNetworkInterface {
688
688
  export type NetworkAddress = {
689
689
  networkInterface: NetworkInterface;
690
690
  address: string | Uint8Array | Uint16Array;
691
+ family: string;
691
692
  subnet: Subnet;
692
693
  domainNames: Set<string>;
693
694
  };
@@ -695,6 +696,7 @@ export type NetworkAddress = {
695
696
  * @typedef {object} NetworkAddress
696
697
  * @property {NetworkInterface} networkInterface
697
698
  * @property {string|Uint8Array|Uint16Array} address
699
+ * @property {string} family
698
700
  * @property {Subnet} subnet
699
701
  * @property {Set<string>} domainNames
700
702
  */
@@ -715,14 +717,9 @@ declare class SkeletonNetworkInterface extends Base {
715
717
  * @return {Iterable<NetworkAddress>}
716
718
  */
717
719
  networkAddresses(filter?: object): Iterable<NetworkAddress>;
720
+ networkAddress(filter: any): NetworkAddress;
718
721
  get rawAddress(): any;
719
- get rawIPv4Address(): any;
720
- get rawIPv6Address(): any;
721
- get cidrAddress(): any;
722
722
  get rawAddresses(): any[];
723
- get rawIPv4Addresses(): any[];
724
- get rawIPv6Addresses(): any[];
725
- get cidrAddresses(): any[];
726
723
  }
727
724
  import { Subnet } from "./subnet.mjs";
728
725
  import { Base } from "./base.mjs";
@@ -1,3 +1,4 @@
1
+ export function cidrAddresses(networkAddresses: any): any[];
1
2
  export namespace networkProperties {
2
3
  export namespace scope {
3
4
  export let type: string;