pmcf 2.12.0 → 2.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": "2.12.0",
3
+ "version": "2.13.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/host.mjs CHANGED
@@ -115,6 +115,9 @@ export class Host extends Base {
115
115
 
116
116
  _applyExtends(host) {
117
117
  for (const service of host.services) {
118
+
119
+ //present.extends.push(service);
120
+
118
121
  this.services = service.forOwner(this);
119
122
  }
120
123
 
package/src/service.mjs CHANGED
@@ -100,12 +100,13 @@ export const ServiceTypeDefinition = {
100
100
  };
101
101
 
102
102
  export class Service extends Base {
103
- alias;
103
+ _alias;
104
104
  _weight;
105
105
  _type;
106
106
  _port;
107
107
  _ipAddresses;
108
108
  _systemd;
109
+ _extends = [];
109
110
 
110
111
  static {
111
112
  addType(this);
@@ -120,6 +121,14 @@ export class Service extends Base {
120
121
  this.read(data, ServiceTypeDefinition);
121
122
  }
122
123
 
124
+ set extends(value) {
125
+ this._extends.push(value);
126
+ }
127
+
128
+ get extends() {
129
+ return this._extends;
130
+ }
131
+
123
132
  get network() {
124
133
  return this.server.network;
125
134
  }
@@ -158,14 +167,28 @@ export class Service extends Base {
158
167
 
159
168
  get endpoints() {
160
169
  if (!ServiceTypes[this.type]) {
161
- return [{ address: this.rawAddress, port: this._port, tls: false }];
170
+ return [
171
+ new Endpoint(this, {
172
+ rawAddress: this.rawAddress,
173
+ port: this._port,
174
+ tls: false
175
+ })
176
+ ];
162
177
  }
163
178
 
164
- return ServiceTypes[this.type].endpoints.map(e =>
165
- Object.assign({ address: this.rawAddress }, e)
179
+ return ServiceTypes[this.type].endpoints.map(
180
+ e => new Endpoint(this, { rawAddress: this.rawAddress, ...e })
166
181
  );
167
182
  }
168
183
 
184
+ set alias(value) {
185
+ this._alias = value;
186
+ }
187
+
188
+ get alias() {
189
+ return this.extendedProperty("_alias");
190
+ }
191
+
169
192
  set port(value) {
170
193
  this._port = value;
171
194
  }
@@ -187,7 +210,7 @@ export class Service extends Base {
187
210
  }
188
211
 
189
212
  get weight() {
190
- return this._weight ?? this.owner.weight ?? 1;
213
+ return this.extendedProperty("_weight") ?? this.owner.weight ?? 1;
191
214
  }
192
215
 
193
216
  set type(value) {
@@ -199,7 +222,7 @@ export class Service extends Base {
199
222
  }
200
223
 
201
224
  get systemdServices() {
202
- return this._systemd;
225
+ return this.extendedProperty("_systemd");
203
226
  }
204
227
 
205
228
  dnsRecordsForDomainName(domainName, hasSVRRecords) {
@@ -262,6 +285,13 @@ export class Service extends Base {
262
285
  }
263
286
  }
264
287
 
288
+ export class Endpoint {
289
+ constructor(service, data) {
290
+ this.service = service;
291
+ Object.assign(this, data);
292
+ }
293
+ }
294
+
265
295
  export const sortByPriority = (a, b) => a.priority - b.priority;
266
296
 
267
297
  export function serviceAddresses(
@@ -278,3 +308,12 @@ export function serviceAddresses(
278
308
  .flat()
279
309
  .filter(addressFilter);
280
310
  }
311
+
312
+ export function serviceEndpoints(sources, filter) {
313
+ return asArray(sources)
314
+ .map(ft => Array.from(ft.findServices(filter)))
315
+ .flat()
316
+ .sort(sortByPriority)
317
+ .map(service => service.endpoints)
318
+ .flat();
319
+ }
@@ -3,7 +3,7 @@ import { FileContentProvider } from "npm-pkgbuild";
3
3
  import {
4
4
  Service,
5
5
  ServiceTypeDefinition,
6
- serviceAddresses
6
+ serviceEndpoints
7
7
  } from "../service.mjs";
8
8
  import { addType } from "../types.mjs";
9
9
  import { writeLines } from "../utils.mjs";
@@ -42,7 +42,7 @@ export class DHCPService extends Service {
42
42
 
43
43
  console.log("kea", host.name, network.name);
44
44
 
45
- const dnsServerAddreses = serviceAddresses(network, {
45
+ const dnsServerEndpoints = serviceEndpoints(network, {
46
46
  type: "dns",
47
47
  priority: "<10"
48
48
  });
@@ -115,8 +115,8 @@ export class DHCPService extends Service {
115
115
  domains.map(domain => {
116
116
  return {
117
117
  name: domain,
118
- "dns-servers": dnsServerAddreses.map(address => {
119
- return { "ip-address": address };
118
+ "dns-servers": dnsServerEndpoints.map(endpoint => {
119
+ return { "ip-address": endpoint.rawAddress };
120
120
  })
121
121
  };
122
122
  });
@@ -1,7 +1,11 @@
1
1
  import { join } from "node:path";
2
2
  import { FileContentProvider } from "npm-pkgbuild";
3
3
  import { addType } from "../types.mjs";
4
- import { ServiceTypeDefinition, serviceAddresses } from "../service.mjs";
4
+ import {
5
+ ServiceTypeDefinition,
6
+ serviceAddresses,
7
+ serviceEndpoints
8
+ } from "../service.mjs";
5
9
  import {
6
10
  ExtraSourceService,
7
11
  ExtraSourceServiceTypeDefinition
@@ -81,10 +85,15 @@ export class NTPService extends ExtraSourceService {
81
85
  };
82
86
 
83
87
  const lines = [
84
- ...serviceAddresses(this, {
88
+ ...serviceEndpoints(this, {
85
89
  ...NTP_SERVICE_FILTER,
86
90
  priority: ">=10"
87
- }).map(address => `server ${address} iburst`),
91
+ }).map(
92
+ endpoint =>
93
+ `${endpoint.service.isPool ? "pool" : "server"} ${
94
+ endpoint.rawAddress
95
+ } iburst`
96
+ ),
88
97
  `mailonchange ${this.administratorEmail} 0.5`,
89
98
  "local stratum 10",
90
99
  "leapsectz right/UTC",
@@ -1,4 +1,5 @@
1
1
  export function serviceAddresses(sources: any, filter: any, addressType?: string, addressFilter?: (a: any) => boolean): any[];
2
+ export function serviceEndpoints(sources: any, filter: any): any[];
2
3
  export namespace ServiceTypeDefinition {
3
4
  export let name: string;
4
5
  export let owners: string[];
@@ -249,12 +250,15 @@ export class Service extends Base {
249
250
  };
250
251
  };
251
252
  };
252
- alias: any;
253
+ _alias: any;
253
254
  _weight: any;
254
255
  _type: any;
255
256
  _port: any;
256
257
  _ipAddresses: any;
257
258
  _systemd: any;
259
+ _extends: any[];
260
+ set extends(value: any[]);
261
+ get extends(): any[];
258
262
  get server(): any;
259
263
  get domainName(): any;
260
264
  get ipAddressOrDomainName(): any;
@@ -264,6 +268,8 @@ export class Service extends Base {
264
268
  get addresses(): any;
265
269
  get networks(): any;
266
270
  get endpoints(): any;
271
+ set alias(value: any);
272
+ get alias(): any;
267
273
  set port(value: any);
268
274
  get port(): any;
269
275
  get protocol(): any;
@@ -278,5 +284,9 @@ export class Service extends Base {
278
284
  toString: (maxKeyLength?: number, ttl?: string) => string;
279
285
  }[];
280
286
  }
287
+ export class Endpoint {
288
+ constructor(service: any, data: any);
289
+ service: any;
290
+ }
281
291
  export function sortByPriority(a: any, b: any): number;
282
292
  import { Base } from "./base.mjs";