pmcf 1.5.2 → 1.5.3

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.5.2",
3
+ "version": "1.5.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -113,22 +113,24 @@ export class Base {
113
113
  }
114
114
  }
115
115
 
116
- export class World {
116
+ export class Owner extends Base {
117
+ addHost(host) {}
118
+ addNetwork(network) {}
119
+ async network(name) {}
120
+ }
121
+
122
+ export class World extends Owner {
117
123
  static get types() {
118
124
  return _types;
119
125
  }
120
126
 
121
- directory;
122
127
  #byName = new Map();
123
128
 
124
129
  constructor(directory) {
130
+ super(undefined, { name: "" });
125
131
  this.directory = directory;
126
132
  }
127
133
 
128
- get name() {
129
- return "";
130
- }
131
-
132
134
  get world() {
133
135
  return this;
134
136
  }
@@ -216,10 +218,6 @@ export class World {
216
218
  return this._loadType(name, Host);
217
219
  }
218
220
 
219
- addHost(host) {}
220
- addNetwork(network) {}
221
- network(name) {}
222
-
223
221
  async *subnets() {
224
222
  for await (const location of this.locations()) {
225
223
  yield* location.subnets();
@@ -235,219 +233,7 @@ export class World {
235
233
  }
236
234
  }
237
235
 
238
- export class Host extends Base {
239
- networkInterfaces = {};
240
- services = {};
241
- postinstall = [];
242
- #extends = [];
243
- #provides = new Set();
244
- #replaces = new Set();
245
- #depends = new Set();
246
- #master = false;
247
- #os;
248
- #distribution;
249
- #deployment;
250
- #location;
251
-
252
- static get typeName() {
253
- return "host";
254
- }
255
-
256
- static async prepareData(world, data) {
257
- if (data.location) {
258
- data.location = await world.location(data.location);
259
- }
260
-
261
- if (data.extends) {
262
- data.extends = await Promise.all(data.extends.map(e => world.host(e)));
263
- }
264
-
265
- if (data.name?.indexOf("model/") >= 0) {
266
- return Model;
267
- }
268
-
269
- return this;
270
- }
271
-
272
- constructor(owner, data) {
273
- super(owner, data);
274
-
275
- if (data.location !== undefined) {
276
- this.#location = data.location;
277
- delete data.location;
278
- }
279
-
280
- if (data.deployment !== undefined) {
281
- this.#deployment = data.deployment;
282
- delete data.deployment;
283
- }
284
- if (data.extends !== undefined) {
285
- this.#extends = data.extends;
286
- delete data.extends;
287
- }
288
- if (data.os !== undefined) {
289
- this.#os = data.os;
290
- delete data.os;
291
- }
292
- if (data.distribution !== undefined) {
293
- this.#distribution = data.distribution;
294
- delete data.distribution;
295
- }
296
- if (data.master !== undefined) {
297
- this.#master = data.master;
298
- delete data.master;
299
- }
300
- if (data.depends !== undefined) {
301
- this.#depends = new Set(data.depends);
302
- delete data.depends;
303
- }
304
- if (data.replaces !== undefined) {
305
- this.#replaces = new Set(data.replaces);
306
- delete data.replaces;
307
- }
308
- if (data.provides !== undefined) {
309
- this.#provides = new Set(data.provides);
310
- delete data.provides;
311
- }
312
-
313
- Object.assign(this, { services: {}, networkInterfaces: {} }, data);
314
-
315
- owner.addHost(this);
316
-
317
- for (const [name, iface] of Object.entries(this.networkInterfaces)) {
318
- iface.host = this;
319
- iface.name = name;
320
- if (iface.network) {
321
- iface.network = this.network(iface.network);
322
- }
323
- }
324
-
325
- for (const [name, data] of Object.entries(
326
- Object.assign({}, ...this.extends.map(e => e.services), this.services)
327
- )) {
328
- data.name = name;
329
- this.services[name] = new Service(this, data);
330
- }
331
- }
332
-
333
- get deployment() {
334
- return this.#deployment || this.extends.find(e => e.deployment);
335
- }
336
-
337
- get extends() {
338
- return this.#extends.map(e => this.expand(e));
339
- }
340
-
341
- get location() {
342
- return this.#location || super.location;
343
- }
344
-
345
- get provides() {
346
- let provides = new Set(this.#provides);
347
- this.extends.forEach(h => (provides = provides.union(h.provides)));
348
- return provides;
349
- }
350
-
351
- get replaces() {
352
- let replaces = new Set(this.#replaces);
353
- this.extends.forEach(h => (replaces = replaces.union(h.replaces)));
354
- return replaces;
355
- }
356
-
357
- get _depends() {
358
- let depends = this.#depends;
359
- this.extends.forEach(h => (depends = depends.union(h._depends)));
360
- return depends;
361
- }
362
-
363
- get depends() {
364
- return this.expand(this._depends);
365
- }
366
-
367
- get master() {
368
- return this.#master || this.extends.find(e => e.master) ? true : false;
369
- }
370
-
371
- get os() {
372
- return this.#os || this.extends.find(e => e.os);
373
- }
374
-
375
- get distribution() {
376
- return this.#distribution || this.extends.find(e => e.distribution);
377
- }
378
-
379
- get model() {
380
- return this.extends.find(h => h instanceof Model);
381
- }
382
-
383
- get domain() {
384
- return this.location?.domain;
385
- }
386
-
387
- get modelName() {
388
- return this.model?.hostName;
389
- }
390
-
391
- get hostName() {
392
- const parts = this.name.split(/\//);
393
- return parts[parts.length - 1];
394
- }
395
-
396
- get domainName() {
397
- return this.hostName + "." + this.domain;
398
- }
399
-
400
- *networkAddresses() {
401
- for (const [name, networkInterface] of Object.entries(
402
- this.networkInterfaces
403
- )) {
404
- for (const attribute of ["ipv4", "ipv6", "link-local-ipv6"]) {
405
- if (networkInterface[attribute]) {
406
- yield { address: networkInterface[attribute], networkInterface };
407
- }
408
- }
409
- }
410
- }
411
-
412
- get ipAddress() {
413
- for (const a of this.networkAddresses()) {
414
- return a.address;
415
- }
416
- }
417
-
418
- async publicKey(type = "ed25519") {
419
- return readFile(join(this.directory, `ssh_host_${type}_key.pub`), "utf8");
420
- }
421
-
422
- get propertyNames() {
423
- return [
424
- ...super.propertyNames,
425
- "os",
426
- "distribution",
427
- "deployment",
428
- "master",
429
- "location",
430
- "model",
431
- "replaces",
432
- "depends",
433
- "networkInterfaces"
434
- ];
435
- }
436
-
437
- toJSON() {
438
- return {
439
- ...super.toJSON(),
440
- extends: this.extends.map(host => host.name),
441
- services: Object.fromEntries(
442
- Object.values(this.services).map(s => [s.name, s.toJSON()])
443
- )
444
- };
445
- }
446
- }
447
-
448
- export class Model extends Host {}
449
-
450
- export class Location extends Base {
236
+ export class Location extends Owner {
451
237
  domain;
452
238
  dns;
453
239
  #administratorEmail;
@@ -556,7 +342,7 @@ export class Location extends Base {
556
342
  return network;
557
343
  }
558
344
 
559
- if(data instanceof Network) {
345
+ if (data instanceof Network) {
560
346
  this.#networks.set(data.name, data);
561
347
  return data;
562
348
  }
@@ -666,6 +452,219 @@ export class Network extends Base {
666
452
  }
667
453
  }
668
454
 
455
+ export class Host extends Base {
456
+ networkInterfaces = {};
457
+ services = {};
458
+ postinstall = [];
459
+ #extends = [];
460
+ #provides = new Set();
461
+ #replaces = new Set();
462
+ #depends = new Set();
463
+ #master = false;
464
+ #os;
465
+ #distribution;
466
+ #deployment;
467
+ #location;
468
+
469
+ static get typeName() {
470
+ return "host";
471
+ }
472
+
473
+ static async prepareData(world, data) {
474
+ if (data.location) {
475
+ data.location = await world.location(data.location);
476
+ }
477
+
478
+ if (data.extends) {
479
+ data.extends = await Promise.all(data.extends.map(e => world.host(e)));
480
+ }
481
+
482
+ if (data.name?.indexOf("model/") >= 0) {
483
+ return Model;
484
+ }
485
+
486
+ return this;
487
+ }
488
+
489
+ constructor(owner, data) {
490
+ super(owner, data);
491
+
492
+ if (data.location !== undefined) {
493
+ this.#location = data.location;
494
+ delete data.location;
495
+ }
496
+
497
+ if (data.deployment !== undefined) {
498
+ this.#deployment = data.deployment;
499
+ delete data.deployment;
500
+ }
501
+ if (data.extends !== undefined) {
502
+ this.#extends = data.extends;
503
+ delete data.extends;
504
+ }
505
+ if (data.os !== undefined) {
506
+ this.#os = data.os;
507
+ delete data.os;
508
+ }
509
+ if (data.distribution !== undefined) {
510
+ this.#distribution = data.distribution;
511
+ delete data.distribution;
512
+ }
513
+ if (data.master !== undefined) {
514
+ this.#master = data.master;
515
+ delete data.master;
516
+ }
517
+ if (data.depends !== undefined) {
518
+ this.#depends = new Set(data.depends);
519
+ delete data.depends;
520
+ }
521
+ if (data.replaces !== undefined) {
522
+ this.#replaces = new Set(data.replaces);
523
+ delete data.replaces;
524
+ }
525
+ if (data.provides !== undefined) {
526
+ this.#provides = new Set(data.provides);
527
+ delete data.provides;
528
+ }
529
+
530
+ Object.assign(this, { services: {}, networkInterfaces: {} }, data);
531
+
532
+ owner.addHost(this);
533
+
534
+ for (const [name, iface] of Object.entries(this.networkInterfaces)) {
535
+ iface.host = this;
536
+ iface.name = name;
537
+ if (iface.network) {
538
+ iface.network = this.network(iface.network);
539
+ }
540
+ }
541
+
542
+ for (const [name, data] of Object.entries(
543
+ Object.assign({}, ...this.extends.map(e => e.services), this.services)
544
+ )) {
545
+ data.name = name;
546
+ this.services[name] = new Service(this, data);
547
+ }
548
+ }
549
+
550
+ get deployment() {
551
+ return this.#deployment || this.extends.find(e => e.deployment);
552
+ }
553
+
554
+ get extends() {
555
+ return this.#extends.map(e => this.expand(e));
556
+ }
557
+
558
+ get location() {
559
+ return this.#location || super.location;
560
+ }
561
+
562
+ get provides() {
563
+ let provides = new Set(this.#provides);
564
+ this.extends.forEach(h => (provides = provides.union(h.provides)));
565
+ return provides;
566
+ }
567
+
568
+ get replaces() {
569
+ let replaces = new Set(this.#replaces);
570
+ this.extends.forEach(h => (replaces = replaces.union(h.replaces)));
571
+ return replaces;
572
+ }
573
+
574
+ get _depends() {
575
+ let depends = this.#depends;
576
+ this.extends.forEach(h => (depends = depends.union(h._depends)));
577
+ return depends;
578
+ }
579
+
580
+ get depends() {
581
+ return this.expand(this._depends);
582
+ }
583
+
584
+ get master() {
585
+ return this.#master || this.extends.find(e => e.master) ? true : false;
586
+ }
587
+
588
+ get os() {
589
+ return this.#os || this.extends.find(e => e.os);
590
+ }
591
+
592
+ get distribution() {
593
+ return this.#distribution || this.extends.find(e => e.distribution);
594
+ }
595
+
596
+ get model() {
597
+ return this.extends.find(h => h instanceof Model);
598
+ }
599
+
600
+ get domain() {
601
+ return this.location?.domain;
602
+ }
603
+
604
+ get modelName() {
605
+ return this.model?.hostName;
606
+ }
607
+
608
+ get hostName() {
609
+ const parts = this.name.split(/\//);
610
+ return parts[parts.length - 1];
611
+ }
612
+
613
+ get domainName() {
614
+ return this.hostName + "." + this.domain;
615
+ }
616
+
617
+ *networkAddresses() {
618
+ for (const [name, networkInterface] of Object.entries(
619
+ this.networkInterfaces
620
+ )) {
621
+ for (const attribute of ["ipv4", "ipv6", "link-local-ipv6"]) {
622
+ if (networkInterface[attribute]) {
623
+ yield { address: networkInterface[attribute], networkInterface };
624
+ }
625
+ }
626
+ }
627
+ }
628
+
629
+ get ipAddress() {
630
+ for (const a of this.networkAddresses()) {
631
+ return a.address;
632
+ }
633
+ }
634
+
635
+ async publicKey(type = "ed25519") {
636
+ return readFile(join(this.directory, `ssh_host_${type}_key.pub`), "utf8");
637
+ }
638
+
639
+ get propertyNames() {
640
+ return [
641
+ ...super.propertyNames,
642
+ "os",
643
+ "distribution",
644
+ "deployment",
645
+ "master",
646
+ "location",
647
+ "model",
648
+ "replaces",
649
+ "depends",
650
+ "networkInterfaces"
651
+ ];
652
+ }
653
+
654
+ toJSON() {
655
+ return {
656
+ ...super.toJSON(),
657
+ extends: this.extends.map(host => host.name),
658
+ services: Object.fromEntries(
659
+ Object.values(this.services).map(s => [s.name, s.toJSON()])
660
+ )
661
+ };
662
+ }
663
+ }
664
+
665
+ export class Model extends Host {}
666
+
667
+
669
668
  export class Subnet extends Base {
670
669
  networks = new Set();
671
670
 
package/types/model.d.mts CHANGED
@@ -23,13 +23,16 @@ export class Base {
23
23
  toJSON(): {};
24
24
  #private;
25
25
  }
26
- export class World {
26
+ export class Owner extends Base {
27
+ addHost(host: any): void;
28
+ addNetwork(network: any): void;
29
+ network(name: any): Promise<void>;
30
+ }
31
+ export class World extends Owner {
27
32
  static get types(): {
28
33
  [k: string]: typeof Location | typeof Host | typeof Network | typeof Subnet | typeof Service;
29
34
  };
30
35
  constructor(directory: any);
31
- directory: any;
32
- get name(): string;
33
36
  get world(): this;
34
37
  _loadType(name: any, type: any): Promise<any>;
35
38
  load(): Promise<void>;
@@ -39,9 +42,6 @@ export class World {
39
42
  domains(): AsyncGenerator<any, void, unknown>;
40
43
  location(name: any): Promise<any>;
41
44
  host(name: any): Promise<any>;
42
- addHost(host: any): void;
43
- addNetwork(network: any): void;
44
- network(name: any): void;
45
45
  subnets(): AsyncGenerator<any, void, unknown>;
46
46
  networkAddresses(): AsyncGenerator<{
47
47
  address: any;
@@ -49,6 +49,37 @@ export class World {
49
49
  }, void, unknown>;
50
50
  #private;
51
51
  }
52
+ export class Location extends Owner {
53
+ domain: any;
54
+ dns: any;
55
+ hosts(): AsyncGenerator<any, void, unknown>;
56
+ service(filter: any): Promise<any>;
57
+ services(filter: any): AsyncGenerator<any, void, unknown>;
58
+ networkAddresses(): AsyncGenerator<any, void, unknown>;
59
+ network(name: any): Promise<any>;
60
+ networks(): AsyncGenerator<any, void, unknown>;
61
+ subnets(): AsyncGenerator<any, void, unknown>;
62
+ addNetwork(data: any): any;
63
+ get dnsAllowedUpdates(): any;
64
+ get dnsRecordTTL(): any;
65
+ get administratorEmail(): any;
66
+ toJSON(): {
67
+ hosts: any[];
68
+ };
69
+ #private;
70
+ }
71
+ export class Network extends Base {
72
+ kind: any;
73
+ scope: any;
74
+ metric: any;
75
+ ipv4: any;
76
+ ipv4_netmask: any;
77
+ subnet: any;
78
+ get subnetAddress(): any;
79
+ hosts(): AsyncGenerator<any, void, unknown>;
80
+ addHost(host: any): void;
81
+ #private;
82
+ }
52
83
  export class Host extends Base {
53
84
  static prepareData(world: any, data: any): Promise<typeof Host>;
54
85
  networkInterfaces: {};
@@ -82,37 +113,6 @@ export class Host extends Base {
82
113
  }
83
114
  export class Model extends Host {
84
115
  }
85
- export class Location extends Base {
86
- domain: any;
87
- dns: any;
88
- hosts(): AsyncGenerator<any, void, unknown>;
89
- service(filter: any): Promise<any>;
90
- services(filter: any): AsyncGenerator<any, void, unknown>;
91
- networkAddresses(): AsyncGenerator<any, void, unknown>;
92
- networks(): AsyncGenerator<any, void, unknown>;
93
- subnets(): AsyncGenerator<any, void, unknown>;
94
- addNetwork(data: any): any;
95
- addHost(host: any): void;
96
- get dnsAllowedUpdates(): any;
97
- get dnsRecordTTL(): any;
98
- get administratorEmail(): any;
99
- toJSON(): {
100
- hosts: any[];
101
- };
102
- #private;
103
- }
104
- export class Network extends Base {
105
- kind: any;
106
- scope: any;
107
- metric: any;
108
- ipv4: any;
109
- ipv4_netmask: any;
110
- subnet: any;
111
- get subnetAddress(): any;
112
- hosts(): AsyncGenerator<any, void, unknown>;
113
- addHost(host: any): void;
114
- #private;
115
- }
116
116
  export class Subnet extends Base {
117
117
  networks: Set<any>;
118
118
  get address(): any;