pmcf 3.12.1 → 3.13.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": "3.12.1",
3
+ "version": "3.13.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/endpoint.mjs CHANGED
@@ -10,7 +10,7 @@ class BaseEndpoint {
10
10
  }
11
11
 
12
12
  get type() {
13
- return this._type ?? this.service.type;
13
+ return this._type?.name ?? this.service.type;
14
14
  }
15
15
 
16
16
  get priority()
@@ -105,13 +105,14 @@ export const ServiceTypes = {
105
105
  ]
106
106
  },
107
107
  "dhcpv6-server": { endpoints: [{ family: "IPv6", port: 547, tls: false }] },
108
- smb: { endpoints: [{ protocol: "tcp", port: 445, tls: false }] },
109
- timemachine: {
110
- extends: ["smb"],
108
+ smb: {
111
109
  endpoints: [
112
110
  { family: "IPv4", protocol: "tcp", port: 445, tls: false },
113
111
  { family: "IPv6", protocol: "tcp", port: 445, tls: false }
114
- ],
112
+ ]
113
+ },
114
+ timemachine: {
115
+ extends: ["smb"],
115
116
  dnsRecord: {
116
117
  type: "TXT",
117
118
  parameters: {
@@ -124,47 +125,69 @@ export const ServiceTypes = {
124
125
  }
125
126
  };
126
127
 
127
- function prepareEndPoints(type, td) {
128
- if (td.endpoints) {
129
- td.endpoints.forEach(e => (e.type = type));
128
+ Object.entries(ServiceTypes).forEach(([name, type]) =>
129
+ addServiceType(type, name)
130
+ );
131
+
132
+ export function addServiceType(type, name) {
133
+ if (type) {
134
+ if (name) {
135
+ type.name = name;
136
+ }
137
+
138
+ ServiceTypes[type.name] = type;
139
+ if (type.endpoints) {
140
+ type.endpoints.forEach(e => (e.type = type));
141
+ } else {
142
+ type.endpoints = [];
143
+ }
144
+
145
+ if (type.services) {
146
+ Object.entries(type.services).forEach(([name, type]) =>
147
+ addServiceType(type, name)
148
+ );
149
+ } else {
150
+ type.services = {};
151
+ }
152
+
153
+ if (type.extends) {
154
+ type.extends = type.extends.map(t =>
155
+ typeof t === "string" ? ServiceTypes[t] : t
156
+ );
157
+ } else {
158
+ type.extends = [];
159
+ }
130
160
  }
161
+ return type;
131
162
  }
132
163
 
133
- Object.entries(ServiceTypes).forEach(([type, td]) =>
134
- prepareEndPoints(type, td)
135
- );
136
-
137
- export function addServiceTypes(st) {
138
- for (const [type, td] of Object.entries(st)) {
139
- ServiceTypes[type] = td;
140
- prepareEndPoints(type, td);
164
+ export function serviceTypes(type) {
165
+ if (type) {
166
+ let types = new Set([type.name]);
141
167
 
142
- if (td.services) {
143
- addServiceTypes(td.services);
168
+ for (const t of type.extends) {
169
+ types = types.union(serviceTypes(t));
144
170
  }
171
+
172
+ return types;
145
173
  }
174
+ return new Set();
146
175
  }
147
176
 
148
177
  export function serviceTypeEndpoints(type) {
149
- let td = ServiceTypes[type];
150
- if (td) {
151
- const all = td.services
152
- ? Object.keys(td.services)
178
+ if (type) {
179
+ const all = type.services
180
+ ? Object.values(type.services)
153
181
  .map(type => serviceTypeEndpoints(type))
154
182
  .flat()
155
183
  : [];
156
184
 
157
- if (td.extends) {
158
- all.push(
159
- td.extends.reduce(
160
- (a, c) => [...a, ...(ServiceTypes[c]?.endpoints || [])],
161
- []
162
- )
163
- );
185
+ if (type.extends) {
186
+ all.push(type.extends.reduce((a, c) => [...a, ...c?.endpoints], []));
164
187
  }
165
188
 
166
- if (td.endpoints) {
167
- all.push(td.endpoints);
189
+ if (type.endpoints) {
190
+ all.push(type.endpoints);
168
191
  }
169
192
 
170
193
  return all.flat();
package/src/service.mjs CHANGED
@@ -16,7 +16,11 @@ import {
16
16
  import { addType } from "./types.mjs";
17
17
  import { asArray } from "./utils.mjs";
18
18
  import { networkAddressAttributes } from "./network-support.mjs";
19
- import { serviceTypeEndpoints, ServiceTypes } from "./service-types.mjs";
19
+ import {
20
+ serviceTypeEndpoints,
21
+ serviceTypes,
22
+ ServiceTypes
23
+ } from "./service-types.mjs";
20
24
  import {
21
25
  DNSRecord,
22
26
  dnsFullName,
@@ -78,7 +82,6 @@ export class Service extends Base {
78
82
  _type;
79
83
  _port;
80
84
  _systemd;
81
- _extends = [];
82
85
 
83
86
  static {
84
87
  addType(this);
@@ -92,14 +95,6 @@ export class Service extends Base {
92
95
  return `${super.toString()}[${this.type}]`;
93
96
  }
94
97
 
95
- set extends(value) {
96
- this._extends.push(value);
97
- }
98
-
99
- get extends() {
100
- return this._extends;
101
- }
102
-
103
98
  get network() {
104
99
  return this.host.network;
105
100
  }
@@ -127,11 +122,11 @@ export class Service extends Base {
127
122
  }
128
123
 
129
124
  get serviceTypeEndpoints() {
130
- return serviceTypeEndpoints(this.type);
125
+ return serviceTypeEndpoints(ServiceTypes[this.type]);
131
126
  }
132
127
 
133
128
  endpoints(filter) {
134
- const data = serviceTypeEndpoints(this.type);
129
+ const data = serviceTypeEndpoints(ServiceTypes[this.type]);
135
130
  if (!data) {
136
131
  return [];
137
132
  }
@@ -195,7 +190,8 @@ export class Service extends Base {
195
190
 
196
191
  address(
197
192
  options = {
198
- endpoints: e => e.networkInterface && e.networkInterface.kind !== "loopbak",
193
+ endpoints: e =>
194
+ e.networkInterface && e.networkInterface.kind !== "loopbak",
199
195
  select: e => e.domainName || e.address,
200
196
  limit: 1,
201
197
  join: ""
@@ -224,7 +220,7 @@ export class Service extends Base {
224
220
  }
225
221
 
226
222
  get port() {
227
- return this._port ?? serviceTypeEndpoints(this.type)[0].port;
223
+ return this._port ?? serviceTypeEndpoints(ServiceTypes[this.type])[0].port;
228
224
  }
229
225
 
230
226
  set weight(value) {
@@ -244,7 +240,7 @@ export class Service extends Base {
244
240
  }
245
241
 
246
242
  get types() {
247
- return new Set([...this._extendedPropertyIterator("type", new Set())]);
243
+ return serviceTypes(ServiceTypes[this.type]);
248
244
  }
249
245
 
250
246
  get systemdServices() {
@@ -285,7 +281,7 @@ export class Service extends Base {
285
281
  if (parameters) {
286
282
  for (const service of this.findServices()) {
287
283
  if (service !== this) {
288
- const r = ServiceTypes[service.type]?.dnsRecord;
284
+ const r = ServiceTypes[service.type].dnsRecord;
289
285
 
290
286
  if (r?.type === dnsRecord.type) {
291
287
  parameters = dnsMergeParameters(parameters, r.parameters);
@@ -76,7 +76,6 @@ const BindServiceTypeDefinition = {
76
76
  minimum: { ...string_attribute_writable, default: 60000 },
77
77
  allowedUpdates: string_collection_attribute_writable
78
78
  },
79
-
80
79
  service: {
81
80
  extends: ["dns"],
82
81
  services: {
@@ -148,12 +147,6 @@ export class BindService extends ExtraSourceService {
148
147
 
149
148
  this._systemd = "bind.service";
150
149
 
151
- // TODO
152
- const dns = new Service(owner);
153
- dns.name = "dns";
154
- dns.type = "dns";
155
-
156
- this._extends.push(dns);
157
150
  this.views = {};
158
151
 
159
152
  for (const name of ["internal", "protected"]) {
@@ -538,7 +531,7 @@ export class BindService extends ExtraSourceService {
538
531
  zone.records.add(DNSRecord("location", "TXT", host.location.name));
539
532
  }
540
533
  for (const na of host.networkAddresses(
541
- na => na.networkInterface.kind != "loopback"
534
+ na => na.networkInterface.kind !== "loopback"
542
535
  )) {
543
536
  zone.records.add(
544
537
  DNSRecord("@", dnsRecordTypeForAddressFamily(na.family), na.address)
@@ -556,9 +549,7 @@ export class BindService extends ExtraSourceService {
556
549
  }
557
550
 
558
551
  get defaultRecords() {
559
- const nameService = this.findService(
560
- '(type="dns" || type="bind") && priority>=300'
561
- ); // TODO bind = dns ?
552
+ const nameService = this.findService('in("dns",types) && priority>=300');
562
553
 
563
554
  const SOARecord = DNSRecord(
564
555
  "@",
@@ -58,7 +58,6 @@ export class ChronyService extends ExtraSourceService {
58
58
 
59
59
  constructor(owner, data) {
60
60
  super(owner, data);
61
- this._extends.push(new Service(owner, { name: this.name, type: "ntp" }));
62
61
  this._systemd = "chronyd.service";
63
62
  }
64
63
 
@@ -87,7 +86,7 @@ export class ChronyService extends ExtraSourceService {
87
86
 
88
87
  const lines = [
89
88
  ...serviceEndpoints(this, {
90
- services: '(type="ntp" || type="chrony") && priority>=100',
89
+ services: 'in("ntp",types) && priority>=100',
91
90
  endpoints: e =>
92
91
  e.type === "ntp" &&
93
92
  !isLinkLocal(e.address) &&
@@ -8,21 +8,23 @@ const SystemdJournalRemoteServiceTypeDefinition = {
8
8
  extends: ServiceTypeDefinition,
9
9
  priority: 0.1,
10
10
  key: "name",
11
- services: {
12
- endpoints: [
13
- {
14
- family: "IPv4",
15
- port: 19532,
16
- protocol: "tcp",
17
- tls: false
18
- },
19
- {
20
- family: "IPv6",
21
- port: 19532,
22
- protocol: "tcp",
23
- tls: false
24
- }
25
- ]
11
+ service: {
12
+ services: {
13
+ endpoints: [
14
+ {
15
+ family: "IPv4",
16
+ port: 19532,
17
+ protocol: "tcp",
18
+ tls: false
19
+ },
20
+ {
21
+ family: "IPv6",
22
+ port: 19532,
23
+ protocol: "tcp",
24
+ tls: false
25
+ }
26
+ ]
27
+ }
26
28
  }
27
29
  };
28
30
 
@@ -11,8 +11,7 @@ const SystemdJournalUploadServiceTypeDefinition = {
11
11
  key: "name",
12
12
  attributes: {
13
13
  url: string_attribute_writable
14
- },
15
- service: {}
14
+ }
16
15
  };
17
16
 
18
17
  export class SystemdJournalUploadService extends Service {
@@ -7,8 +7,7 @@ const SystemdJournalServiceTypeDefinition = {
7
7
  owners: ServiceTypeDefinition.owners,
8
8
  extends: ServiceTypeDefinition,
9
9
  priority: 0.1,
10
- key: "name",
11
- service: {}
10
+ key: "name"
12
11
  };
13
12
 
14
13
  export class SystemdJournalService extends Service {
@@ -12,8 +12,7 @@ const SystemdResolvedServiceTypeDefinition = {
12
12
  owners: ServiceTypeDefinition.owners,
13
13
  extends: ExtraSourceServiceTypeDefinition,
14
14
  priority: 0.1,
15
- key: "name",
16
- service: {}
15
+ key: "name"
17
16
  };
18
17
 
19
18
  export class SystemdResolvedService extends ExtraSourceService {
@@ -36,7 +35,7 @@ export class SystemdResolvedService extends ExtraSourceService {
36
35
  systemdConfigs(name) {
37
36
  const options = (lower, upper, limit) => {
38
37
  return {
39
- services: `(type="dns" || type="bind") && priority>=${lower} && priority<=${upper}`,
38
+ services: `in("dns",types) && priority>=${lower} && priority<=${upper}`,
40
39
  endpoints: e =>
41
40
  e.networkInterface &&
42
41
  e.networkInterface.kind !== "loopback" &&
@@ -11,8 +11,7 @@ const SystemdTimesyncdServiceTypeDefinition = {
11
11
  extends: ExtraSourceServiceTypeDefinition,
12
12
  specializationOf: ServiceTypeDefinition,
13
13
  owners: ServiceTypeDefinition.owners,
14
- priority: 0.1,
15
- service: {}
14
+ priority: 0.1
16
15
  };
17
16
 
18
17
  export class SystemdTimesyncdService extends ExtraSourceService {
@@ -35,7 +34,7 @@ export class SystemdTimesyncdService extends ExtraSourceService {
35
34
  systemdConfigs(name) {
36
35
  const options = (lower, upper) => {
37
36
  return {
38
- services: `(type="ntp" || type="chrony") && priority >= ${lower} && priority <= ${upper}`,
37
+ services: `in("ntp",types) && priority >= ${lower} && priority <= ${upper}`,
39
38
  endpoints: e =>
40
39
  e.networkInterface && e.networkInterface.kind !== "loopback",
41
40
  select: endpoint => endpoint.address,
package/src/types.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  oneOfType,
5
5
  addType as paccAddType
6
6
  } from "pacc";
7
- import { addServiceTypes } from "./service-types.mjs";
7
+ import { addServiceType } from "./service-types.mjs";
8
8
  export { types };
9
9
 
10
10
  export function addType(clazz) {
@@ -15,10 +15,7 @@ export function addType(clazz) {
15
15
  type.specializationOf.specializations[type.name] = type;
16
16
  }
17
17
 
18
- if (type.service) {
19
- addServiceTypes({ [type.name]: type.service });
20
- }
21
-
18
+ addServiceType(type.service, type.name);
22
19
  paccAddType(type);
23
20
  }
24
21
 
@@ -1,4 +1,5 @@
1
- export function addServiceTypes(st: any): void;
1
+ export function addServiceType(type: any, name: any): any;
2
+ export function serviceTypes(type: any): Set<any>;
2
3
  export function serviceTypeEndpoints(type: any): any;
3
4
  export const ServiceTypes: {
4
5
  "pacman-repo": {
@@ -157,6 +158,7 @@ export const ServiceTypes: {
157
158
  };
158
159
  smb: {
159
160
  endpoints: {
161
+ family: string;
160
162
  protocol: string;
161
163
  port: number;
162
164
  tls: boolean;
@@ -164,12 +166,6 @@ export const ServiceTypes: {
164
166
  };
165
167
  timemachine: {
166
168
  extends: string[];
167
- endpoints: {
168
- family: string;
169
- protocol: string;
170
- port: number;
171
- tls: boolean;
172
- }[];
173
169
  dnsRecord: {
174
170
  type: string;
175
171
  parameters: {
@@ -670,9 +670,6 @@ export class Service extends Base {
670
670
  _type: any;
671
671
  _port: any;
672
672
  _systemd: any;
673
- _extends: any[];
674
- set extends(value: any[]);
675
- get extends(): any[];
676
673
  get host(): Host;
677
674
  hosts(): Generator<any, void, any>;
678
675
  get domainName(): any;
@@ -813,13 +813,15 @@ export class SystemdJournalRemoteService extends Service {
813
813
  };
814
814
  priority: number;
815
815
  key: string;
816
- services: {
817
- endpoints: {
818
- family: string;
819
- port: number;
820
- protocol: string;
821
- tls: boolean;
822
- }[];
816
+ service: {
817
+ services: {
818
+ endpoints: {
819
+ family: string;
820
+ port: number;
821
+ protocol: string;
822
+ tls: boolean;
823
+ }[];
824
+ };
823
825
  };
824
826
  };
825
827
  get type(): string;
@@ -816,7 +816,6 @@ export class SystemdJournalUploadService extends Service {
816
816
  attributes: {
817
817
  url: import("pacc").AttributeDefinition;
818
818
  };
819
- service: {};
820
819
  };
821
820
  get type(): string;
822
821
  get systemdServices(): string;
@@ -813,7 +813,6 @@ export class SystemdJournalService extends Service {
813
813
  };
814
814
  priority: number;
815
815
  key: string;
816
- service: {};
817
816
  };
818
817
  get type(): string;
819
818
  get systemdServices(): string;
@@ -1037,7 +1037,6 @@ export class SystemdResolvedService extends ExtraSourceService {
1037
1037
  };
1038
1038
  priority: number;
1039
1039
  key: string;
1040
- service: {};
1041
1040
  };
1042
1041
  get systemdServices(): string;
1043
1042
  systemdConfigs(name: any): {
@@ -1036,7 +1036,6 @@ export class SystemdTimesyncdService extends ExtraSourceService {
1036
1036
  };
1037
1037
  })[];
1038
1038
  priority: number;
1039
- service: {};
1040
1039
  };
1041
1040
  get systemdServices(): string;
1042
1041
  systemdConfigs(name: any): {