pmcf 2.2.0 → 2.3.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.2.0",
3
+ "version": "2.3.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -289,11 +289,11 @@ export class Base {
289
289
  }
290
290
 
291
291
  get domains() {
292
- return this.owner?.domains || new Set();
292
+ return this.owner?.domains ?? new Set();
293
293
  }
294
294
 
295
295
  get localDomains() {
296
- return this.owner?.localDomains || new Set();
296
+ return this.owner?.localDomains ?? new Set();
297
297
  }
298
298
 
299
299
  get administratorEmail() {
@@ -317,12 +317,7 @@ export class Base {
317
317
  }
318
318
 
319
319
  get priority() {
320
- if (this._priority !== undefined) {
321
- return this._priority;
322
- }
323
- if (this.owner?.priority !== undefined) {
324
- return this.owner.priority;
325
- }
320
+ return this._priority ?? this.owner?.priority;
326
321
  }
327
322
 
328
323
  get smtp() {
@@ -351,7 +346,7 @@ export class Base {
351
346
  }
352
347
 
353
348
  get directory() {
354
- return this._directory || join(this.owner.directory, this.name);
349
+ return this._directory ?? join(this.owner.directory, this.name);
355
350
  }
356
351
 
357
352
  get fullName() {
package/src/dns-utils.mjs CHANGED
@@ -31,7 +31,7 @@ export function DNSRecord(key, type, ...values) {
31
31
 
32
32
  return {
33
33
  key,
34
- toString: (maxKeyLength, ttl) =>
34
+ toString: (maxKeyLength = 0, ttl = "1W") =>
35
35
  `${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
36
36
  5,
37
37
  " "
package/src/host.mjs CHANGED
@@ -138,7 +138,7 @@ export class Host extends Base {
138
138
  }
139
139
 
140
140
  get serial() {
141
- return this._serial || this.extends.find(e => e.serial)?.serial;
141
+ return this._serial ?? this.extends.find(e => e.serial)?.serial;
142
142
  }
143
143
 
144
144
  set deployment(value) {
@@ -146,7 +146,7 @@ export class Host extends Base {
146
146
  }
147
147
 
148
148
  get deployment() {
149
- return this._deployment || this.extends.find(e => e.deployment)?.deployment;
149
+ return this._deployment ?? this.extends.find(e => e.deployment)?.deployment;
150
150
  }
151
151
 
152
152
  set chassis(value) {
@@ -154,7 +154,7 @@ export class Host extends Base {
154
154
  }
155
155
 
156
156
  get chassis() {
157
- return this._chassis || this.extends.find(e => e.chassis)?.chassis;
157
+ return this._chassis ?? this.extends.find(e => e.chassis)?.chassis;
158
158
  }
159
159
 
160
160
  set vendor(value) {
@@ -162,7 +162,7 @@ export class Host extends Base {
162
162
  }
163
163
 
164
164
  get vendor() {
165
- return this._vendor || this.extends.find(e => e.vendor)?.vendor;
165
+ return this._vendor ?? this.extends.find(e => e.vendor)?.vendor;
166
166
  }
167
167
 
168
168
  set architecture(value) {
@@ -171,7 +171,7 @@ export class Host extends Base {
171
171
 
172
172
  get architecture() {
173
173
  return (
174
- this._architecture || this.extends.find(e => e.architecture)?.architecture
174
+ this._architecture ?? this.extends.find(e => e.architecture)?.architecture
175
175
  );
176
176
  }
177
177
 
@@ -258,7 +258,7 @@ export class Host extends Base {
258
258
  }
259
259
 
260
260
  get os() {
261
- return this._os || this.extends.find(e => e.os)?.os;
261
+ return this._os ?? this.extends.find(e => e.os)?.os;
262
262
  }
263
263
 
264
264
  set distribution(value) {
@@ -267,7 +267,7 @@ export class Host extends Base {
267
267
 
268
268
  get distribution() {
269
269
  return (
270
- this._distribution || this.extends.find(e => e.distribution)?.distribution
270
+ this._distribution ?? this.extends.find(e => e.distribution)?.distribution
271
271
  );
272
272
  }
273
273
 
@@ -580,7 +580,7 @@ export class NetworkInterface extends Base {
580
580
  }
581
581
 
582
582
  get hostName() {
583
- return this._hostName || this.host.hostName;
583
+ return this._hostName ?? this.host.hostName;
584
584
  }
585
585
 
586
586
  set hostName(value) {
@@ -602,7 +602,7 @@ export class NetworkInterface extends Base {
602
602
  }
603
603
 
604
604
  get network() {
605
- return this._network || this.host.network;
605
+ return this._network ?? this.host.network;
606
606
  }
607
607
 
608
608
  set network(network) {
@@ -614,7 +614,7 @@ export class NetworkInterface extends Base {
614
614
  }
615
615
 
616
616
  get scope() {
617
- return this._scope || this.network?.scope || "global";
617
+ return this._scope ?? this.network?.scope ?? "global";
618
618
  }
619
619
 
620
620
  set metric(value) {
@@ -622,7 +622,7 @@ export class NetworkInterface extends Base {
622
622
  }
623
623
 
624
624
  get metric() {
625
- return this._metric || this.network?.metric || 1004;
625
+ return this._metric ?? this.network?.metric ?? 1004;
626
626
  }
627
627
 
628
628
  set ssid(value) {
@@ -630,7 +630,7 @@ export class NetworkInterface extends Base {
630
630
  }
631
631
 
632
632
  get ssid() {
633
- return this._ssid || this.network?.ssid;
633
+ return this._ssid ?? this.network?.ssid;
634
634
  }
635
635
 
636
636
  set psk(value) {
@@ -638,7 +638,7 @@ export class NetworkInterface extends Base {
638
638
  }
639
639
 
640
640
  get psk() {
641
- return this._psk || this.network?.psk;
641
+ return this._psk ?? this.network?.psk;
642
642
  }
643
643
 
644
644
  set kind(value) {
@@ -646,6 +646,6 @@ export class NetworkInterface extends Base {
646
646
  }
647
647
 
648
648
  get kind() {
649
- return this._kind || this.network?.kind;
649
+ return this._kind ?? this.network?.kind;
650
650
  }
651
651
  }
package/src/service.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Base } from "./base.mjs";
2
2
  import { addType } from "./types.mjs";
3
- import { asArray,isLocalhost } from "./utils.mjs";
3
+ import { asArray, isLocalhost } from "./utils.mjs";
4
4
  import { networkAddressProperties } from "./network-support.mjs";
5
5
  import {
6
6
  DNSRecord,
@@ -11,38 +11,43 @@ import {
11
11
  import { DHCPService, DNSService, NTPService } from "./module.mjs";
12
12
 
13
13
  const ServiceTypes = {
14
- ntp: { protocol: "udp", port: 123, tls: false },
15
- dns: { protocol: "udp", port: 53, tls: false },
16
- ldap: { protocol: "tcp", port: 389, tls: false },
17
- ldaps: { protocol: "tcp", port: 636, tls: true },
18
- http: { protocol: "tcp", port: 80, tls: false },
14
+ ntp: { endpoints: [{ protocol: "udp", port: 123, tls: false }] },
15
+ dns: { endpoints: [{ protocol: "udp", port: 53, tls: false }] },
16
+ ldap: { endpoints: [{ protocol: "tcp", port: 389, tls: false }] },
17
+ ldaps: { endpoints: [{ protocol: "tcp", port: 636, tls: true }] },
18
+ http: { endpoints: [{ protocol: "tcp", port: 80, tls: false }] },
19
19
  https: {
20
- protocol: "tcp",
21
- port: 443,
22
- tls: true,
20
+ endpoints: [{ protocol: "tcp", port: 443, tls: true }],
23
21
  dnsRecord: { type: "HTTPS", parameters: { alpn: "h2" } }
24
22
  },
25
23
  http3: {
26
24
  type: "https",
27
- protocol: "tcp",
28
- port: 443,
29
- tls: true,
25
+ endpoints: [{ protocol: "tcp", port: 443, tls: true }],
30
26
  dnsRecord: {
31
27
  type: "HTTPS",
32
28
  parameters: { "no-default-alpn": undefined, alpn: "h3" }
33
29
  }
34
30
  },
35
- rtsp: { protocol: "tcp", port: 554, tls: false },
36
- smtp: { protocol: "tcp", port: 25, tls: false, dnsRecord: { type: "MX" } },
37
- ssh: { protocol: "tcp", port: 22, tls: false },
38
- imap: { protocol: "tcp", port: 143, tls: false },
39
- imaps: { protocol: "tcp", port: 993, tls: true },
40
- dhcp: { tls: false },
41
- smb: { protocol: "tcp", port: 445, tls: false },
31
+ rtsp: { endpoints: [{ protocol: "tcp", port: 554, tls: false }] },
32
+ smtp: {
33
+ endpoints: [{ protocol: "tcp", port: 25, tls: false }],
34
+ dnsRecord: { type: "MX" }
35
+ },
36
+ ssh: { endpoints: [{ protocol: "tcp", port: 22, tls: false }] },
37
+ imap: { endpoints: [{ protocol: "tcp", port: 143, tls: false }] },
38
+ imaps: { endpoints: [{ protocol: "tcp", port: 993, tls: true }] },
39
+ dhcp: { endpoints: [{ port: 547, tls: false }] },
40
+ "dhcpv6-client": {
41
+ endpoints: [
42
+ { protocol: "tcp", port: 546, tls: false },
43
+ { protocol: "udp", port: 546, tls: false }
44
+ ]
45
+ },
46
+ "dhcpv6-server": { endpoints: [{ port: 547, tls: false }] },
47
+ smb: { endpoints: [{ protocol: "tcp", port: 445, tls: false }] },
42
48
  timemachine: {
43
49
  type: "adisk",
44
- protocol: "tcp",
45
- tls: false,
50
+ endpoints: [{ protocol: "tcp", tls: false }],
46
51
  dnsRecord: {
47
52
  type: "TXT",
48
53
  parameters: {
@@ -86,7 +91,6 @@ export const ServiceTypeDefinition = {
86
91
  alias: { type: "string", collection: false, writeable: true },
87
92
  type: { type: "string", collection: false, writeable: true },
88
93
  weight: { type: "number", collection: false, writeable: true },
89
- srvPrefix: { type: "string", collection: false, writeable: false },
90
94
  tls: { type: "string", collection: false, writeable: false },
91
95
  systemd: { type: "string", collection: true, writeable: true }
92
96
  }
@@ -145,12 +149,22 @@ export class Service extends Base {
145
149
  return this.rawAddresses.map(a => `${a}:${this.port}`);
146
150
  }
147
151
 
152
+ get endpoints() {
153
+ if (this._port !== undefined) {
154
+ return [
155
+ { protocol: this.protocol, address: this.rawAddress, port: this._port }
156
+ ];
157
+ }
158
+
159
+ return ServiceTypes[this.type]?.endpoints || [];
160
+ }
161
+
148
162
  set port(value) {
149
163
  this._port = value;
150
164
  }
151
165
 
152
166
  get port() {
153
- return this._port || ServiceTypes[this.type]?.port;
167
+ return this._port ?? ServiceTypes[this.type]?.endpoints[0].port;
154
168
  }
155
169
 
156
170
  set weight(value) {
@@ -158,15 +172,7 @@ export class Service extends Base {
158
172
  }
159
173
 
160
174
  get weight() {
161
- if (this._weight !== undefined) {
162
- return this._weight;
163
- }
164
-
165
- if (this.owner.weight !== undefined) {
166
- return this.owner.weight;
167
- }
168
-
169
- return 1;
175
+ return this._weight ?? this.owner.weight ?? 1;
170
176
  }
171
177
 
172
178
  set type(value) {
@@ -178,7 +184,7 @@ export class Service extends Base {
178
184
  }
179
185
 
180
186
  get protocol() {
181
- return ServiceTypes[this.type]?.protocol;
187
+ return ServiceTypes[this.type]?.endpoints[0].protocol;
182
188
  }
183
189
 
184
190
  get tls() {
@@ -189,30 +195,29 @@ export class Service extends Base {
189
195
  return this._systemd;
190
196
  }
191
197
 
192
- get srvPrefix() {
193
- const st = ServiceTypes[this.type];
194
- if (st?.protocol) {
195
- return `_${st.type || this.type}._${st.protocol}`;
196
- }
197
- }
198
-
199
198
  dnsRecordsForDomainName(domainName, hasSVRRecords) {
200
199
  const records = [];
201
200
  if (this.priority <= 1 && this.alias) {
202
201
  records.push(DNSRecord(this.alias, "CNAME", dnsFullName(domainName)));
203
202
  }
204
203
 
205
- if (hasSVRRecords && this.srvPrefix) {
206
- records.push(
207
- DNSRecord(
208
- dnsFullName(`${this.srvPrefix}.${domainName}`),
209
- "SRV",
210
- this.priority || 10,
211
- this.weight,
212
- this.port,
213
- dnsFullName(this.domainName)
214
- )
215
- );
204
+ if (hasSVRRecords) {
205
+ for (const ep of this.endpoints.filter(e => e.protocol)) {
206
+ records.push(
207
+ DNSRecord(
208
+ dnsFullName(
209
+ `_${ServiceTypes[this.type]?.type || this.type}._${
210
+ ep.protocol
211
+ }.${domainName}`
212
+ ),
213
+ "SRV",
214
+ this.priority ?? 10,
215
+ this.weight,
216
+ ep.port,
217
+ dnsFullName(this.domainName)
218
+ )
219
+ );
220
+ }
216
221
  }
217
222
 
218
223
  const dnsRecord = ServiceTypes[this.type]?.dnsRecord;
@@ -234,7 +239,7 @@ export class Service extends Base {
234
239
  DNSRecord(
235
240
  dnsFullName(domainName),
236
241
  dnsRecord.type,
237
- this.priority || 10,
242
+ this.priority ?? 10,
238
243
  ".",
239
244
  dnsFormatParameters(parameters)
240
245
  )
@@ -256,12 +261,13 @@ export function serviceAddresses(
256
261
  sources,
257
262
  filter,
258
263
  addressType = "rawAddresses",
259
- addressFilter = a=>!isLocalhost(a)
264
+ addressFilter = a => !isLocalhost(a)
260
265
  ) {
261
266
  return asArray(sources)
262
267
  .map(ft => Array.from(ft.findServices(filter)))
263
268
  .flat()
264
269
  .sort(sortByPriority)
265
270
  .map(s => s[addressType])
266
- .flat().filter(addressFilter);
271
+ .flat()
272
+ .filter(addressFilter);
267
273
  }
@@ -1,7 +1,7 @@
1
1
  export function dnsFullName(name: any): any;
2
2
  export function DNSRecord(key: any, type: any, ...values: any[]): {
3
3
  key: any;
4
- toString: (maxKeyLength: any, ttl: any) => string;
4
+ toString: (maxKeyLength?: number, ttl?: string) => string;
5
5
  };
6
6
  export function dnsFormatParameters(parameters: any): string;
7
7
  export function dnsMergeParameters(a: any, b: any): {
@@ -98,11 +98,6 @@ export class ExtraSourceService extends Service {
98
98
  collection: boolean;
99
99
  writeable: boolean;
100
100
  };
101
- srvPrefix: {
102
- type: string;
103
- collection: boolean;
104
- writeable: boolean;
105
- };
106
101
  tls: {
107
102
  type: string;
108
103
  collection: boolean;
@@ -83,11 +83,6 @@ export namespace ServiceTypeDefinition {
83
83
  collection: boolean;
84
84
  writeable: boolean;
85
85
  };
86
- srvPrefix: {
87
- type: string;
88
- collection: boolean;
89
- writeable: boolean;
90
- };
91
86
  tls: {
92
87
  type: string;
93
88
  collection: boolean;
@@ -209,11 +204,6 @@ export class Service extends Base {
209
204
  collection: boolean;
210
205
  writeable: boolean;
211
206
  };
212
- srvPrefix: {
213
- type: string;
214
- collection: boolean;
215
- writeable: boolean;
216
- };
217
207
  tls: {
218
208
  type: string;
219
209
  collection: boolean;
@@ -264,6 +254,7 @@ export class Service extends Base {
264
254
  get rawAddress(): any;
265
255
  set ipAddresses(value: any);
266
256
  get addresses(): any;
257
+ get endpoints(): any;
267
258
  set port(value: any);
268
259
  get port(): any;
269
260
  set weight(value: any);
@@ -273,10 +264,9 @@ export class Service extends Base {
273
264
  get protocol(): any;
274
265
  get tls(): any;
275
266
  get systemdServices(): any;
276
- get srvPrefix(): string;
277
267
  dnsRecordsForDomainName(domainName: any, hasSVRRecords: any): {
278
268
  key: any;
279
- toString: (maxKeyLength: any, ttl: any) => string;
269
+ toString: (maxKeyLength?: number, ttl?: string) => string;
280
270
  }[];
281
271
  }
282
272
  export function sortByPriority(a: any, b: any): number;
@@ -85,11 +85,6 @@ export class DHCPService extends Service {
85
85
  collection: boolean;
86
86
  writeable: boolean;
87
87
  };
88
- srvPrefix: {
89
- type: string;
90
- collection: boolean;
91
- writeable: boolean;
92
- };
93
88
  tls: {
94
89
  type: string;
95
90
  collection: boolean;
@@ -90,11 +90,6 @@ export class DNSService extends ExtraSourceService {
90
90
  collection: boolean;
91
91
  writeable: boolean;
92
92
  };
93
- srvPrefix: {
94
- type: string;
95
- collection: boolean;
96
- writeable: boolean;
97
- };
98
93
  tls: {
99
94
  type: string;
100
95
  collection: boolean;
@@ -88,11 +88,6 @@ export class NTPService extends ExtraSourceService {
88
88
  collection: boolean;
89
89
  writeable: boolean;
90
90
  };
91
- srvPrefix: {
92
- type: string;
93
- collection: boolean;
94
- writeable: boolean;
95
- };
96
91
  tls: {
97
92
  type: string;
98
93
  collection: boolean;