pmcf 3.8.13 → 3.8.15

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": "3.8.13",
3
+ "version": "3.8.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -51,7 +51,7 @@
51
51
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
52
52
  },
53
53
  "dependencies": {
54
- "ip-utilties": "^1.4.8",
54
+ "ip-utilties": "^1.4.9",
55
55
  "npm-pkgbuild": "^18.2.29",
56
56
  "pacc": "^4.14.1",
57
57
  "package-directory": "^8.1.0"
package/src/base.mjs CHANGED
@@ -72,10 +72,6 @@ export class Base {
72
72
  case "object":
73
73
  this.read(data, BaseTypeDefinition);
74
74
  }
75
-
76
- if (this.name === undefined) {
77
- this.error("Missing name", this.owner?.toString(), data);
78
- }
79
75
  }
80
76
 
81
77
  ownerFor(property, data) {
@@ -94,7 +90,11 @@ export class Base {
94
90
  return this;
95
91
  }
96
92
 
97
- read(data, type) {
93
+ read(data, type=this.constructor.typeDefinition) {
94
+ if(type.extends) {
95
+ this.read(data, type.extends);
96
+ }
97
+
98
98
  const assign = (name, property, value) => {
99
99
  if (value === undefined && property.default !== undefined) {
100
100
  value = property.default;
@@ -178,6 +178,7 @@ export class Base {
178
178
  this.ownerFor(property, value),
179
179
  value
180
180
  );
181
+ object.read(value);
181
182
  this.addObject(object);
182
183
  } else {
183
184
  this.finalize(() => {
package/src/cluster.mjs CHANGED
@@ -35,10 +35,6 @@ export class Cluster extends Host {
35
35
  return ClusterTypeDefinition;
36
36
  }
37
37
 
38
- constructor(owner, data) {
39
- super(owner, data);
40
- this.read(data, ClusterTypeDefinition);
41
- }
42
38
 
43
39
  set masters(value) {
44
40
  this._masters.push(value);
@@ -22,11 +22,6 @@ export class ExtraSourceService extends Service {
22
22
  return ExtraSourceServiceTypeDefinition;
23
23
  }
24
24
 
25
- constructor(owner, data) {
26
- super(owner, data);
27
- this.read(data, ExtraSourceServiceTypeDefinition);
28
- }
29
-
30
25
  get type() {
31
26
  return ExtraSourceServiceTypeDefinition.name;
32
27
  }
package/src/host.mjs CHANGED
@@ -109,12 +109,13 @@ export class Host extends ServiceOwner {
109
109
 
110
110
  constructor(owner, data) {
111
111
  super(owner, data);
112
-
113
- this.read(data, HostTypeDefinition);
114
-
115
112
  owner.addObject(this);
113
+ }
116
114
 
117
- if (data.extends) {
115
+ read(data, type) {
116
+ super.read(data, type);
117
+
118
+ if (data?.extends) {
118
119
  this.finalize(() => {
119
120
  for (const host of this.extends) {
120
121
  host.execFinalize();
@@ -122,7 +123,6 @@ export class Host extends ServiceOwner {
122
123
  }
123
124
  });
124
125
  }
125
-
126
126
  this.extra = data.extra;
127
127
  }
128
128
 
package/src/location.mjs CHANGED
@@ -23,11 +23,6 @@ export class Location extends Owner {
23
23
  return LocationTypeDefinition;
24
24
  }
25
25
 
26
- constructor(owner, data) {
27
- super(owner, data);
28
- this.read(data, LocationTypeDefinition);
29
- }
30
-
31
26
  get location() {
32
27
  return this;
33
28
  }
@@ -30,11 +30,6 @@ export class EthernetNetworkInterface extends NetworkInterface {
30
30
  return name.match(/eth\d+$/);
31
31
  }
32
32
 
33
- constructor(owner, data) {
34
- super(owner, data);
35
- this.read(data, EthernetNetworkInterfaceTypeDefinition);
36
- }
37
-
38
33
  get kind() {
39
34
  return EthernetNetworkInterfaceTypeDefinition.name;
40
35
  }
@@ -33,11 +33,6 @@ export class LoopbackNetworkInterface extends SkeletonNetworkInterface {
33
33
  return name.match(/lo\d+$/);
34
34
  }
35
35
 
36
- constructor(owner, data) {
37
- super(owner, data);
38
- this.read(data, NetworkInterfaceTypeDefinition);
39
- }
40
-
41
36
  get kind() {
42
37
  return LoopbackNetworkInterfaceTypeDefinition.name;
43
38
  }
@@ -69,11 +69,6 @@ export class NetworkInterface extends SkeletonNetworkInterface {
69
69
  _hwaddr;
70
70
  _class;
71
71
 
72
- constructor(owner, data) {
73
- super(owner, data);
74
- this.read(data, NetworkInterfaceTypeDefinition);
75
- }
76
-
77
72
  addSubnet(address) {
78
73
  if (!this.network) {
79
74
  if (!hasWellKnownSubnet(address)) {
@@ -1,8 +1,8 @@
1
- import { SkeletonNetworkInterface } from "./skeleton.mjs";
1
+ import { NetworkInterface } from "./network-interface.mjs";
2
2
  import { NetworkInterfaceTypeDefinition } from "./network-interface.mjs";
3
3
  import { addType } from "../types.mjs";
4
4
 
5
- const WireguardNetworkInterfaceTypeDefinition = {
5
+ const TUNdNetworkInterfaceTypeDefinition = {
6
6
  name: "tun",
7
7
  specializationOf: NetworkInterfaceTypeDefinition,
8
8
  owners: NetworkInterfaceTypeDefinition.owners,
@@ -11,20 +11,16 @@ const WireguardNetworkInterfaceTypeDefinition = {
11
11
  properties: {}
12
12
  };
13
13
 
14
- export class TUNNetworkInterface extends SkeletonNetworkInterface {
14
+ export class TUNNetworkInterface extends NetworkInterface {
15
15
  static {
16
16
  addType(this);
17
17
  }
18
18
 
19
19
  static get typeDefinition() {
20
- return WireguardNetworkInterfaceTypeDefinition;
20
+ return TUNdNetworkInterfaceTypeDefinition;
21
21
  }
22
22
 
23
23
  get kind() {
24
- return WireguardNetworkInterfaceTypeDefinition.name;
25
- }
26
-
27
- get ipAddresses() {
28
- return new Map();
24
+ return TUNdNetworkInterfaceTypeDefinition.name;
29
25
  }
30
26
  }
package/src/network.mjs CHANGED
@@ -35,11 +35,6 @@ export class Network extends Owner {
35
35
  return NetworkTypeDefinition;
36
36
  }
37
37
 
38
- constructor(owner, data) {
39
- super(owner, data);
40
- this.read(data, NetworkTypeDefinition);
41
- }
42
-
43
38
  get network() {
44
39
  return this;
45
40
  }
package/src/owner.mjs CHANGED
@@ -44,11 +44,6 @@ export class Owner extends Base {
44
44
  return OwnerTypeDefinition;
45
45
  }
46
46
 
47
- constructor(owner, data) {
48
- super(owner, data);
49
- this.read(data, OwnerTypeDefinition);
50
- }
51
-
52
47
  _traverse(...args) {
53
48
  if (super._traverse(...args)) {
54
49
  for (const typeSlot of this._membersByType.values()) {
package/src/service.mjs CHANGED
@@ -86,11 +86,6 @@ export class Service extends Base {
86
86
  return ServiceTypeDefinition;
87
87
  }
88
88
 
89
- constructor(owner, data) {
90
- super(owner, data);
91
- this.read(data, ServiceTypeDefinition);
92
- }
93
-
94
89
  toString() {
95
90
  return `${super.toString()}[${this.type}]`;
96
91
  }
@@ -120,7 +120,6 @@ export class BindService extends ExtraSourceService {
120
120
  retry = 72000;
121
121
  expire = 600000;
122
122
  minimum = 60000;
123
-
124
123
  static {
125
124
  addType(this);
126
125
  }
@@ -133,7 +132,13 @@ export class BindService extends ExtraSourceService {
133
132
  super(owner, data);
134
133
 
135
134
  this._systemd = "bind.service";
136
- this._extends.push(new Service(owner, { name: this.name, type: "dns" }));
135
+
136
+ // TODO
137
+ const dns = new Service(owner);
138
+ dns.name = "dns";
139
+ dns.type = "dns";
140
+
141
+ this._extends.push(dns);
137
142
  this.views = {};
138
143
 
139
144
  for (const name of ["internal", "protected"]) {
@@ -145,8 +150,6 @@ export class BindService extends ExtraSourceService {
145
150
 
146
151
  this.views.protected.inView = this.views.internal;
147
152
  this.views.protected.access = ["!internal"];
148
-
149
- this.read(data, BindServiceTypeDefinition);
150
153
  }
151
154
 
152
155
  get type() {
@@ -58,11 +58,7 @@ export class ChronyService extends ExtraSourceService {
58
58
 
59
59
  constructor(owner, data) {
60
60
  super(owner, data);
61
-
62
61
  this._extends.push(new Service(owner, { name: this.name, type: "ntp" }));
63
-
64
- this.read(data, ChronyServiceTypeDefinition);
65
-
66
62
  this._systemd = "chronyd.service";
67
63
  }
68
64
 
@@ -44,11 +44,6 @@ export class InfluxdbService extends Service {
44
44
  return InfluxdbServiceTypeDefinition;
45
45
  }
46
46
 
47
- constructor(owner, data) {
48
- super(owner, data);
49
- this.read(data, InfluxdbServiceTypeDefinition);
50
- }
51
-
52
47
  get type() {
53
48
  return InfluxdbServiceTypeDefinition.name;
54
49
  }
@@ -136,11 +136,6 @@ export class KeaService extends Service {
136
136
  return KeaServiceTypeDefinition;
137
137
  }
138
138
 
139
- constructor(owner, data) {
140
- super(owner, data);
141
- this.read(data, KeaServiceTypeDefinition);
142
- }
143
-
144
139
  get type() {
145
140
  return KeaServiceTypeDefinition.name;
146
141
  }
@@ -415,6 +410,13 @@ export class KeaService extends Service {
415
410
  const subnets = [...this.subnets].filter(
416
411
  s => s !== SUBNET_LOCALHOST_IPV4 && s !== SUBNET_LOCALHOST_IPV6
417
412
  );
413
+
414
+ const pools = (subnet) => {
415
+ return subnet.dhcpPools.map(pool => {
416
+ return { pool: Array.isArray(pool) ? pool.join(" - ") : pool };
417
+ });
418
+ };
419
+
418
420
  const dhcp4 = {
419
421
  Dhcp4: {
420
422
  ...(await commonConfig("4")),
@@ -424,16 +426,14 @@ export class KeaService extends Service {
424
426
  return {
425
427
  id: index + 1,
426
428
  subnet: subnet.longAddress,
427
- pools: subnet.dhcpPools.map(range => {
428
- return { pool: range.join(" - ") };
429
- }),
429
+ pools: pools(subnet),
430
+ reservations: reservations(subnet, "4"),
430
431
  "option-data": [
431
432
  {
432
433
  name: "routers",
433
434
  data: network.gateway.address
434
435
  }
435
- ],
436
- reservations: reservations(subnet, "4")
436
+ ]
437
437
  };
438
438
  })
439
439
  }
@@ -447,9 +447,7 @@ export class KeaService extends Service {
447
447
  return {
448
448
  id: index + 1,
449
449
  subnet: subnet.longAddress,
450
- pools: subnet.dhcpPools.map(range => {
451
- return { pool: range.join(" - ") };
452
- }),
450
+ pools: pools(subnet),
453
451
  reservations: reservations(subnet, "6")
454
452
  };
455
453
  })
@@ -35,11 +35,6 @@ export class MosquittoService extends Service {
35
35
  return MosquittoServiceTypeDefinition;
36
36
  }
37
37
 
38
- constructor(owner, data) {
39
- super(owner, data);
40
- this.read(data, MosquittoServiceTypeDefinition);
41
- }
42
-
43
38
  get type() {
44
39
  return MosquittoServiceTypeDefinition.name;
45
40
  }
@@ -55,8 +55,6 @@ export class OpenLDAPService extends Service {
55
55
 
56
56
  constructor(owner, data) {
57
57
  super(owner, data);
58
- this.read(data, OpenLDAPServiceTypeDefinition);
59
-
60
58
  this._systemd = "slapd.service";
61
59
  }
62
60
 
@@ -35,11 +35,6 @@ export class SystemdJournalRemoteService extends Service {
35
35
  return SystemdJournalRemoteServiceTypeDefinition;
36
36
  }
37
37
 
38
- constructor(owner, data) {
39
- super(owner, data);
40
- this.read(data, SystemdJournalRemoteServiceTypeDefinition);
41
- }
42
-
43
38
  get type() {
44
39
  return SystemdJournalRemoteServiceTypeDefinition.name;
45
40
  }
@@ -23,11 +23,6 @@ export class SystemdJournalUploadService extends Service {
23
23
  return SystemdJournalUploadServiceTypeDefinition;
24
24
  }
25
25
 
26
- constructor(owner, data) {
27
- super(owner, data);
28
- this.read(data, SystemdJournalUploadServiceTypeDefinition);
29
- }
30
-
31
26
  get type() {
32
27
  return SystemdJournalUploadServiceTypeDefinition.name;
33
28
  }
@@ -20,11 +20,6 @@ export class SystemdJournalService extends Service {
20
20
  return SystemdJournalServiceTypeDefinition;
21
21
  }
22
22
 
23
- constructor(owner, data) {
24
- super(owner, data);
25
- this.read(data, SystemdJournalServiceTypeDefinition);
26
- }
27
-
28
23
  get type() {
29
24
  return SystemdJournalServiceTypeDefinition.name;
30
25
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ExtraSourceService,
3
+ ExtraSourceServiceTypeDefinition,
3
4
  ServiceTypeDefinition,
4
5
  serviceEndpoints
5
6
  } from "pmcf";
@@ -9,7 +10,7 @@ const SystemdResolvedServiceTypeDefinition = {
9
10
  name: "systemd-resolved",
10
11
  specializationOf: ServiceTypeDefinition,
11
12
  owners: ServiceTypeDefinition.owners,
12
- extends: ServiceTypeDefinition,
13
+ extends: ExtraSourceServiceTypeDefinition,
13
14
  priority: 0.1,
14
15
  properties: {},
15
16
  service: {}
@@ -24,11 +25,6 @@ export class SystemdResolvedService extends ExtraSourceService {
24
25
  return SystemdResolvedServiceTypeDefinition;
25
26
  }
26
27
 
27
- constructor(owner, data) {
28
- super(owner, data);
29
- this.read(data, SystemdResolvedServiceTypeDefinition);
30
- }
31
-
32
28
  get type() {
33
29
  return SystemdResolvedServiceTypeDefinition.name;
34
30
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ExtraSourceService,
3
+ ExtraSourceServiceTypeDefinition,
3
4
  ServiceTypeDefinition,
4
5
  serviceEndpoints
5
6
  } from "pmcf";
@@ -9,7 +10,7 @@ const SystemdTimesyncdServiceTypeDefinition = {
9
10
  name: "systemd-timesyncd",
10
11
  specializationOf: ServiceTypeDefinition,
11
12
  owners: ServiceTypeDefinition.owners,
12
- extends: ServiceTypeDefinition,
13
+ extends: ExtraSourceServiceTypeDefinition,
13
14
  priority: 0.1,
14
15
  properties: {},
15
16
  service: {}
@@ -24,11 +25,6 @@ export class SystemdTimesyncdService extends ExtraSourceService {
24
25
  return SystemdTimesyncdServiceTypeDefinition;
25
26
  }
26
27
 
27
- constructor(owner, data) {
28
- super(owner, data);
29
- this.read(data, SystemdTimesyncdServiceTypeDefinition);
30
- }
31
-
32
28
  get type() {
33
29
  return SystemdTimesyncdServiceTypeDefinition.name;
34
30
  }
package/src/subnet.mjs CHANGED
@@ -21,7 +21,8 @@ const SubnetTypeDefinition = {
21
21
  isKey: true
22
22
  },
23
23
  networks: { type: "network", collection: true, writable: true },
24
- prefixLength: { ...number_attribute }
24
+ prefixLength: { ...number_attribute },
25
+ family: { ...string_attribute }
25
26
  }
26
27
  };
27
28
 
@@ -66,8 +67,11 @@ export class Subnet extends Base {
66
67
 
67
68
  get dhcpPools() {
68
69
  /* TODO where to take values from ? */
70
+
69
71
  return [
70
- rangeIP(this.prefix, this.prefixLength, 51, 6).map(a => decodeIP(a))
72
+ this.family === "IPv6"
73
+ ? this.prefix
74
+ : rangeIP(this.prefix, this.prefixLength, 51, 6).map(a => decodeIP(a))
71
75
  ];
72
76
  }
73
77
 
package/src/types.mjs CHANGED
@@ -91,5 +91,7 @@ export function resolveTypeLinks() {
91
91
 
92
92
  export function typeFactory(type, owner, data) {
93
93
  const factory = type.factoryFor?.(owner, data) || type.clazz;
94
- return new factory(owner, data);
94
+ const object = new factory(owner);
95
+ object.read(data);
96
+ return object;
95
97
  }
package/types/base.d.mts CHANGED
@@ -61,7 +61,7 @@ export class Base {
61
61
  _finalize: any;
62
62
  _properties: any;
63
63
  ownerFor(property: any, data: any): any;
64
- read(data: any, type: any): void;
64
+ read(data: any, type?: any): void;
65
65
  named(name: any): void;
66
66
  typeNamed(typeName: any, name: any): any;
67
67
  addObject(object: any): any;
@@ -106,6 +106,20 @@ export class Cluster extends Host {
106
106
  get?: Function;
107
107
  env?: string[] | string;
108
108
  };
109
+ family: {
110
+ type: string;
111
+ isKey: boolean;
112
+ writable: boolean;
113
+ mandatory: boolean;
114
+ collection: boolean;
115
+ private?: boolean;
116
+ depends?: string;
117
+ description?: string;
118
+ default?: any;
119
+ set?: Function;
120
+ get?: Function;
121
+ env?: string[] | string;
122
+ };
109
123
  };
110
124
  };
111
125
  collection: boolean;
@@ -106,6 +106,20 @@ export class Location extends Owner {
106
106
  get?: Function;
107
107
  env?: string[] | string;
108
108
  };
109
+ family: {
110
+ type: string;
111
+ isKey: boolean;
112
+ writable: boolean;
113
+ mandatory: boolean;
114
+ collection: boolean;
115
+ private?: boolean;
116
+ depends?: string;
117
+ description?: string;
118
+ default?: any;
119
+ set?: Function;
120
+ get?: Function;
121
+ env?: string[] | string;
122
+ };
109
123
  };
110
124
  };
111
125
  collection: boolean;
@@ -317,6 +331,20 @@ export class Location extends Owner {
317
331
  get?: Function;
318
332
  env?: string[] | string;
319
333
  };
334
+ family: {
335
+ type: string;
336
+ isKey: boolean;
337
+ writable: boolean;
338
+ mandatory: boolean;
339
+ collection: boolean;
340
+ private?: boolean;
341
+ depends?: string;
342
+ description?: string;
343
+ default?: any;
344
+ set?: Function;
345
+ get?: Function;
346
+ env?: string[] | string;
347
+ };
320
348
  };
321
349
  };
322
350
  collection: boolean;
@@ -1,4 +1,4 @@
1
- export class TUNNetworkInterface extends SkeletonNetworkInterface {
1
+ export class TUNNetworkInterface extends NetworkInterface {
2
2
  static get typeDefinition(): {
3
3
  name: string;
4
4
  specializationOf: {
@@ -573,4 +573,4 @@ export class TUNNetworkInterface extends SkeletonNetworkInterface {
573
573
  };
574
574
  get kind(): string;
575
575
  }
576
- import { SkeletonNetworkInterface } from "./skeleton.mjs";
576
+ import { NetworkInterface } from "./network-interface.mjs";
@@ -108,6 +108,20 @@ export class Network extends Owner {
108
108
  get?: Function;
109
109
  env?: string[] | string;
110
110
  };
111
+ family: {
112
+ type: string;
113
+ isKey: boolean;
114
+ writable: boolean;
115
+ mandatory: boolean;
116
+ collection: boolean;
117
+ private?: boolean;
118
+ depends?: string;
119
+ description?: string;
120
+ default?: any;
121
+ set?: Function;
122
+ get?: Function;
123
+ env?: string[] | string;
124
+ };
111
125
  };
112
126
  };
113
127
  collection: boolean;
package/types/owner.d.mts CHANGED
@@ -104,6 +104,20 @@ export class Owner extends Base {
104
104
  get?: Function;
105
105
  env?: string[] | string;
106
106
  };
107
+ family: {
108
+ type: string;
109
+ isKey: boolean;
110
+ writable: boolean;
111
+ mandatory: boolean;
112
+ collection: boolean;
113
+ private?: boolean;
114
+ depends?: string;
115
+ description?: string;
116
+ default?: any;
117
+ set?: Function;
118
+ get?: Function;
119
+ env?: string[] | string;
120
+ };
107
121
  };
108
122
  };
109
123
  collection: boolean;
package/types/root.d.mts CHANGED
@@ -110,6 +110,20 @@ export class Root extends Location {
110
110
  get?: Function;
111
111
  env?: string[] | string;
112
112
  };
113
+ family: {
114
+ type: string;
115
+ isKey: boolean;
116
+ writable: boolean;
117
+ mandatory: boolean;
118
+ collection: boolean;
119
+ private?: boolean;
120
+ depends?: string;
121
+ description?: string;
122
+ default?: any;
123
+ set?: Function;
124
+ get?: Function;
125
+ env?: string[] | string;
126
+ };
113
127
  };
114
128
  };
115
129
  collection: boolean;
@@ -321,6 +335,20 @@ export class Root extends Location {
321
335
  get?: Function;
322
336
  env?: string[] | string;
323
337
  };
338
+ family: {
339
+ type: string;
340
+ isKey: boolean;
341
+ writable: boolean;
342
+ mandatory: boolean;
343
+ collection: boolean;
344
+ private?: boolean;
345
+ depends?: string;
346
+ description?: string;
347
+ default?: any;
348
+ set?: Function;
349
+ get?: Function;
350
+ env?: string[] | string;
351
+ };
324
352
  };
325
353
  };
326
354
  collection: boolean;