pmcf 2.57.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/bin/pmcf-package CHANGED
@@ -33,6 +33,7 @@ const publishingDetails = createPublishingDetails(
33
33
  for (const object of root.find(args)) {
34
34
  const stagingDir = join(options.output, object.fullName);
35
35
 
36
+ //console.log(`packages for ${object.fullName}`);
36
37
  for await (const { sources, outputs, properties } of object.preparePackages(
37
38
  stagingDir
38
39
  )) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "2.57.0",
3
+ "version": "2.59.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -111,11 +111,10 @@ export class Base {
111
111
  if (Array.isArray(current)) {
112
112
  current.push(value);
113
113
  } else {
114
- if(current instanceof Set) {
114
+ if (current instanceof Set) {
115
115
  // TODO
116
116
  this[property.name] = value;
117
- }
118
- else if (current instanceof Map) {
117
+ } else if (current instanceof Map) {
119
118
  // TODO
120
119
  this[property.name] = value;
121
120
  } else {
@@ -374,10 +373,15 @@ export class Base {
374
373
  return this.findService({ type: "smtp" });
375
374
  }
376
375
 
376
+ /**
377
+ *
378
+ * @param {any} filter
379
+ * @returns service with the highest priority
380
+ */
377
381
  findService(filter) {
378
382
  let best;
379
383
  for (const service of this.findServices(filter)) {
380
- if (!best || service.priority < best.priority) {
384
+ if (!best || service.priority > best.priority) {
381
385
  best = service;
382
386
  }
383
387
  }
@@ -427,16 +431,7 @@ export class Base {
427
431
  return new Set(allOutputs.filter(o => this.packaging.has(o.name)));
428
432
  }
429
433
 
430
- async *preparePackages(stagingDir) {
431
- yield {
432
- sources: [],
433
- outputs: this.outputs,
434
- properties: {
435
- description: `${this.typeName} definitions for ${this.fullName}`,
436
- access: "private"
437
- }
438
- };
439
- }
434
+ async *preparePackages(stagingDir) {}
440
435
 
441
436
  get tags() {
442
437
  return this._tags;
package/src/cluster.mjs CHANGED
@@ -118,7 +118,7 @@ export class Cluster extends Host {
118
118
  cfg.push(" }");
119
119
  cfg.push(` virtual_router_id ${cluster.routerId}`);
120
120
  cfg.push(
121
- ` priority ${host.priority - (cluster.masters.has(ni) ? 0 : 5)}`
121
+ ` priority ${host.priority - 100 + (cluster.masters.has(ni) ? 0 : 5)}`
122
122
  );
123
123
  cfg.push(" smtp_alert");
124
124
  cfg.push(" advert_int 5");
package/src/dns-utils.mjs CHANGED
@@ -23,13 +23,17 @@ export function sortZoneRecords(a, b) {
23
23
  if (a.type === "PTR") {
24
24
  const toNum = a => {
25
25
  const s = a.split(".");
26
- s.pop();s.pop();s.pop();
27
- return s.reverse().reduce((a, c) => BigInt(parseInt(c,16)) + 256n * 256n * a, 0n);
26
+ s.pop();
27
+ s.pop();
28
+ s.pop();
29
+ return s
30
+ .reverse()
31
+ .reduce((a, c) => BigInt(parseInt(c, 16)) + 256n * 256n * a, 0n);
28
32
  };
29
33
  return Number(toNum(a.key) - toNum(b.key));
30
34
  }
31
35
  order = a.key.localeCompare(b.key);
32
- if(order) {
36
+ if (order) {
33
37
  return order;
34
38
  }
35
39
 
@@ -100,3 +104,7 @@ export function dnsMergeParameters(a, b) {
100
104
  ])
101
105
  );
102
106
  }
107
+
108
+ export function dnsPriority(priority) {
109
+ return 500 - (priority ?? 10);
110
+ }
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
@@ -6,7 +6,8 @@ import {
6
6
  DNSRecord,
7
7
  dnsFullName,
8
8
  dnsFormatParameters,
9
- dnsMergeParameters
9
+ dnsMergeParameters,
10
+ dnsPriority
10
11
  } from "./dns-utils.mjs";
11
12
 
12
13
  const ServiceTypes = {
@@ -268,7 +269,7 @@ export class Service extends Base {
268
269
 
269
270
  dnsRecordsForDomainName(domainName, hasSVRRecords) {
270
271
  const records = [];
271
- if (this.priority <= 1 && this.alias) {
272
+ if (this.priority >= 390 && this.alias) {
272
273
  records.push(DNSRecord(this.alias, "CNAME", dnsFullName(domainName)));
273
274
  }
274
275
 
@@ -283,7 +284,7 @@ export class Service extends Base {
283
284
  DNSRecord(
284
285
  dnsFullName(`_${this.type}._${ep.protocol}.${domainName}`),
285
286
  "SRV",
286
- this.priority ?? 10,
287
+ dnsPriority(this.priority),
287
288
  this.weight,
288
289
  ep.port,
289
290
  dnsFullName(this.domainName)
@@ -311,7 +312,7 @@ export class Service extends Base {
311
312
  DNSRecord(
312
313
  dnsFullName(domainName),
313
314
  dnsRecord.type,
314
- this.priority ?? 10,
315
+ dnsPriority(this.priority),
315
316
  ".",
316
317
  dnsFormatParameters(parameters)
317
318
  )
@@ -321,7 +322,7 @@ export class Service extends Base {
321
322
  DNSRecord(
322
323
  "@",
323
324
  dnsRecord.type,
324
- this.priority ?? 10,
325
+ dnsPriority(this.priority),
325
326
  dnsFullName(domainName)
326
327
  )
327
328
  );
@@ -332,8 +333,8 @@ export class Service extends Base {
332
333
  }
333
334
  }
334
335
 
335
- export const sortByPriority = (a, b) => a.priority - b.priority;
336
- 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;
337
338
 
338
339
  /**
339
340
  *
@@ -350,7 +351,7 @@ export function serviceEndpoints(sources, options = {}) {
350
351
  const all = asArray(sources)
351
352
  .map(ft => Array.from(ft.findServices(options.services)))
352
353
  .flat()
353
- .sort(sortByPriority)
354
+ .sort(sortDescendingByPriority)
354
355
  .map(service => service.endpoints(options.endpoints))
355
356
  .flat();
356
357
 
@@ -236,7 +236,7 @@ export class BindService extends ExtraSourceService {
236
236
  };
237
237
 
238
238
  const forwarders = serviceEndpoints(this.source, {
239
- services: { type: "dns", priority: ">=20" },
239
+ services: { type: "dns", priority: ">=300" },
240
240
  select: e => e.address,
241
241
  limit: 5
242
242
  });
@@ -535,7 +535,7 @@ export class BindService extends ExtraSourceService {
535
535
  }
536
536
 
537
537
  get defaultRecords() {
538
- const nameService = this.findService({ type: "dns", priority: "<10" });
538
+ const nameService = this.findService({ type: "dns", priority: ">=300" });
539
539
 
540
540
  const SOARecord = DNSRecord(
541
541
  "@",
@@ -58,7 +58,7 @@ export class ChronyService extends ExtraSourceService {
58
58
  ...serviceEndpoints(this, {
59
59
  services: {
60
60
  type: "ntp",
61
- priority: "<10"
61
+ priority: ">=200"
62
62
  },
63
63
  endpoints: e =>
64
64
  e.service.host !== host &&
@@ -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,
@@ -142,7 +142,7 @@ export class KeaService extends Service {
142
142
  const dnsServerEndpoints = serviceEndpoints(network, {
143
143
  services: {
144
144
  type: "dns",
145
- priority: "<10"
145
+ priority: ">=300"
146
146
  },
147
147
  endpoints: endpoint => endpoint.networkInterface.kind !== "loopback"
148
148
  });
@@ -162,10 +162,10 @@ export class KeaService extends Service {
162
162
  const peers = async family =>
163
163
  (
164
164
  await Array.fromAsync(
165
- network.findServices({ type: "dhcp", priority: "<20" })
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);
@@ -94,14 +99,7 @@ export class Base {
94
99
  get packaging(): Set<any>;
95
100
  get derivedPackaging(): any;
96
101
  get outputs(): Set<typeof import("npm-pkgbuild").ARCH | typeof import("npm-pkgbuild").DOCKER>;
97
- preparePackages(stagingDir: any): AsyncGenerator<{
98
- sources: any[];
99
- outputs: Set<typeof import("npm-pkgbuild").ARCH | typeof import("npm-pkgbuild").DOCKER>;
100
- properties: {
101
- description: string;
102
- access: string;
103
- };
104
- }, void, unknown>;
102
+ preparePackages(stagingDir: any): AsyncGenerator<never, void, unknown>;
105
103
  set tags(value: Set<any>);
106
104
  get tags(): Set<any>;
107
105
  get isTemplate(): boolean;
@@ -11,3 +11,4 @@ export function dnsFormatParameters(parameters: any): string;
11
11
  export function dnsMergeParameters(a: any, b: any): {
12
12
  [k: string]: Set<any>;
13
13
  };
14
+ export function dnsPriority(priority: any): number;
@@ -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";