pmcf 1.46.1 → 1.46.3

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.
@@ -4,7 +4,7 @@ import { join } from "node:path";
4
4
  import { createHmac } from "node:crypto";
5
5
  import {
6
6
  writeLines,
7
- isIPv4Address,
7
+ isIPv6Address,
8
8
  normalizeIPAddress
9
9
  } from "../src/utils.mjs";
10
10
  import { prepare } from "../src/cmd.mjs";
@@ -58,17 +58,7 @@ async function generateNamedDefs(owner, targetDir) {
58
58
  );
59
59
  }
60
60
 
61
- const subnets = [
62
- ...new Set([...owner.networks()].map(n => [...n.subnets()]).flat())
63
- ];
64
-
65
- console.log(
66
- owner.fullName,
67
- domain,
68
- nameserver?.hostName,
69
- rname,
70
- subnets.map(s => `${s.owner.name}/${s.name}`)
71
- );
61
+ console.log(owner.fullName, domain, nameserver?.hostName, rname);
72
62
  const reverseZones = new Map();
73
63
 
74
64
  const SOARecord = createRecord(
@@ -99,6 +89,7 @@ async function generateNamedDefs(owner, targetDir) {
99
89
  zones.push(zone);
100
90
 
101
91
  const hosts = new Set();
92
+ const addresses = new Set();
102
93
 
103
94
  for await (const {
104
95
  address,
@@ -107,14 +98,19 @@ async function generateNamedDefs(owner, targetDir) {
107
98
  } of owner.networkAddresses()) {
108
99
  const host = networkInterface.host;
109
100
 
110
- if (!hosts.has(host)) {
101
+ if (!addresses.has(address)) {
102
+ addresses.add(address);
103
+
111
104
  zone.records.add(
112
105
  createRecord(
113
106
  fullName(host.domainName),
114
- isIPv4Address(address) ? "A" : "AAAA",
107
+ isIPv6Address(address) ? "AAAA" : "A",
115
108
  normalizeIPAddress(address)
116
109
  )
117
110
  );
111
+ }
112
+
113
+ if (!hosts.has(host)) {
118
114
  hosts.add(host);
119
115
  for (const service of host.services()) {
120
116
  if (service.master && service.alias) {
@@ -207,20 +203,20 @@ async function generateNamedDefs(owner, targetDir) {
207
203
  }
208
204
 
209
205
  export function reverseAddress(address) {
210
- if (isIPv4Address(address)) {
211
- return address.split(".").reverse().join(".");
212
- }
213
-
214
- return normalizeIPAddress(address)
206
+ if (isIPv6Address(address)) {
207
+ return normalizeIPAddress(address)
215
208
  .replaceAll(":", "")
216
209
  .split("")
217
210
  .reverse()
218
211
  .join(".");
212
+ }
213
+
214
+ return address.split(".").reverse().join(".");
219
215
  }
220
216
 
221
217
  export function reverseArpaAddress(address) {
222
218
  return (
223
219
  reverseAddress(address) +
224
- (isIPv4Address(address) ? ".in-addr.arpa" : ".ip6.arpa")
220
+ (isIPv6Address(address) ? ".ip6.arpa" : ".in-addr.arpa")
225
221
  );
226
222
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.46.1",
3
+ "version": "1.46.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -67,16 +67,24 @@ export class Base {
67
67
  for (const [slotName, typeDef] of Object.entries(
68
68
  this.constructor.typeDefinition.properties
69
69
  )) {
70
- const slot = data[slotName];
70
+ let slot = data[slotName];
71
71
  if (slot) {
72
72
  delete data[slotName];
73
73
 
74
- const type = typeof typeDef.type === "string" ? typesByName[typeDef.type] : typeDef.type;
74
+ const type =
75
+ typeof typeDef.type === "string"
76
+ ? typesByName[typeDef.type]
77
+ : typeDef.type;
75
78
 
76
79
  if (typeDef.collection) {
77
80
  if (Array.isArray(slot) || typeof slot === "string") {
78
- for (const item of asArray(slot)) {
79
- new type(this, item);
81
+ slot = asArray(slot);
82
+ if (type) {
83
+ for (const item of slot) {
84
+ new type(this, item);
85
+ }
86
+ } else {
87
+ this[slotName] = slot;
80
88
  }
81
89
  } else {
82
90
  for (const [objectName, objectData] of Object.entries(slot)) {
package/src/host.mjs CHANGED
@@ -310,6 +310,7 @@ export class NetworkInterface extends Base {
310
310
  ssid: { type: "string" },
311
311
  psk: { type: "string" },
312
312
  metric: { type: "number" },
313
+ MTU: { type: "number" },
313
314
  cidrAddresses: { type: "string", collection: true, writeable: false },
314
315
  rawAddresses: { type: "string", collection: true, writeable: false },
315
316
  network: { type: "network" },
@@ -376,12 +377,10 @@ export class NetworkInterface extends Base {
376
377
  }
377
378
 
378
379
  addSubnet(address) {
379
- if(hasWellKnownSubnet(address)) {
380
- return;
381
- }
382
-
383
380
  if (!this.network) {
384
- this.error("Missing network", address);
381
+ if (!hasWellKnownSubnet(address)) {
382
+ this.error("Missing network", address);
383
+ }
385
384
  } else {
386
385
  return this.network.addSubnet(address);
387
386
  }
package/src/location.mjs CHANGED
@@ -21,7 +21,8 @@ export class Location extends Owner {
21
21
  clusters: { type: Cluster, collection: true },
22
22
  subnets: { type: Subnet, collection: true },
23
23
  dns: { type: DNSService },
24
- country: { type: "string" }
24
+ country: { type: "string" },
25
+ locales: { type: "string", collection: true }
25
26
  }
26
27
  };
27
28
  }
package/src/owner.mjs CHANGED
@@ -171,14 +171,10 @@ export class Owner extends Base {
171
171
 
172
172
  const subnets = [...this.subnets()];
173
173
 
174
- const subnet = subnets.find(s =>s.matchesAddress(address));
175
- if(subnet) {
174
+ const subnet = subnets.find(s => s.matchesAddress(address));
175
+ if (subnet) {
176
176
  return subnet;
177
177
  }
178
- /*
179
- if (subnets.length === 1) {
180
- return subnets[0];
181
- }*/
182
178
 
183
179
  this.error(
184
180
  `Address without subnet ${address}`,
@@ -277,9 +273,7 @@ export class Owner extends Base {
277
273
 
278
274
  *networkAddresses() {
279
275
  for (const host of this.hosts()) {
280
- for (const networkAddresses of host.networkAddresses()) {
281
- yield networkAddresses;
282
- }
276
+ yield* host.networkAddresses();
283
277
  }
284
278
  }
285
279
 
package/src/utils.mjs CHANGED
@@ -142,7 +142,7 @@ export function normalizeCIDR(address) {
142
142
  prefix = "fe80::";
143
143
  prefixLength = 64;
144
144
  } else {
145
- const definition = isIPv4Address(prefix) ? ipv4 : ipv6;
145
+ const definition = isIPv6Address(prefix) ? ipv6 : ipv4;
146
146
  let n = _encode(definition, prefix);
147
147
 
148
148
  if (prefixLength) {
@@ -167,7 +167,7 @@ export function normalizeCIDR(address) {
167
167
  export function hasWellKnownSubnet(address)
168
168
  {
169
169
  const n = encodeIP(address);
170
- return n === IPV4_LOCALHOST || n === IPV6_LOCALHOST;
170
+ return n === IPV4_LOCALHOST || n === IPV6_LOCALHOST || isLinkLocal(address);
171
171
  }
172
172
 
173
173
  const IPV4_LOCALHOST = _encode(ipv4, "127.0.0.1");
package/types/host.d.mts CHANGED
@@ -108,6 +108,9 @@ export class NetworkInterface extends Base {
108
108
  metric: {
109
109
  type: string;
110
110
  };
111
+ MTU: {
112
+ type: string;
113
+ };
111
114
  cidrAddresses: {
112
115
  type: string;
113
116
  collection: boolean;
@@ -25,6 +25,10 @@ export class Location extends Owner {
25
25
  country: {
26
26
  type: string;
27
27
  };
28
+ locales: {
29
+ type: string;
30
+ collection: boolean;
31
+ };
28
32
  };
29
33
  };
30
34
  get location(): this;
package/types/owner.d.mts CHANGED
@@ -59,7 +59,7 @@ export class Owner extends Base {
59
59
  clusters(): any;
60
60
  addBridge(network: any, destinationNetworks: any): any;
61
61
  _resolveBridges(): void;
62
- networkAddresses(): Generator<any, void, unknown>;
62
+ networkAddresses(): Generator<any, void, any>;
63
63
  domains(): Generator<any, void, unknown>;
64
64
  #private;
65
65
  }
package/types/utils.d.mts CHANGED
@@ -23,4 +23,4 @@ export function normalizeCIDR(address: any): {
23
23
  prefixLength: any;
24
24
  cidr: string;
25
25
  };
26
- export function hasWellKnownSubnet(address: any): boolean;
26
+ export function hasWellKnownSubnet(address: any): any;