pmcf 1.2.2 → 1.3.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": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -23,21 +23,21 @@
23
23
  "license": "0BSD",
24
24
  "bin": {
25
25
  "pmcf-host-defs": "./bin/pmcf-host-defs",
26
+ "pmcf-info": "./bin/pmcf-info",
26
27
  "pmcf-location-defs": "./bin/pmcf-location-defs",
27
28
  "pmcf-named-defs": "./bin/pmcf-named-defs",
28
- "pmcf-info": "./bin/pmcf-info",
29
29
  "pmcf-network": "./bin/pmcf-network"
30
30
  },
31
31
  "scripts": {
32
32
  "prepare": "node --run prepare:typescript",
33
- "prepare:typescript": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext --rootDir src ./src**/*.mjs",
33
+ "prepare:typescript": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext --rootDir src ./src**/*.mjs",
34
34
  "test": "node --run test:ava",
35
35
  "test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
36
36
  "cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
37
37
  "docs": "documentation readme --section=API ./src**/*.mjs",
38
38
  "lint": "node --run lint:docs && node --run lint:typescript",
39
39
  "lint:docs": "documentation lint ./src**/*.mjs",
40
- "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
40
+ "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^22.10.7",
package/src/model.mjs CHANGED
@@ -96,13 +96,12 @@ export class Base {
96
96
  return this.typeName + ":" + this.owner.name + "/" + this.name;
97
97
  }
98
98
 
99
+ get propertyNames() {
100
+ return ["name", "description", "directory", "owner"];
101
+ }
102
+
99
103
  toJSON() {
100
- return {
101
- name: this.name,
102
- directory: this.directory,
103
- owner: this.owner.name,
104
- description: this.description
105
- };
104
+ return extractFrom(this, this.propertyNames);
106
105
  }
107
106
  }
108
107
 
@@ -388,24 +387,24 @@ export class Host extends Base {
388
387
  return readFile(join(this.directory, `ssh_host_${type}_key.pub`), "utf8");
389
388
  }
390
389
 
390
+ get propertyNames() {
391
+ return [
392
+ ...super.propertyNames,
393
+ "os",
394
+ "distribution",
395
+ "deployment",
396
+ "master",
397
+ "location",
398
+ "model",
399
+ "replaces",
400
+ "depends",
401
+ "networkInterfaces"
402
+ ];
403
+ }
404
+
391
405
  toJSON() {
392
406
  return {
393
407
  ...super.toJSON(),
394
- ...Object.fromEntries(
395
- [
396
- "location",
397
- "model",
398
- "os",
399
- "distribution",
400
- "deployment",
401
- "replaces",
402
- "depends",
403
- "master",
404
- "networkInterfaces"
405
- ]
406
- .filter(p => this[p])
407
- .map(p => [p, this[p]])
408
- ),
409
408
  extends: this.extends.map(host => host.name),
410
409
  services: Object.fromEntries(
411
410
  Object.values(this.services).map(s => [s.name, s.toJSON()])
@@ -574,10 +573,13 @@ export class Location extends Base {
574
573
  return this.#administratorEmail || "admin@" + this.domain;
575
574
  }
576
575
 
576
+ get propertyNames() {
577
+ return [...super.propertyNames, "domain"];
578
+ }
579
+
577
580
  toJSON() {
578
581
  return {
579
582
  ...super.toJSON(),
580
- domain: this.domain,
581
583
  hosts: [...this.#hosts.keys()].sort()
582
584
  };
583
585
  }
@@ -627,14 +629,8 @@ export class Network extends Base {
627
629
  this.#hosts.set(host.name, host);
628
630
  }
629
631
 
630
- toJSON() {
631
- return {
632
- ...super.toJSON(),
633
- kind: this.kind,
634
- ipv4: this.ipv4,
635
- scope: this.scope,
636
- metric: this.metric
637
- };
632
+ get propertyNames() {
633
+ return [...super.propertyNames, "kind", "ipv4", "scope", "metric"];
638
634
  }
639
635
  }
640
636
 
@@ -734,16 +730,16 @@ export class Service extends Base {
734
730
  return this.#type || this.name;
735
731
  }
736
732
 
737
- toJSON() {
738
- return {
739
- ...super.toJSON(),
740
- ipAddress: this.ipAddress,
741
- alias: this.alias,
742
- type: this.type,
743
- master: this.master,
744
- priority: this.priority,
745
- weight: this.weight
746
- };
733
+ get propertyNames() {
734
+ return [
735
+ ...super.propertyNames,
736
+ "ipAddress",
737
+ "alias",
738
+ "type",
739
+ "master",
740
+ "priority",
741
+ "weight"
742
+ ];
747
743
  }
748
744
  }
749
745
 
@@ -776,3 +772,14 @@ export function sectionLines(sectionName, values) {
776
772
 
777
773
  return lines;
778
774
  }
775
+
776
+ function extractFrom(object, propertyNames) {
777
+ const json = {};
778
+ for (const p of propertyNames) {
779
+ const value = object[p];
780
+ if (value !== undefined) {
781
+ json[p] = value;
782
+ }
783
+ }
784
+ return json;
785
+ }
package/types/model.d.mts CHANGED
@@ -17,12 +17,8 @@ export class Base {
17
17
  get directory(): any;
18
18
  expand(object: any): any;
19
19
  toString(): string;
20
- toJSON(): {
21
- name: any;
22
- directory: any;
23
- owner: any;
24
- description: any;
25
- };
20
+ get propertyNames(): string[];
21
+ toJSON(): {};
26
22
  #private;
27
23
  }
28
24
  export class World {
@@ -75,10 +71,6 @@ export class Host extends Base {
75
71
  toJSON(): {
76
72
  extends: any[];
77
73
  services: any;
78
- name: any;
79
- directory: any;
80
- owner: any;
81
- description: any;
82
74
  };
83
75
  #private;
84
76
  }
@@ -101,12 +93,7 @@ export class Location extends Base {
101
93
  get dnsRecordTTL(): any;
102
94
  get administratorEmail(): any;
103
95
  toJSON(): {
104
- domain: any;
105
96
  hosts: any[];
106
- name: any;
107
- directory: any;
108
- owner: any;
109
- description: any;
110
97
  };
111
98
  #private;
112
99
  }
@@ -120,16 +107,6 @@ export class Network extends Base {
120
107
  get subnetAddress(): any;
121
108
  hosts(): AsyncGenerator<any, void, unknown>;
122
109
  addHost(host: any): void;
123
- toJSON(): {
124
- kind: any;
125
- ipv4: any;
126
- scope: any;
127
- metric: any;
128
- name: any;
129
- directory: any;
130
- owner: any;
131
- description: any;
132
- };
133
110
  #private;
134
111
  }
135
112
  export class Subnet extends Base {
@@ -145,17 +122,5 @@ export class Service extends Base {
145
122
  get weight(): any;
146
123
  get master(): any;
147
124
  get type(): any;
148
- toJSON(): {
149
- ipAddress: any;
150
- alias: any;
151
- type: any;
152
- master: any;
153
- priority: any;
154
- weight: any;
155
- name: any;
156
- directory: any;
157
- owner: any;
158
- description: any;
159
- };
160
125
  #private;
161
126
  }