pmcf 2.58.0 → 2.59.0

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.58.0",
3
+ "version": "2.59.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -373,10 +373,15 @@ export class Base {
373
373
  return this.findService({ type: "smtp" });
374
374
  }
375
375
 
376
+ /**
377
+ *
378
+ * @param {any} filter
379
+ * @returns service with the highest priority
380
+ */
376
381
  findService(filter) {
377
382
  let best;
378
383
  for (const service of this.findServices(filter)) {
379
- if (!best || service.priority < best.priority) {
384
+ if (!best || service.priority > best.priority) {
380
385
  best = service;
381
386
  }
382
387
  }
package/src/filter.mjs CHANGED
@@ -43,10 +43,17 @@ export function* objectFilter(type, objects, filter) {
43
43
  case "number":
44
44
  return filter[key] === object[key];
45
45
  case "string":
46
- const m = filter[key].match(/^([=><!]+)(\d+)/);
46
+ let m = filter[key].match(/^([=><!]+)(\d+)/);
47
47
  if (m) {
48
48
  return compare(m[1], key, parseInt(m[2]));
49
49
  }
50
+
51
+ m = filter[key].match(/^\[(\d+):(\d+)\]/);
52
+ if (m) {
53
+ const lower = parseInt(m[1]);
54
+ const upper = parseInt(m[2]);
55
+ return lower <= object[key] && upper >= object[key];
56
+ }
50
57
  }
51
58
  return false;
52
59
  };
package/src/service.mjs CHANGED
@@ -333,8 +333,8 @@ export class Service extends Base {
333
333
  }
334
334
  }
335
335
 
336
- export const sortByPriority = (a, b) => a.priority - b.priority;
337
- export const sortInverseByPriority = (a, b) => b.priority - a.priority;
336
+ export const sortAscendingByPriority = (a, b) => a.priority - b.priority;
337
+ export const sortDescendingByPriority = (a, b) => b.priority - a.priority;
338
338
 
339
339
  /**
340
340
  *
@@ -351,7 +351,7 @@ export function serviceEndpoints(sources, options = {}) {
351
351
  const all = asArray(sources)
352
352
  .map(ft => Array.from(ft.findServices(options.services)))
353
353
  .flat()
354
- .sort(sortByPriority)
354
+ .sort(sortDescendingByPriority)
355
355
  .map(service => service.endpoints(options.endpoints))
356
356
  .flat();
357
357
 
@@ -3,7 +3,7 @@ import { FileContentProvider } from "npm-pkgbuild";
3
3
  import { reverseArpa } from "ip-utilties";
4
4
  import {
5
5
  Service,
6
- sortInverseByPriority,
6
+ sortAscendingByPriority,
7
7
  ServiceTypeDefinition,
8
8
  Endpoint,
9
9
  UnixEndpoint,
@@ -165,7 +165,7 @@ export class KeaService extends Service {
165
165
  network.findServices({ type: "dhcp", priority: ">=200" })
166
166
  )
167
167
  )
168
- .sort(sortInverseByPriority)
168
+ .sort(sortAscendingByPriority)
169
169
  .map((dhcp, i) => {
170
170
  const ctrlAgentEndpoint = dhcp.endpoint(
171
171
  e =>
@@ -37,24 +37,24 @@ export class SystemdResolvedService extends ExtraSourceService {
37
37
  }
38
38
 
39
39
  systemdConfig(name) {
40
- const options = priority => {
40
+ const options = (priority, limit) => {
41
41
  return {
42
42
  services: { type: "dns", priority },
43
43
  endpoints: e => e.networkInterface.kind !== "loopback",
44
44
  select: endpoint => endpoint.address,
45
45
  join: " ",
46
- limit: 5
46
+ limit
47
47
  };
48
48
  };
49
49
 
50
50
  return {
51
- serviceName: "systemd-resolved",
51
+ serviceName: "systemd-resolved",
52
52
  configFileName: `etc/systemd/resolved.conf.d/${name}.conf`,
53
53
  content: [
54
54
  "Resolve",
55
55
  {
56
- DNS: serviceEndpoints(this, options("<10")),
57
- FallbackDNS: serviceEndpoints(this, options(">=20")),
56
+ DNS: serviceEndpoints(this, options(">=300", 2)),
57
+ FallbackDNS: serviceEndpoints(this, options("[100:199]", 4)),
58
58
  Domains: [...this.localDomains].join(" "),
59
59
  DNSSEC: "no",
60
60
  MulticastDNS: this.network.multicastDNS ? "yes" : "no",
@@ -46,11 +46,12 @@ export class SystemdTimesyncdService extends ExtraSourceService {
46
46
  NTP: serviceEndpoints(this, {
47
47
  services: {
48
48
  type: "ntp",
49
- priority: "<10"
49
+ priority: "[200:399]"
50
50
  },
51
51
  endpoints: endpoint =>
52
52
  endpoint.networkInterface.kind !== "loopback",
53
53
  select: endpoint => endpoint.domainName,
54
+ limit: 2,
54
55
  join: " "
55
56
  })
56
57
  }
package/types/base.d.mts CHANGED
@@ -85,6 +85,11 @@ export class Base {
85
85
  get priority(): any;
86
86
  _priority: any;
87
87
  get smtp(): any;
88
+ /**
89
+ *
90
+ * @param {any} filter
91
+ * @returns service with the highest priority
92
+ */
88
93
  findService(filter: any): any;
89
94
  findServices(filter: any): Generator<any, void, any>;
90
95
  set directory(directory: any);
@@ -339,7 +339,7 @@ export class Service extends Base {
339
339
  toString: (maxKeyLength?: number, ttl?: string) => string;
340
340
  }[];
341
341
  }
342
- export function sortByPriority(a: any, b: any): number;
343
- export function sortInverseByPriority(a: any, b: any): number;
342
+ export function sortAscendingByPriority(a: any, b: any): number;
343
+ export function sortDescendingByPriority(a: any, b: any): number;
344
344
  import { Base } from "pmcf";
345
345
  import { Host } from "pmcf";