pmcf 1.41.1 → 1.42.1

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.41.1",
3
+ "version": "1.42.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import { getAttribute } from "pacc";
3
+ import { typesByName } from "./types.mjs";
3
4
 
4
5
  export class Base {
5
6
  owner;
@@ -10,6 +11,12 @@ export class Base {
10
11
  return "base";
11
12
  }
12
13
 
14
+ static get typeDefinition() {
15
+ return {
16
+ // name: { type: "string", collection: false }
17
+ };
18
+ }
19
+
13
20
  static get pluralTypeName() {
14
21
  return this.typeName + "s";
15
22
  }
@@ -47,6 +54,25 @@ export class Base {
47
54
  }
48
55
  }
49
56
 
57
+ read(data) {
58
+ for (const [slotName, typeDef] of Object.entries(
59
+ this.constructor.typeDefinition
60
+ )) {
61
+ const slot = data[slotName];
62
+ if (slot) {
63
+ delete data[slotName];
64
+ if (typeDef.collection) {
65
+ for (const [objectName, objectData] of Object.entries(slot)) {
66
+ objectData.name = objectName;
67
+ new typesByName[typeDef.type](this, objectData);
68
+ }
69
+ } else {
70
+ this[typeDef.type] = new typesByName[typeDef.type](this, slot);
71
+ }
72
+ }
73
+ }
74
+ }
75
+
50
76
  forOwner(owner) {
51
77
  if (this.owner !== owner) {
52
78
  // @ts-ignore
package/src/host.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Base } from "./base.mjs";
2
2
  import { Network } from "./network.mjs";
3
- import { Service } from "./service.mjs";
4
3
  import {
5
4
  asArray,
6
5
  isIPv4Address,
@@ -32,6 +31,13 @@ export class Host extends Base {
32
31
  return "host";
33
32
  }
34
33
 
34
+ static get typeDefinition() {
35
+ return {
36
+ networkInterfaces: { type: "network_interface", collection: true },
37
+ services: { type: "service", collection: true }
38
+ };
39
+ }
40
+
35
41
  static async prepareData(root, data) {
36
42
  if (data.extends) {
37
43
  data.extends = await Promise.all(
@@ -86,32 +92,14 @@ export class Host extends Base {
86
92
  delete data.provides;
87
93
  }
88
94
 
89
- if (data.services) {
90
- for (const [name, sd] of Object.entries(data.services)) {
91
- sd.name = name;
92
- new Service(this, sd);
93
- }
94
- delete data.services;
95
- }
96
-
97
- if (data.networkInterfaces) {
98
- for (const [name, iface] of Object.entries(data.networkInterfaces)) {
99
- iface.name = name;
100
- new NetworkInterface(this, iface);
101
- }
102
- delete data.networkInterfaces;
103
- }
104
-
105
95
  for (const host of this.extends) {
106
96
  for (const service of host.services()) {
107
97
  service.forOwner(this);
108
98
  }
109
-
110
- /*for (const ni of host.networkInterfaces.values()) {
111
- ni.forOwner(this);
112
- }*/
113
99
  }
114
100
 
101
+ this.read(data);
102
+
115
103
  Object.assign(this, data);
116
104
 
117
105
  owner.addObject(this);
package/src/owner.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { asArray, normalizeCIDR } from "./utils.mjs";
2
2
  import { Base } from "./base.mjs";
3
3
  import { Subnet } from "./subnet.mjs";
4
- import { addType, typesByName } from "./types.mjs";
4
+ import { addType } from "./types.mjs";
5
5
 
6
6
  export class Owner extends Base {
7
7
  #membersByType = new Map();
@@ -18,9 +18,12 @@ export class Owner extends Base {
18
18
  return "owner";
19
19
  }
20
20
 
21
- static get ownedTypes() {
21
+ static get typeDefinition() {
22
22
  return {
23
23
  networks: { type: "network", collection: true },
24
+ hosts: { type: "host", collection: true },
25
+ clusters: { type: "cluster", collection: true },
26
+ /* subnets: { type: "subnet", collection: true },*/
24
27
  dns: { type: "dns", collection: false }
25
28
  };
26
29
  }
@@ -43,22 +46,7 @@ export class Owner extends Base {
43
46
  delete data.ntp;
44
47
  }
45
48
 
46
- for (const [slotName, typeDef] of Object.entries(
47
- this.constructor.ownedTypes
48
- )) {
49
- const slot = data[slotName];
50
- if (slot) {
51
- delete data[slotName];
52
- if (typeDef.collection) {
53
- for (const [objectName, objectData] of Object.entries(slot)) {
54
- objectData.name = objectName;
55
- new typesByName[typeDef.type](this, objectData);
56
- }
57
- } else {
58
- this[typeDef.type] = new typesByName[typeDef.type](this, slot);
59
- }
60
- }
61
- }
49
+ this.read(data);
62
50
 
63
51
  owner?.addObject(this);
64
52
  }
@@ -118,9 +106,9 @@ export class Owner extends Base {
118
106
  this._addObject(object.typeName, object.fullName, object);
119
107
  }
120
108
 
121
- async service(filter) {
109
+ service(filter) {
122
110
  let best;
123
- for await (const service of this.services(filter)) {
111
+ for (const service of this.services(filter)) {
124
112
  if (!best || service.priority < best.priority) {
125
113
  best = service;
126
114
  }
@@ -129,9 +117,9 @@ export class Owner extends Base {
129
117
  return best;
130
118
  }
131
119
 
132
- async *services(filter) {
133
- for await (const host of this.hosts()) {
134
- for await (const service of host.services(filter)) {
120
+ *services(filter) {
121
+ for (const host of this.hosts()) {
122
+ for (const service of host.services(filter)) {
135
123
  yield service;
136
124
  }
137
125
  }
@@ -257,8 +245,8 @@ export class Owner extends Base {
257
245
  }
258
246
  }
259
247
 
260
- async *networkAddresses() {
261
- for await (const host of this.hosts()) {
248
+ *networkAddresses() {
249
+ for (const host of this.hosts()) {
262
250
  for (const networkAddresses of host.networkAddresses()) {
263
251
  yield networkAddresses;
264
252
  }
package/types/base.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  export function extractFrom(object: any): {};
2
2
  export class Base {
3
3
  static get typeName(): string;
4
+ static get typeDefinition(): {};
4
5
  static get pluralTypeName(): string;
5
6
  static get nameLookupName(): string;
6
7
  static get typeFileName(): string;
@@ -11,6 +12,7 @@ export class Base {
11
12
  owner: any;
12
13
  name: any;
13
14
  description: any;
15
+ read(data: any): void;
14
16
  forOwner(owner: any): any;
15
17
  get typeName(): any;
16
18
  get root(): any;
package/types/host.d.mts CHANGED
@@ -1,4 +1,14 @@
1
1
  export class Host extends Base {
2
+ static get typeDefinition(): {
3
+ networkInterfaces: {
4
+ type: string;
5
+ collection: boolean;
6
+ };
7
+ services: {
8
+ type: string;
9
+ collection: boolean;
10
+ };
11
+ };
2
12
  static prepareData(root: any, data: any): Promise<typeof Host>;
3
13
  postinstall: any[];
4
14
  _traverse(...args: any[]): boolean;
package/types/owner.d.mts CHANGED
@@ -1,9 +1,17 @@
1
1
  export class Owner extends Base {
2
- static get ownedTypes(): {
2
+ static get typeDefinition(): {
3
3
  networks: {
4
4
  type: string;
5
5
  collection: boolean;
6
6
  };
7
+ hosts: {
8
+ type: string;
9
+ collection: boolean;
10
+ };
11
+ clusters: {
12
+ type: string;
13
+ collection: boolean;
14
+ };
7
15
  dns: {
8
16
  type: string;
9
17
  collection: boolean;
@@ -21,8 +29,8 @@ export class Owner extends Base {
21
29
  typeList(typeName: any): any;
22
30
  _addObject(typeName: any, fullName: any, object: any): void;
23
31
  addObject(object: any): void;
24
- service(filter: any): Promise<any>;
25
- services(filter: any): AsyncGenerator<any, void, unknown>;
32
+ service(filter: any): any;
33
+ services(filter: any): Generator<any, void, unknown>;
26
34
  locationNamed(name: any): any;
27
35
  locations(): any;
28
36
  hostNamed(name: any): any;
@@ -37,7 +45,7 @@ export class Owner extends Base {
37
45
  clusters(): any;
38
46
  addBridge(network: any, destinationNetworks: any): any;
39
47
  _resolveBridges(): void;
40
- networkAddresses(): AsyncGenerator<any, void, unknown>;
48
+ networkAddresses(): Generator<any, void, unknown>;
41
49
  domains(): Generator<any, void, unknown>;
42
50
  #private;
43
51
  }