pmcf 1.74.1 → 1.75.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.74.1",
3
+ "version": "1.75.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/host.mjs CHANGED
@@ -2,7 +2,10 @@ import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { FileContentProvider } from "npm-pkgbuild";
4
4
  import { Base } from "./base.mjs";
5
- import { networkProperties, networkAddressProperties } from "./network-support.mjs";
5
+ import {
6
+ networkProperties,
7
+ networkAddressProperties
8
+ } from "./network-support.mjs";
6
9
  import {
7
10
  asArray,
8
11
  isIPv4Address,
@@ -33,6 +36,8 @@ const HostTypeDefinition = {
33
36
  writeable: true
34
37
  },
35
38
  services: { type: "service", collection: true, writeable: true },
39
+ aliases: { type: "string", collection: false, writeable: true },
40
+
36
41
  os: { type: "string", collection: false, writeable: true },
37
42
  "machine-id": { type: "string", collection: false, writeable: true },
38
43
  distribution: { type: "string", collection: false, writeable: true },
@@ -56,6 +61,7 @@ export class Host extends Base {
56
61
  priority = 1;
57
62
  #services = [];
58
63
  #extends = [];
64
+ #aliases = new Set();
59
65
  #networkInterfaces = new Map();
60
66
  #provides = new Set();
61
67
  #replaces = new Set();
@@ -158,6 +164,18 @@ export class Host extends Base {
158
164
  return this.extends.find(h => h.isModel);
159
165
  }
160
166
 
167
+ set aliases(value) {
168
+ if (value instanceof Set) {
169
+ this.#aliases = this.#aliases.union(value);
170
+ } else {
171
+ this.#aliases.add(value);
172
+ }
173
+ }
174
+
175
+ get aliases() {
176
+ return this.#aliases;
177
+ }
178
+
161
179
  set extends(value) {
162
180
  this.#extends.push(value);
163
181
  }
@@ -226,10 +244,6 @@ export class Host extends Base {
226
244
  return this.#distribution || this.extends.find(e => e.distribution);
227
245
  }
228
246
 
229
- get domain() {
230
- return this.location?.domain;
231
- }
232
-
233
247
  get modelName() {
234
248
  return this.model?.hostName;
235
249
  }
@@ -239,6 +253,22 @@ export class Host extends Base {
239
253
  return parts[parts.length - 1];
240
254
  }
241
255
 
256
+ get domains() {
257
+ const domains = new Set(
258
+ [...this.aliases].map(n => {
259
+ const p = n.split(".");
260
+ p.shift();
261
+ return p.join(".");
262
+ })
263
+ );
264
+ domains.add(this.domain);
265
+ return domains;
266
+ }
267
+
268
+ get domainNames() {
269
+ return [this.domainName, ...this.aliases];
270
+ }
271
+
242
272
  get domainName() {
243
273
  const domain = this.domain;
244
274
  const hostName = this.hostName;
package/src/utils.mjs CHANGED
@@ -2,12 +2,16 @@ import { writeFile, mkdir } from "node:fs/promises";
2
2
  import { join, dirname, basename } from "node:path";
3
3
 
4
4
  export async function writeLines(dir, name, lines) {
5
+ switch(typeof lines) {
6
+ case "undefined": return;
7
+ case "string": lines = [lines];
8
+ }
9
+
5
10
  const full = join(dir, name);
6
11
  dir = dirname(full);
7
12
  name = basename(full);
8
-
9
13
  await mkdir(dir, { recursive: true });
10
- if (typeof lines === "string") lines = [lines];
14
+
11
15
  return writeFile(
12
16
  join(dir, name),
13
17
  [...lines]
package/types/host.d.mts CHANGED
@@ -51,6 +51,11 @@ export class Host extends Base {
51
51
  collection: boolean;
52
52
  writeable: boolean;
53
53
  };
54
+ aliases: {
55
+ type: string;
56
+ collection: boolean;
57
+ writeable: boolean;
58
+ };
54
59
  os: {
55
60
  type: string;
56
61
  collection: boolean;
@@ -168,6 +173,8 @@ export class Host extends Base {
168
173
  get isTemplate(): true | RegExpMatchArray;
169
174
  get isModel(): boolean;
170
175
  get model(): any;
176
+ set aliases(value: Set<any>);
177
+ get aliases(): Set<any>;
171
178
  set extends(value: any[]);
172
179
  get extends(): any[];
173
180
  set master(value: boolean);
@@ -178,6 +185,8 @@ export class Host extends Base {
178
185
  get distribution(): any;
179
186
  get modelName(): any;
180
187
  get hostName(): string;
188
+ get domains(): Set<any>;
189
+ get domainNames(): any[];
181
190
  get domainName(): string;
182
191
  get host(): this;
183
192
  named(name: any): any;