pmcf 4.1.0 → 4.1.2

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/README.md CHANGED
@@ -42,59 +42,61 @@ generates config packages for:
42
42
 
43
43
  * [Base](#base)
44
44
  * [Parameters](#parameters)
45
- * [getProperties](#getproperties)
45
+ * [propertyIterator](#propertyiterator)
46
46
  * [Parameters](#parameters-1)
47
+ * [getProperties](#getproperties)
48
+ * [Parameters](#parameters-2)
47
49
  * [priority](#priority)
48
50
  * [expression](#expression)
49
- * [Parameters](#parameters-2)
50
- * [findService](#findservice)
51
51
  * [Parameters](#parameters-3)
52
- * [expand](#expand)
52
+ * [findService](#findservice)
53
53
  * [Parameters](#parameters-4)
54
+ * [expand](#expand)
55
+ * [Parameters](#parameters-5)
54
56
  * [PortEndpoint](#portendpoint)
55
- * [Parameters](#parameters-5)
57
+ * [Parameters](#parameters-6)
56
58
  * [port](#port)
57
59
  * [socketAddress](#socketaddress)
58
60
  * [HTTPEndpoint](#httpendpoint)
59
- * [Parameters](#parameters-6)
61
+ * [Parameters](#parameters-7)
60
62
  * [port](#port-1)
61
63
  * [SkeletonNetworkInterface](#skeletonnetworkinterface)
62
64
  * [networkAddresses](#networkaddresses)
63
- * [Parameters](#parameters-7)
65
+ * [Parameters](#parameters-8)
64
66
  * [SystemdJournalRemoteService](#systemdjournalremoteservice)
65
67
  * [Properties](#properties)
66
68
  * [systemdConfigs](#systemdconfigs)
67
- * [Parameters](#parameters-8)
69
+ * [Parameters](#parameters-9)
68
70
  * [SystemdJournalUploadService](#systemdjournaluploadservice)
69
71
  * [Properties](#properties-1)
70
72
  * [systemdConfigs](#systemdconfigs-1)
71
- * [Parameters](#parameters-9)
73
+ * [Parameters](#parameters-10)
72
74
  * [NetworkAddress](#networkaddress)
73
- * [Parameters](#parameters-10)
75
+ * [Parameters](#parameters-11)
74
76
  * [subnet](#subnet)
75
77
  * [networkInterface](#networkinterface)
76
78
  * [address](#address)
77
79
  * [addresses](#addresses)
78
- * [Parameters](#parameters-11)
79
- * [cidrAddresses](#cidraddresses)
80
80
  * [Parameters](#parameters-12)
81
+ * [cidrAddresses](#cidraddresses)
82
+ * [Parameters](#parameters-13)
81
83
  * [isTemplate](#istemplate)
82
84
  * [services](#services)
83
- * [Parameters](#parameters-13)
84
- * [named](#named)
85
85
  * [Parameters](#parameters-14)
86
- * [serviceEndpoints](#serviceendpoints)
86
+ * [named](#named)
87
87
  * [Parameters](#parameters-15)
88
- * [domainName](#domainname)
88
+ * [serviceEndpoints](#serviceendpoints)
89
89
  * [Parameters](#parameters-16)
90
- * [domainFromDominName](#domainfromdominname)
90
+ * [domainName](#domainname)
91
91
  * [Parameters](#parameters-17)
92
- * [sectionLines](#sectionlines)
92
+ * [domainFromDominName](#domainfromdominname)
93
93
  * [Parameters](#parameters-18)
94
- * [asArray](#asarray)
94
+ * [sectionLines](#sectionlines)
95
95
  * [Parameters](#parameters-19)
96
- * [asIterator](#asiterator)
96
+ * [asArray](#asarray)
97
97
  * [Parameters](#parameters-20)
98
+ * [asIterator](#asiterator)
99
+ * [Parameters](#parameters-21)
98
100
 
99
101
  ## Base
100
102
 
@@ -103,13 +105,23 @@ generates config packages for:
103
105
  * `owner` **[Base](#base)** 
104
106
  * `data` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** 
105
107
 
108
+ ### propertyIterator
109
+
110
+ Retrive attribute values from an object.
111
+
112
+ #### Parameters
113
+
114
+ * `filter` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
115
+
116
+ Returns **Iterable<\[[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), any]>** values
117
+
106
118
  ### getProperties
107
119
 
108
120
  Retrive attribute values from an object.
109
121
 
110
122
  #### Parameters
111
123
 
112
- * `filter` (optional, default `filterPublic`)
124
+ * `filter` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** (optional, default `filterPublic`)
113
125
 
114
126
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** values
115
127
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -55,11 +55,11 @@
55
55
  "dependencies": {
56
56
  "ip-utilties": "^2.0.2",
57
57
  "npm-pkgbuild": "^19.1.4",
58
- "pacc": "^7.2.0",
58
+ "pacc": "^8.0.0",
59
59
  "package-directory": "^8.1.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@types/node": "^25.0.5",
62
+ "@types/node": "^25.0.6",
63
63
  "ava": "^6.4.1",
64
64
  "c8": "^10.1.3",
65
65
  "documentation": "^14.0.3",
package/src/base.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import { allOutputs } from "npm-pkgbuild";
3
3
  import {
4
+ getAttribute,
4
5
  typeFactory,
5
6
  addType,
6
7
  parse,
@@ -346,7 +347,7 @@ export class Base {
346
347
  if (!seen.has(this)) {
347
348
  seen.add(this);
348
349
 
349
- const value = this[propertyName];
350
+ const value = getAttribute(e, propertyName);
350
351
  if (value !== undefined) {
351
352
  yield value;
352
353
  }
@@ -362,7 +363,8 @@ export class Base {
362
363
  seen.add(this);
363
364
  for (const e of this.extends) {
364
365
  const value =
365
- e[propertyName] ?? e._extendedProperty(propertyName, seen);
366
+ getAttribute(e, propertyName) ??
367
+ e._extendedProperty(propertyName, seen);
366
368
  if (value !== undefined) {
367
369
  return value;
368
370
  }
@@ -371,7 +373,7 @@ export class Base {
371
373
  }
372
374
 
373
375
  extendedProperty(propertyName) {
374
- const value = this[propertyName];
376
+ const value = getAttribute(this, propertyName);
375
377
  if (value !== undefined) {
376
378
  return value;
377
379
  }
@@ -479,7 +481,11 @@ export class Base {
479
481
  * @returns {any}
480
482
  */
481
483
  expression(expression, options) {
482
- return parse(expression, { root: this, globals: this.globals, ...options });
484
+ return parse(expression, {
485
+ root: this,
486
+ getGlobal: x => this.getGlobal(x),
487
+ ...options
488
+ });
483
489
  }
484
490
 
485
491
  /**
@@ -556,13 +562,8 @@ export class Base {
556
562
  return this.name?.indexOf("*") >= 0 || this.owner?.isTemplate || false;
557
563
  }
558
564
 
559
- get globals() {
560
- return Object.assign(
561
- {},
562
- this.properties,
563
- ...[...this.owners()].map(o => o.properties),
564
- globals
565
- );
565
+ getGlobal(a) {
566
+ return globals[a] ?? this.property(a);
566
567
  }
567
568
 
568
569
  get properties() {
@@ -596,7 +597,7 @@ export class Base {
596
597
  return expand(object, {
597
598
  stopClass: Base,
598
599
  root: this,
599
- globals: this.globals
600
+ getGlobal: x => this.getGlobal(x)
600
601
  });
601
602
  }
602
603
 
package/src/host.mjs CHANGED
@@ -475,7 +475,7 @@ export class Host extends ServiceOwner {
475
475
  for (const { serviceName, configFileName, content } of asArray(
476
476
  service.expand(service.systemdConfigs(this.name))
477
477
  )) {
478
- await writeLines(dir, configFileName, sectionLines(...content));
478
+ await writeLines(dir, configFileName, content);
479
479
 
480
480
  addHook(
481
481
  packageData.properties.hooks,
package/src/service.mjs CHANGED
@@ -222,7 +222,7 @@ export class Service extends Base {
222
222
  }
223
223
 
224
224
  get port() {
225
- return this._port ?? serviceTypeEndpoints(ServiceTypes[this.type])[0].port;
225
+ return this._port ?? serviceTypeEndpoints(ServiceTypes[this.type])[0]?.port;
226
226
  }
227
227
 
228
228
  set weight(value) {
@@ -4,7 +4,7 @@ import {
4
4
  boolean_attribute_writable
5
5
  } from "pacc";
6
6
  import { Service, ServiceTypeDefinition, addServiceType } from "pmcf";
7
- import { filterConfigurable } from "../utils.mjs";
7
+ import { filterConfigurable, sectionLines } from "../utils.mjs";
8
8
 
9
9
  const SystemdJournalRemoteServiceTypeDefinition = {
10
10
  name: "systemd-journal-remote",
@@ -105,7 +105,7 @@ export class SystemdJournalRemoteService extends Service {
105
105
  return {
106
106
  serviceName: this.systemdService,
107
107
  configFileName: `etc/systemd/journal-remote.conf.d/${name}.conf`,
108
- content: ["Remote", this.getProperties(filterConfigurable)]
108
+ content: sectionLines("Remote", this.getProperties(filterConfigurable))
109
109
  };
110
110
  }
111
111
  }
@@ -4,7 +4,7 @@ import {
4
4
  addType
5
5
  } from "pacc";
6
6
  import { Service, ServiceTypeDefinition, addServiceType } from "pmcf";
7
- import { filterConfigurable } from "../utils.mjs";
7
+ import { filterConfigurable, sectionLines } from "../utils.mjs";
8
8
 
9
9
  const SystemdJournalUploadServiceTypeDefinition = {
10
10
  name: "systemd-journal-upload",
@@ -73,7 +73,7 @@ export class SystemdJournalUploadService extends Service {
73
73
  return {
74
74
  serviceName: this.systemdService,
75
75
  configFileName: `etc/systemd/journal-upload.conf.d/${name}.conf`,
76
- content: ["Upload", this.getProperties(filterConfigurable)]
76
+ content: sectionLines("Upload", this.getProperties(filterConfigurable))
77
77
  };
78
78
  }
79
79
  }
@@ -4,7 +4,7 @@ import {
4
4
  duration_attribute_writable
5
5
  } from "pacc";
6
6
  import { Service, ServiceTypeDefinition, addServiceType } from "pmcf";
7
- import { filterConfigurable } from "../utils.mjs";
7
+ import { filterConfigurable, sectionLines } from "../utils.mjs";
8
8
 
9
9
  const SystemdJournalServiceTypeDefinition = {
10
10
  name: "systemd-journald",
@@ -129,7 +129,7 @@ export class SystemdJournaldService extends Service {
129
129
  return {
130
130
  serviceName: this.systemdService,
131
131
  configFileName: `etc/systemd/journal.conf.d/${name}.conf`,
132
- content: ["Journal", this.getProperties(filterConfigurable)]
132
+ content: sectionLines("Journal", this.getProperties(filterConfigurable))
133
133
  };
134
134
  }
135
135
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  addType,
3
+ object_attribute,
3
4
  duration_attribute_writable,
4
5
  string_attribute_writable,
5
6
  boolean_attribute_writable,
@@ -12,7 +13,12 @@ import {
12
13
  serviceEndpoints,
13
14
  addServiceType
14
15
  } from "pmcf";
15
- import { filterConfigurable, yesno } from "../utils.mjs";
16
+ import {
17
+ filterConfigurable,
18
+ yesno,
19
+ sectionLines,
20
+ setionLinesFromPropertyIterator
21
+ } from "../utils.mjs";
16
22
 
17
23
  const SystemdResolvedServiceTypeDefinition = {
18
24
  name: "systemd-resolved",
@@ -21,24 +27,42 @@ const SystemdResolvedServiceTypeDefinition = {
21
27
  owners: ServiceTypeDefinition.owners,
22
28
  key: "name",
23
29
  attributes: {
24
- DNS: { ...string_attribute_writable, configurable: true },
25
- FallbackDNS: { ...string_attribute_writable, configurable: true },
26
- Domains: { ...string_attribute_writable, configurable: true },
27
- MulticastDNS: { ...boolean_attribute_writable, configurable: true },
28
- Cache: { ...boolean_attribute_writable, configurable: true },
29
- CacheFromLocalhost: { ...boolean_attribute_writable, configurable: true },
30
- DNSStubListener: { ...boolean_attribute_writable, configurable: true },
31
- DNSStubListenerExtra: { ...string_attribute_writable, configurable: true },
32
- ReadEtcHosts: { ...boolean_attribute_writable, configurable: true },
33
- ResolveUnicastSingleLabel: {
34
- ...boolean_attribute_writable,
35
- configurable: true
36
- },
37
- StaleRetentionSec: { ...duration_attribute_writable, configurable: true },
38
- RefuseRecordTypes: { ...string_attribute_writable, configurable: true },
39
- DNSSEC: { ...yesno_attribute_writable, default: false, configurable: true },
40
- DNSOverTLS: { ...yesno_attribute_writable, configurable: true },
41
- LLMNR: { ...yesno_attribute_writable, configurable: true }
30
+ /* Resolve: {
31
+ ...object_attribute,
32
+ attributes: {*/
33
+ DNS: { ...string_attribute_writable, configurable: true },
34
+ FallbackDNS: { ...string_attribute_writable, configurable: true },
35
+ Domains: { ...string_attribute_writable, configurable: true },
36
+ MulticastDNS: { ...yesno_attribute_writable, configurable: true },
37
+ Cache: { ...boolean_attribute_writable, configurable: true },
38
+ CacheFromLocalhost: {
39
+ ...boolean_attribute_writable,
40
+ configurable: true
41
+ },
42
+ DNSStubListener: { ...boolean_attribute_writable, configurable: true },
43
+ DNSStubListenerExtra: {
44
+ ...string_attribute_writable,
45
+ configurable: true
46
+ },
47
+ ReadEtcHosts: { ...boolean_attribute_writable, configurable: true },
48
+ ResolveUnicastSingleLabel: {
49
+ ...boolean_attribute_writable,
50
+ configurable: true
51
+ },
52
+ StaleRetentionSec: {
53
+ ...duration_attribute_writable,
54
+ configurable: true
55
+ },
56
+ RefuseRecordTypes: { ...string_attribute_writable, configurable: true },
57
+ DNSSEC: {
58
+ ...yesno_attribute_writable,
59
+ default: false,
60
+ configurable: true
61
+ },
62
+ DNSOverTLS: { ...yesno_attribute_writable, configurable: true },
63
+ LLMNR: { ...yesno_attribute_writable, configurable: true }
64
+ /* }
65
+ }*/
42
66
  },
43
67
  service: {
44
68
  systemdService: "systemd-resolved.service"
@@ -59,6 +83,8 @@ export class SystemdResolvedService extends ExtraSourceService {
59
83
  return SystemdResolvedServiceTypeDefinition.name;
60
84
  }
61
85
 
86
+ Resolve = {};
87
+
62
88
  systemdConfigs(name) {
63
89
  const options = (lower, upper, limit) => {
64
90
  return {
@@ -76,16 +102,14 @@ export class SystemdResolvedService extends ExtraSourceService {
76
102
  return {
77
103
  serviceName: this.systemdService,
78
104
  configFileName: `etc/systemd/resolved.conf.d/${name}.conf`,
79
- content: [
80
- "Resolve",
81
- {
82
- DNS: serviceEndpoints(this, options(300, 399, 4)),
83
- FallbackDNS: serviceEndpoints(this, options(100, 199, 4)),
84
- Domains: [...this.localDomains].join(" "),
85
- MulticastDNS: yesno(this.network.multicastDNS),
86
- ...this.getProperties(filterConfigurable)
87
- }
88
- ]
105
+ //content: [...setionLinesFromPropertyIterator(this.propertyIterator( filterConfigurable)), "A=1"]
106
+ content: sectionLines("Resolve", {
107
+ DNS: serviceEndpoints(this, options(300, 399, 4)),
108
+ FallbackDNS: serviceEndpoints(this, options(100, 199, 4)),
109
+ Domains: [...this.localDomains].join(" "),
110
+ MulticastDNS: yesno(this.network.multicastDNS),
111
+ ...this.getProperties(filterConfigurable)
112
+ })
89
113
  };
90
114
  }
91
115
  }
@@ -10,7 +10,7 @@ import {
10
10
  serviceEndpoints,
11
11
  addServiceType
12
12
  } from "pmcf";
13
- import { filterConfigurable } from "../utils.mjs";
13
+ import { filterConfigurable, sectionLines } from "../utils.mjs";
14
14
 
15
15
  const SystemdTimesyncdServiceTypeDefinition = {
16
16
  name: "systemd-timesyncd",
@@ -61,14 +61,14 @@ export class SystemdTimesyncdService extends ExtraSourceService {
61
61
  return {
62
62
  serviceName: this.systemdService,
63
63
  configFileName: `etc/systemd/timesyncd.conf.d/${name}.conf`,
64
- content: [
64
+ content: sectionLines(
65
65
  "Time",
66
66
  {
67
67
  NTP: serviceEndpoints(this, options(300, 399)),
68
68
  FallbackNTP: serviceEndpoints(this, options(100, 199)),
69
69
  ...this.getProperties(filterConfigurable)
70
- }
71
- ]
70
+ })
71
+
72
72
  };
73
73
  }
74
74
  }
package/src/utils.mjs CHANGED
@@ -7,8 +7,8 @@ export function yesno(flag) {
7
7
 
8
8
  /**
9
9
  * Appends default domain if name does not already have a domain.
10
- * @param {string} name
11
- * @param {string} [defaultDomain]
10
+ * @param {string} name
11
+ * @param {string} [defaultDomain]
12
12
  * @returns {string|undefined}
13
13
  */
14
14
  export function domainName(name, defaultDomain) {
@@ -20,7 +20,7 @@ export function domainName(name, defaultDomain) {
20
20
 
21
21
  /**
22
22
  * Extracts domain name from a name.
23
- * @param {string} domainName
23
+ * @param {string} domainName
24
24
  * @param {string} [defaultDomain]
25
25
  * @returns {string|undefined}
26
26
  */
@@ -62,9 +62,9 @@ export async function writeLines(dir, name, lines) {
62
62
  }
63
63
 
64
64
  /**
65
- *
66
- * @param {string} sectionName
67
- * @param {Object} values
65
+ *
66
+ * @param {string} sectionName
67
+ * @param {Object} values
68
68
  * @returns {Array<string>}
69
69
  */
70
70
  export function sectionLines(sectionName, values) {
@@ -77,12 +77,22 @@ export function sectionLines(sectionName, values) {
77
77
  return lines;
78
78
  }
79
79
 
80
+ export function* setionLinesFromPropertyIterator(properties) {
81
+ for (const [name, value, path, attribute] of properties) {
82
+ if (attribute.attributes) {
83
+ yield `[${name}]`;
84
+ } else {
85
+ yield `${name}=${value}`;
86
+ }
87
+ }
88
+ }
89
+
80
90
  export function bridgeToJSON(bridge) {
81
91
  return [...bridge].map(n => n.fullName || `(${n})`).sort();
82
92
  }
83
93
 
84
94
  /**
85
- * @param {any} value
95
+ * @param {any} value
86
96
  * @returns {Array<any>}
87
97
  */
88
98
  export function asArray(value) {
@@ -90,7 +100,7 @@ export function asArray(value) {
90
100
  }
91
101
 
92
102
  /**
93
- * @param {any} value
103
+ * @param {any} value
94
104
  * @returns {Iterable<any>}
95
105
  */
96
106
  export function asIterator(value) {
@@ -108,5 +118,5 @@ export function asIterator(value) {
108
118
  return asArray(value);
109
119
  }
110
120
 
111
-
112
- export const filterConfigurable = (name, attribute) => !attribute.private & attribute.configurable;
121
+ export const filterConfigurable = (name, attribute) =>
122
+ !attribute.private & attribute.configurable;
package/types/base.d.mts CHANGED
@@ -124,7 +124,7 @@ export class Base {
124
124
  set tags(value: Set<any>);
125
125
  get tags(): Set<any>;
126
126
  get isTemplate(): any;
127
- get globals(): any;
127
+ getGlobal(a: any): any;
128
128
  get properties(): any;
129
129
  property(name: any): any;
130
130
  /**
@@ -1258,7 +1258,7 @@ export class SystemdJournaldService extends Service {
1258
1258
  systemdConfigs(name: any): {
1259
1259
  serviceName: any;
1260
1260
  configFileName: string;
1261
- content: any[];
1261
+ content: string[];
1262
1262
  };
1263
1263
  }
1264
1264
  import { Service } from "pmcf";
@@ -1303,25 +1303,8 @@ export class SystemdResolvedService extends ExtraSourceService {
1303
1303
  };
1304
1304
  MulticastDNS: {
1305
1305
  configurable: boolean;
1306
- type: object;
1307
- isKey: boolean;
1308
1306
  writable: boolean;
1309
- mandatory: boolean;
1310
1307
  collection: boolean;
1311
- private?: boolean;
1312
- credential?: boolean;
1313
- persistent?: boolean;
1314
- depends?: string;
1315
- description?: string;
1316
- default?: any;
1317
- set?: Function;
1318
- get?: Function;
1319
- toInternal?: Function;
1320
- toExternal?: Function;
1321
- values?: Set<any>;
1322
- externalName?: string;
1323
- env?: string[] | string;
1324
- additionalValues?: object;
1325
1308
  };
1326
1309
  Cache: {
1327
1310
  configurable: boolean;
@@ -1520,10 +1503,11 @@ export class SystemdResolvedService extends ExtraSourceService {
1520
1503
  systemdService: string;
1521
1504
  };
1522
1505
  };
1506
+ Resolve: {};
1523
1507
  systemdConfigs(name: any): {
1524
1508
  serviceName: any;
1525
1509
  configFileName: string;
1526
- content: any[];
1510
+ content: string[];
1527
1511
  };
1528
1512
  }
1529
1513
  import { ExtraSourceService } from "pmcf";
@@ -1396,7 +1396,7 @@ export class SystemdTimesyncdService extends ExtraSourceService {
1396
1396
  systemdConfigs(name: any): {
1397
1397
  serviceName: any;
1398
1398
  configFileName: string;
1399
- content: any[];
1399
+ content: string[];
1400
1400
  };
1401
1401
  }
1402
1402
  import { ExtraSourceService } from "pmcf";
package/types/utils.d.mts CHANGED
@@ -21,6 +21,7 @@ export function writeLines(dir: any, name: any, lines: any): Promise<void>;
21
21
  * @returns {Array<string>}
22
22
  */
23
23
  export function sectionLines(sectionName: string, values: any): Array<string>;
24
+ export function setionLinesFromPropertyIterator(properties: any): Generator<string, void, unknown>;
24
25
  export function bridgeToJSON(bridge: any): any[];
25
26
  /**
26
27
  * @param {any} value