pmcf 1.43.2 → 1.44.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.43.2",
3
+ "version": "1.44.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -16,10 +16,11 @@ export class Base {
16
16
  return {
17
17
  name: "base",
18
18
  properties: {
19
- /* name: { type: "string" },
19
+ type: { type: "string", writeable: false },
20
+ name: { type: "string" },
20
21
  description: { type: "string" },
21
- directory: { type: "string" },
22
- owner: {}*/
22
+ directory: { type: "string", writeable: false },
23
+ owner: {}
23
24
  }
24
25
  };
25
26
  }
@@ -81,9 +82,18 @@ export class Base {
81
82
  }
82
83
  }
83
84
  } else {
84
- // if (typeDef.type) {
85
- this[typeDef.type] = new typesByName[typeDef.type](this, slot);
86
- // }
85
+ switch (typeDef.type) {
86
+ case "undefined":
87
+ break;
88
+ case "boolean":
89
+ case "string":
90
+ case "number":
91
+ this[slotName] = slot;
92
+ break;
93
+
94
+ default:
95
+ this[slotName] = new typesByName[typeDef.type](this, slot);
96
+ }
87
97
  }
88
98
  }
89
99
  }
@@ -100,7 +110,7 @@ export class Base {
100
110
 
101
111
  get typeName() {
102
112
  // @ts-ignore
103
- return this.constructor.typeName;
113
+ return this.constructor.typeDefinition.name;
104
114
  }
105
115
 
106
116
  get root() {
@@ -220,43 +230,71 @@ export class Base {
220
230
  return `${this.fullName}(${this.typeName})`;
221
231
  }
222
232
 
223
- get propertyNames() {
224
- return ["name", "description", "directory", "owner"];
225
- }
226
-
227
233
  toJSON() {
228
- return extractFrom(this);
234
+ return extractFrom(this, this.constructor.typeDefinition);
229
235
  }
230
236
  }
231
237
 
232
- export function extractFrom(object) {
233
- const json = {};
238
+ export function extractFrom(object, typeDefinition) {
239
+ if (!typeDefinition || object === undefined) {
240
+ return object;
241
+ }
234
242
 
235
- for (const p of object?.propertyNames || Object.keys(object)) {
236
- const value = object[p];
243
+ const json = {};
237
244
 
238
- switch (typeof value) {
239
- case "undefined":
240
- break;
241
- case "object":
242
- if (value instanceof Base) {
243
- json[p] = { type: value.typeName };
244
- if (value.name) {
245
- json[p].name = value.name;
245
+ do {
246
+ for (const [name, def] of Object.entries(typeDefinition.properties)) {
247
+ let value = object[name];
248
+
249
+ switch (typeof value) {
250
+ case "function":
251
+ {
252
+ value = object[name]();
253
+
254
+ if (Array.isArray(value)) {
255
+ if (value.length > 0) {
256
+ json[name] = value;
257
+ }
258
+ } else {
259
+ if (typeof value?.next === "function") {
260
+ value = [...value];
261
+ if (value.length > 0) {
262
+ json[name] = value;
263
+ }
264
+ } else {
265
+ json[name] = value;
266
+ }
267
+ }
246
268
  }
247
- } else {
248
- if (Array.isArray(value)) {
249
- json[p] = value;
269
+ break;
270
+ case "object":
271
+ if (value instanceof Base) {
272
+ json[name] = { type: value.typeName };
273
+ if (value.name) {
274
+ json[name].name = value.name;
275
+ }
250
276
  } else {
251
- json[p] = Object.fromEntries(
252
- Object.entries(value).map(([k, v]) => [k, extractFrom(v)])
253
- );
277
+ if (Array.isArray(value)) {
278
+ json[name] = value;
279
+ } else {
280
+ json[name] = Object.fromEntries(
281
+ Object.entries(value).map(([k, v]) => [
282
+ k,
283
+ extractFrom(v, typesByName[def.type])
284
+ ])
285
+ );
286
+ }
254
287
  }
255
- }
256
- break;
257
- default:
258
- json[p] = value;
288
+ break;
289
+ case "undefined":
290
+ break;
291
+
292
+ default:
293
+ json[name] = value;
294
+ }
259
295
  }
260
- }
296
+ typeDefinition = typeDefinition?.extends?.typeDefinition;
297
+ } while (typeDefinition);
298
+
261
299
  return json;
262
300
  }
package/src/cluster.mjs CHANGED
@@ -9,7 +9,7 @@ export class Cluster extends Owner {
9
9
  static get typeDefinition() {
10
10
  return {
11
11
  name: "cluster",
12
- extends: "owner",
12
+ extends: Owner,
13
13
  properties: {}
14
14
  };
15
15
  }
package/src/dns.mjs CHANGED
@@ -8,23 +8,22 @@ export class DNSService extends Base {
8
8
  soaUpdates = [36000, 72000, 600000, 60000];
9
9
  hasSVRRecords = true;
10
10
  hasCatalog = true;
11
-
12
11
  forwardsTo = [];
13
12
 
14
13
  static {
15
14
  addType(this);
16
15
  }
17
-
16
+
18
17
  static get typeDefinition() {
19
18
  return {
20
19
  name: "dns",
21
20
  properties: {
22
- /*recordTTL: {},
23
- soaUpdates: {},
24
- hasSVRRecords: {},
25
- hasCatalog: {},
26
- forwardsTo: {},
27
- allowedUpdates: {}*/
21
+ hasSVRRecords: { type: "boolean" },
22
+ hasCatalog: { type: "boolean" },
23
+ recordTTL: { type: "string" },
24
+ soaUpdates: { type: "number", collection: true },
25
+ forwardsTo: { type: "host", collection: true },
26
+ allowedUpdates: { type: "string", collection: true }
28
27
  }
29
28
  };
30
29
  }
@@ -50,17 +49,6 @@ export class DNSService extends Base {
50
49
  return [this.owner.domain];
51
50
  }
52
51
 
53
- get propertyNames() {
54
- return [
55
- "recordTTL",
56
- "soaUpdates",
57
- "hasSVRRecords",
58
- "hasCatalog",
59
- "forwardsTo",
60
- "allowedUpdates"
61
- ];
62
- }
63
-
64
52
  async resolvedConfig() {
65
53
  const dnsServices = (await Array.fromAsync(this.services())).sort(
66
54
  (a, b) => a.priority - b.priority
package/src/host.mjs CHANGED
@@ -30,17 +30,17 @@ export class Host extends Base {
30
30
  static get typeDefinition() {
31
31
  return {
32
32
  name: "host",
33
- extends: "base",
33
+ extends: Base,
34
34
  properties: {
35
35
  networkInterfaces: { type: "network_interface", collection: true },
36
- services: { type: "service", collection: true }
37
- /*os: {},
38
- distribution: {},
39
- deployment: {},
40
- master: { },
41
- model: {},
42
- replaces: { },
43
- depends: { }*/
36
+ services: { type: "service", collection: true },
37
+ os: { type: "string" },
38
+ distribution: { type: "string" },
39
+ deployment: { type: "string" },
40
+ master: { type: "boolean" },
41
+ model: { type: "string" },
42
+ replaces: { type: "string" },
43
+ depends: { type: "string" }
44
44
  }
45
45
  };
46
46
  }
@@ -273,20 +273,6 @@ export class Host extends Base {
273
273
  return readFile(join(this.directory, `ssh_host_${type}_key.pub`), "utf8");
274
274
  }
275
275
 
276
- get propertyNames() {
277
- return [
278
- ...super.propertyNames,
279
- "os",
280
- "distribution",
281
- "deployment",
282
- "master",
283
- "model",
284
- "replaces",
285
- "depends",
286
- "networkInterfaces"
287
- ];
288
- }
289
-
290
276
  toJSON() {
291
277
  return {
292
278
  ...super.toJSON(),
@@ -309,19 +295,18 @@ export class NetworkInterface extends Base {
309
295
  static get typeDefinition() {
310
296
  return {
311
297
  name: "network_interface",
312
- extends: "base",
298
+ extends: Base,
313
299
  properties: {
314
- /*
315
- arpbridge: {},
316
- hwaddr: {},
300
+ hwaddr: { type: "string" },
301
+ scope: { type: "string" },
302
+ kind: { type: "string" },
303
+ ssid: { type: "string" },
304
+ psk: { type: "string" },
305
+ metric: { type: "number" },
306
+ ipAddresses: { type: "string", collection: true },
317
307
  network: {},
318
308
  gateway: {},
319
- ssid: {},
320
- psk: {},
321
- scope: {},
322
- metric: {},
323
- kind: {},
324
- ipAddresses: {}*/
309
+ arpbridge: {}
325
310
  }
326
311
  };
327
312
  }
@@ -482,20 +467,4 @@ export class NetworkInterface extends Base {
482
467
  get kind() {
483
468
  return this.#kind || this.network?.kind;
484
469
  }
485
-
486
- get propertyNames() {
487
- return [
488
- ...super.propertyNames,
489
- "arpbridge",
490
- "hwaddr",
491
- "network",
492
- "gateway",
493
- "ssid",
494
- "psk",
495
- "scope",
496
- "metric",
497
- "kind",
498
- "ipAddresses"
499
- ];
500
- }
501
470
  }
package/src/location.mjs CHANGED
@@ -9,7 +9,7 @@ export class Location extends Owner {
9
9
  static get typeDefinition() {
10
10
  return {
11
11
  name: "location",
12
- extends: "owner",
12
+ extends: Owner,
13
13
  properties: {
14
14
  networks: { type: "network", collection: true },
15
15
  hosts: { type: "host", collection: true },
@@ -35,15 +35,4 @@ export class Location extends Owner {
35
35
  get network() {
36
36
  return [...this.typeList("network")][0] || super.network;
37
37
  }
38
-
39
- /*
40
- *subnets() {
41
- // yield* super.subnets();
42
-
43
- for(const network of this.networks()) {
44
- // console.log(network.toString());
45
- yield* network.typeList("subnet");
46
- }
47
- }
48
- */
49
38
  }
package/src/network.mjs CHANGED
@@ -16,18 +16,18 @@ export class Network extends Owner {
16
16
  static get typeDefinition() {
17
17
  return {
18
18
  name: "network",
19
- extends: "owner",
19
+ extends: Owner,
20
20
  properties: {
21
21
  networks: { type: "network", collection: true },
22
22
  hosts: { type: "host", collection: true },
23
23
  clusters: { type: "cluster", collection: true },
24
24
  subnets: { type: "subnet", collection: true },
25
- dns: { type: "dns", collection: false }
25
+ dns: { type: "dns", collection: false },
26
+ //metric: { type: "number" }
26
27
 
27
- /* kind: {},
28
- scope: {},
29
- metric: {},
30
- bridge: {},
28
+ /*kind: { type: "string" },
29
+ scope: { type: "string" },
30
+ /*bridge: {},
31
31
  gateway: {}*/
32
32
  }
33
33
  };
@@ -41,6 +41,8 @@ export class Network extends Owner {
41
41
  delete data.bridge;
42
42
  }
43
43
 
44
+ //this.read(data);
45
+
44
46
  Object.assign(this, data);
45
47
 
46
48
  if (typeof this.gateway === "string") {
@@ -73,15 +75,4 @@ export class Network extends Owner {
73
75
  set bridge(bridge) {
74
76
  this.#bridge = bridge;
75
77
  }
76
-
77
- get propertyNames() {
78
- return [
79
- ...super.propertyNames,
80
- "kind",
81
- "scope",
82
- "metric",
83
- "bridge",
84
- "gateway"
85
- ];
86
- }
87
78
  }
package/src/owner.mjs CHANGED
@@ -17,13 +17,15 @@ export class Owner extends Base {
17
17
  static get typeDefinition() {
18
18
  return {
19
19
  name: "owner",
20
- extends: "base",
20
+ extends: Base,
21
21
  properties: {
22
22
  networks: { type: "network", collection: true },
23
23
  hosts: { type: "host", collection: true },
24
24
  clusters: { type: "cluster", collection: true },
25
25
  subnets: { type: "subnet", collection: true },
26
- dns: { type: "dns", collection: false }
26
+ dns: { type: "dns", collection: false },
27
+ domain: { type: "string" },
28
+ administratorEmail: { type: "string" }
27
29
  }
28
30
  };
29
31
  }
@@ -284,10 +286,6 @@ export class Owner extends Base {
284
286
  }
285
287
  }
286
288
 
287
- get propertyNames() {
288
- return [...super.propertyNames, "domain", "administratorEmail", "dns"];
289
- }
290
-
291
289
  toJSON() {
292
290
  const json = super.toJSON();
293
291
 
package/src/root.mjs CHANGED
@@ -5,7 +5,6 @@ import { Location } from "./location.mjs";
5
5
  import { addType, types } from "./types.mjs";
6
6
 
7
7
  export class Root extends Location {
8
-
9
8
  static {
10
9
  addType(this);
11
10
  }
@@ -13,9 +12,8 @@ export class Root extends Location {
13
12
  static get typeDefinition() {
14
13
  return {
15
14
  name: "root",
16
- extends: "location",
17
- properties: {
18
- }
15
+ extends: Location,
16
+ properties: {}
19
17
  };
20
18
  }
21
19
 
package/src/service.mjs CHANGED
@@ -29,17 +29,17 @@ export class Service extends Base {
29
29
  static get typeDefinition() {
30
30
  return {
31
31
  name: "service",
32
- extends: "base",
32
+ extends: Base,
33
33
  properties: {
34
- /*ipAddresses: {},
34
+ ipAddresses: {},
35
35
  addresses: {},
36
- port: {},
37
- protocol: {},
38
- alias: {},
39
- type: {},
40
- master: {},
41
- priority: {},
42
- weight: {}*/
36
+ port: { type: "number" },
37
+ protocol: { type: "string" },
38
+ alias: { type: "string" },
39
+ type: { type: "string" },
40
+ master: { type: "boolean" },
41
+ priority: { type: "number" },
42
+ weight: { type: "number" }
43
43
  }
44
44
  };
45
45
  }
@@ -135,19 +135,4 @@ export class Service extends Base {
135
135
  get type() {
136
136
  return this.#type || this.name;
137
137
  }
138
-
139
- get propertyNames() {
140
- return [
141
- ...super.propertyNames,
142
- "ipAddresses",
143
- "addresses",
144
- "port",
145
- "protocol",
146
- "alias",
147
- "type",
148
- "master",
149
- "priority",
150
- "weight"
151
- ];
152
- }
153
138
  }
package/src/subnet.mjs CHANGED
@@ -12,13 +12,10 @@ export class Subnet extends Base {
12
12
  static get typeDefinition() {
13
13
  return {
14
14
  name: "subnet",
15
- extends: "base",
16
15
  properties: {
17
- /*
18
- address: {},
19
- networks: { type: "network", collection true },
16
+ address: { type: "string" },
17
+ networks: { type: "network", collection: true },
20
18
  prefixLength: { type: "number", writeable: false }
21
- */
22
19
  }
23
20
  };
24
21
  }
@@ -65,10 +62,6 @@ export class Subnet extends Base {
65
62
  return this.name;
66
63
  }
67
64
 
68
- get propertyNames() {
69
- return [...super.propertyNames, "networks", "prefixLength"];
70
- }
71
-
72
65
  _traverse(...args) {
73
66
  if (super._traverse(...args)) {
74
67
  for (const network of this.networks) {
package/types/base.d.mts CHANGED
@@ -1,9 +1,25 @@
1
- export function extractFrom(object: any): {};
1
+ export function extractFrom(object: any, typeDefinition: any): any;
2
2
  export class Base {
3
3
  static get typeName(): string;
4
4
  static get typeDefinition(): {
5
5
  name: string;
6
- properties: {};
6
+ properties: {
7
+ type: {
8
+ type: string;
9
+ writeable: boolean;
10
+ };
11
+ name: {
12
+ type: string;
13
+ };
14
+ description: {
15
+ type: string;
16
+ };
17
+ directory: {
18
+ type: string;
19
+ writeable: boolean;
20
+ };
21
+ owner: {};
22
+ };
7
23
  };
8
24
  static get nameLookupName(): string;
9
25
  static get typeFileName(): string;
@@ -34,7 +50,6 @@ export class Base {
34
50
  error(...args: any[]): void;
35
51
  info(...args: any[]): void;
36
52
  toString(): string;
37
- get propertyNames(): string[];
38
- toJSON(): {};
53
+ toJSON(): any;
39
54
  #private;
40
55
  }
@@ -1,7 +1,7 @@
1
1
  export class Cluster extends Owner {
2
2
  static get typeDefinition(): {
3
3
  name: string;
4
- extends: string;
4
+ extends: typeof Owner;
5
5
  properties: {};
6
6
  };
7
7
  constructor(owner: any, data: any);
package/types/dns.d.mts CHANGED
@@ -1,4 +1,30 @@
1
1
  export class DNSService extends Base {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ properties: {
5
+ hasSVRRecords: {
6
+ type: string;
7
+ };
8
+ hasCatalog: {
9
+ type: string;
10
+ };
11
+ recordTTL: {
12
+ type: string;
13
+ };
14
+ soaUpdates: {
15
+ type: string;
16
+ collection: boolean;
17
+ };
18
+ forwardsTo: {
19
+ type: string;
20
+ collection: boolean;
21
+ };
22
+ allowedUpdates: {
23
+ type: string;
24
+ collection: boolean;
25
+ };
26
+ };
27
+ };
2
28
  allowedUpdates: any[];
3
29
  recordTTL: string;
4
30
  soaUpdates: number[];
package/types/host.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  export class Host extends Base {
2
2
  static get typeDefinition(): {
3
3
  name: string;
4
- extends: string;
4
+ extends: typeof Base;
5
5
  properties: {
6
6
  networkInterfaces: {
7
7
  type: string;
@@ -11,6 +11,27 @@ export class Host extends Base {
11
11
  type: string;
12
12
  collection: boolean;
13
13
  };
14
+ os: {
15
+ type: string;
16
+ };
17
+ distribution: {
18
+ type: string;
19
+ };
20
+ deployment: {
21
+ type: string;
22
+ };
23
+ master: {
24
+ type: string;
25
+ };
26
+ model: {
27
+ type: string;
28
+ };
29
+ replaces: {
30
+ type: string;
31
+ };
32
+ depends: {
33
+ type: string;
34
+ };
14
35
  };
15
36
  };
16
37
  static prepareData(root: any, data: any): Promise<typeof Host>;
@@ -48,18 +69,39 @@ export class Host extends Base {
48
69
  get ipAddressesWithPrefixLength(): any[];
49
70
  get ipAddress(): any;
50
71
  publicKey(type?: string): Promise<any>;
51
- toJSON(): {
52
- extends: any[];
53
- networkInterfaces: any;
54
- services: any;
55
- };
56
72
  #private;
57
73
  }
58
74
  export class NetworkInterface extends Base {
59
75
  static get typeDefinition(): {
60
76
  name: string;
61
- extends: string;
62
- properties: {};
77
+ extends: typeof Base;
78
+ properties: {
79
+ hwaddr: {
80
+ type: string;
81
+ };
82
+ scope: {
83
+ type: string;
84
+ };
85
+ kind: {
86
+ type: string;
87
+ };
88
+ ssid: {
89
+ type: string;
90
+ };
91
+ psk: {
92
+ type: string;
93
+ };
94
+ metric: {
95
+ type: string;
96
+ };
97
+ ipAddresses: {
98
+ type: string;
99
+ collection: boolean;
100
+ };
101
+ network: {};
102
+ gateway: {};
103
+ arpbridge: {};
104
+ };
63
105
  };
64
106
  arpbridge: any;
65
107
  hwaddr: any;
@@ -1,4 +1,30 @@
1
1
  export class Location extends Owner {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: typeof Owner;
5
+ properties: {
6
+ networks: {
7
+ type: string;
8
+ collection: boolean;
9
+ };
10
+ hosts: {
11
+ type: string;
12
+ collection: boolean;
13
+ };
14
+ clusters: {
15
+ type: string;
16
+ collection: boolean;
17
+ };
18
+ subnets: {
19
+ type: string;
20
+ collection: boolean;
21
+ };
22
+ dns: {
23
+ type: string;
24
+ collection: boolean;
25
+ };
26
+ };
27
+ };
2
28
  get location(): this;
3
29
  }
4
30
  import { Owner } from "./owner.mjs";
@@ -1,4 +1,30 @@
1
1
  export class Network extends Owner {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: typeof Owner;
5
+ properties: {
6
+ networks: {
7
+ type: string;
8
+ collection: boolean;
9
+ };
10
+ hosts: {
11
+ type: string;
12
+ collection: boolean;
13
+ };
14
+ clusters: {
15
+ type: string;
16
+ collection: boolean;
17
+ };
18
+ subnets: {
19
+ type: string;
20
+ collection: boolean;
21
+ };
22
+ dns: {
23
+ type: string;
24
+ collection: boolean;
25
+ };
26
+ };
27
+ };
2
28
  constructor(owner: any, data: any);
3
29
  kind: any;
4
30
  scope: any;
package/types/owner.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  export class Owner extends Base {
2
2
  static get typeDefinition(): {
3
3
  name: string;
4
- extends: string;
4
+ extends: typeof Base;
5
5
  properties: {
6
6
  networks: {
7
7
  type: string;
@@ -23,6 +23,12 @@ export class Owner extends Base {
23
23
  type: string;
24
24
  collection: boolean;
25
25
  };
26
+ domain: {
27
+ type: string;
28
+ };
29
+ administratorEmail: {
30
+ type: string;
31
+ };
26
32
  };
27
33
  };
28
34
  constructor(owner: any, data?: {});
package/types/root.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  export class Root extends Location {
2
2
  static get typeDefinition(): {
3
3
  name: string;
4
- extends: string;
4
+ extends: typeof Location;
5
5
  properties: {};
6
6
  };
7
7
  constructor(directory: any);
@@ -1,8 +1,32 @@
1
1
  export class Service extends Base {
2
2
  static get typeDefinition(): {
3
3
  name: string;
4
- extends: string;
5
- properties: {};
4
+ extends: typeof Base;
5
+ properties: {
6
+ ipAddresses: {};
7
+ addresses: {};
8
+ port: {
9
+ type: string;
10
+ };
11
+ protocol: {
12
+ type: string;
13
+ };
14
+ alias: {
15
+ type: string;
16
+ };
17
+ type: {
18
+ type: string;
19
+ };
20
+ master: {
21
+ type: string;
22
+ };
23
+ priority: {
24
+ type: string;
25
+ };
26
+ weight: {
27
+ type: string;
28
+ };
29
+ };
6
30
  };
7
31
  alias: any;
8
32
  get protocol(): any;
@@ -1,8 +1,19 @@
1
1
  export class Subnet extends Base {
2
2
  static get typeDefinition(): {
3
3
  name: string;
4
- extends: string;
5
- properties: {};
4
+ properties: {
5
+ address: {
6
+ type: string;
7
+ };
8
+ networks: {
9
+ type: string;
10
+ collection: boolean;
11
+ };
12
+ prefixLength: {
13
+ type: string;
14
+ writeable: boolean;
15
+ };
16
+ };
6
17
  };
7
18
  networks: Set<any>;
8
19
  matchesAddress(address: any): any;