pmcf 1.79.2 → 1.79.4

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": "1.79.2",
3
+ "version": "1.79.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dns-utils.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { asArray, asIterator } from "./utils.mjs";
2
+
1
3
  export function dnsFullName(name) {
2
4
  return name.endsWith(".") ? name : name + ".";
3
5
  }
@@ -17,6 +19,24 @@ export function DNSRecord(key, type, ...values) {
17
19
 
18
20
  export function dnsFormatParameters(parameters) {
19
21
  return Object.entries(parameters)
20
- .map(([name, value]) => (value !== undefined ? `${name}="${value}"` : name))
22
+ .map(([name, value]) =>
23
+ value !== undefined && [...asIterator(value)].length > 0
24
+ ? `${name}="${[...asIterator(value)].join(",")}"`
25
+ : name
26
+ )
21
27
  .join(" ");
22
28
  }
29
+
30
+ export function dnsMergeParameters(a, b) {
31
+ return Object.fromEntries(
32
+ [...new Set([...Object.keys(a), ...Object.keys(b)])].map(key => [
33
+ key,
34
+ new Set(asIterator(a[key])).union(new Set(asIterator(b[key])))
35
+ ])
36
+ );
37
+ }
38
+ /*
39
+ console.log(
40
+ dnsFormatParameters(dnsMergeParameters({ alpn: "h2" }, { alpn: "h3" }))
41
+ );
42
+ */
package/src/host.mjs CHANGED
@@ -38,7 +38,6 @@ const HostTypeDefinition = {
38
38
  },
39
39
  services: { type: "service", collection: true, writeable: true },
40
40
  aliases: { type: "string", collection: true, writeable: true },
41
-
42
41
  os: { type: "string", collection: false, writeable: true },
43
42
  "machine-id": { type: "string", collection: false, writeable: true },
44
43
  distribution: { type: "string", collection: false, writeable: true },
package/src/location.mjs CHANGED
@@ -11,7 +11,6 @@ const LocationTypeDefinition = {
11
11
  priority: 1.0,
12
12
  extends: Owner.typeDefinition,
13
13
  properties: {
14
- country: { type: "string", writeable: true },
15
14
  locales: { type: "string", collection: true, writeable: true }
16
15
  }
17
16
  };
package/src/service.mjs CHANGED
@@ -2,7 +2,12 @@ import { Base } from "./base.mjs";
2
2
  import { addType } from "./types.mjs";
3
3
  import { asArray } from "./utils.mjs";
4
4
  import { networkAddressProperties } from "./network-support.mjs";
5
- import { DNSRecord, dnsFullName, dnsFormatParameters } from "./dns-utils.mjs";
5
+ import {
6
+ DNSRecord,
7
+ dnsFullName,
8
+ dnsFormatParameters,
9
+ dnsMergeParameters
10
+ } from "./dns-utils.mjs";
6
11
 
7
12
  const ServiceTypes = {
8
13
  dns: { protocol: "udp", port: 53, tls: false },
@@ -213,13 +218,25 @@ export class Service extends Base {
213
218
 
214
219
  const dnsRecord = ServiceTypes[this.type]?.dnsRecord;
215
220
  if (dnsRecord) {
221
+ let parameters = dnsRecord.parameters;
222
+
223
+ for (const service of this.findServices()) {
224
+ if (service !== this) {
225
+ const r = ServiceTypes[service.type]?.dnsRecord;
226
+
227
+ if (r?.type === dnsRecord.type) {
228
+ parameters = dnsMergeParameters(parameters, r.parameters);
229
+ }
230
+ }
231
+ }
232
+
216
233
  records.push(
217
234
  DNSRecord(
218
235
  dnsFullName(domainName),
219
236
  dnsRecord.type,
220
237
  this.priority,
221
238
  ".",
222
- dnsFormatParameters(dnsRecord.parameters)
239
+ dnsFormatParameters(parameters)
223
240
  )
224
241
  );
225
242
  }
@@ -228,7 +245,6 @@ export class Service extends Base {
228
245
  }
229
246
  }
230
247
 
231
-
232
248
  export const sortByPriority = (a, b) => a.priority - b.priority;
233
249
 
234
250
  export function serviceAddresses(
package/src/utils.mjs CHANGED
@@ -55,8 +55,11 @@ export function asArray(value) {
55
55
  }
56
56
 
57
57
  export function asIterator(value) {
58
- if (value === undefined) {
59
- return [];
58
+ switch (typeof value) {
59
+ case "undefined":
60
+ return [];
61
+ case "string":
62
+ return [value];
60
63
  }
61
64
 
62
65
  if (typeof value[Symbol.iterator] === "function") {
@@ -4,3 +4,6 @@ export function DNSRecord(key: any, type: any, ...values: any[]): {
4
4
  toString: (maxKeyLength: any, ttl: any) => string;
5
5
  };
6
6
  export function dnsFormatParameters(parameters: any): string;
7
+ export function dnsMergeParameters(a: any, b: any): {
8
+ [k: string]: Set<any>;
9
+ };
@@ -401,10 +401,6 @@ export class Location extends Owner {
401
401
  };
402
402
  };
403
403
  properties: {
404
- country: {
405
- type: string;
406
- writeable: boolean;
407
- };
408
404
  locales: {
409
405
  type: string;
410
406
  collection: boolean;
package/types/root.d.mts CHANGED
@@ -405,10 +405,6 @@ export class Root extends Location {
405
405
  };
406
406
  };
407
407
  properties: {
408
- country: {
409
- type: string;
410
- writeable: boolean;
411
- };
412
408
  locales: {
413
409
  type: string;
414
410
  collection: boolean;