pmcf 2.15.0 → 2.16.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.
@@ -1,13 +1,9 @@
1
1
  import { join } from "node:path";
2
2
  import { createHmac } from "node:crypto";
3
3
  import { FileContentProvider } from "npm-pkgbuild";
4
- import {
5
- writeLines,
6
- isIPv6Address,
7
- isLinkLocal,
8
- isLocalhost
9
- } from "../utils.mjs";
10
- import { DNSRecord, dnsFullName, reverseArpaAddress } from "../dns-utils.mjs";
4
+ import { writeLines } from "../utils.mjs";
5
+ import { isIPv6, isLinkLocal, isLocalhost, reverseArpa } from "../ip.mjs";
6
+ import { DNSRecord, dnsFullName } from "../dns-utils.mjs";
11
7
  import { addType } from "../types.mjs";
12
8
  import { ServiceTypeDefinition, serviceAddresses } from "../service.mjs";
13
9
  import {
@@ -211,9 +207,10 @@ export class DNSService extends ExtraSourceService {
211
207
  yield packageData;
212
208
  }
213
209
 
214
- const p2 = (packageData.dir = join(dir, "p2"));
210
+ const p2 = join(dir, "p2");
215
211
 
216
212
  packageData.properties = {
213
+ dir: p2,
217
214
  name: `named-zones-${name}`,
218
215
  description: `zone definitions for ${location.fullName}`,
219
216
  dependencies: ["mf-named"],
@@ -292,7 +289,7 @@ async function generateZoneDefs(dns, location, packageData) {
292
289
  for (const address of host.rawAddresses) {
293
290
  if (!isLocalhost(address)) {
294
291
  zone.records.add(
295
- DNSRecord("@", isIPv6Address(address) ? "AAAA" : "A", address)
292
+ DNSRecord("@", isIPv6(address) ? "AAAA" : "A", address)
296
293
  );
297
294
  }
298
295
  }
@@ -366,7 +363,7 @@ async function generateZoneDefs(dns, location, packageData) {
366
363
  zone.records.add(
367
364
  DNSRecord(
368
365
  dnsFullName(domainName),
369
- isIPv6Address(address) ? "AAAA" : "A",
366
+ isIPv6(address) ? "AAAA" : "A",
370
367
  address
371
368
  )
372
369
  );
@@ -375,11 +372,11 @@ async function generateZoneDefs(dns, location, packageData) {
375
372
  let reverseZone = reverseZones.get(subnet.address);
376
373
 
377
374
  if (!reverseZone) {
378
- const reverseArpa = reverseArpaAddress(subnet.prefix);
375
+ const id = reverseArpa(subnet.prefix);
379
376
  reverseZone = {
380
- id: reverseArpa,
377
+ id,
381
378
  type: "plain",
382
- file: `${locationName}/${reverseArpa}.zone`,
379
+ file: `${locationName}/${id}.zone`,
383
380
  records: new Set([SOARecord, NSRecord])
384
381
  };
385
382
  config.zones.push(reverseZone);
@@ -389,7 +386,7 @@ async function generateZoneDefs(dns, location, packageData) {
389
386
  for (const domainName of host.domainNames) {
390
387
  reverseZone.records.add(
391
388
  DNSRecord(
392
- dnsFullName(reverseArpaAddress(address)),
389
+ dnsFullName(reverseArpa(address)),
393
390
  "PTR",
394
391
  dnsFullName(domainName)
395
392
  )
package/src/subnet.mjs CHANGED
@@ -1,10 +1,4 @@
1
- import {
2
- normalizeCIDR,
3
- isLinkLocal,
4
- isIPv4Address,
5
- isIPv6Address,
6
- addressWithPrefixLength
7
- } from "./utils.mjs";
1
+ import { normalizeCIDR, isLinkLocal, isIPv4, isIPv6, prefixIP } from "./ip.mjs";
8
2
  import { Base } from "./base.mjs";
9
3
  import { addType } from "./types.mjs";
10
4
 
@@ -37,9 +31,13 @@ export class Subnet extends Base {
37
31
  }
38
32
 
39
33
  constructor(owner, address) {
40
- const { cidr } = normalizeCIDR(address);
34
+ const { longPrefix, prefix, prefixLength, cidr } = normalizeCIDR(address);
41
35
  super(owner, cidr);
42
36
  owner.addObject(this);
37
+
38
+ this.prefix = prefix;
39
+ this.prefixLength = prefixLength;
40
+ this.longPrefix = longPrefix;
43
41
  }
44
42
 
45
43
  get fullName() {
@@ -55,36 +53,20 @@ export class Subnet extends Base {
55
53
  }
56
54
 
57
55
  get isIPv4() {
58
- return isIPv4Address(this.address);
56
+ return isIPv4(this.address);
59
57
  }
60
58
 
61
59
  get isIPv6() {
62
- return isIPv6Address(this.address);
60
+ return isIPv6(this.address);
63
61
  }
64
62
 
65
63
  get addressRange() {
66
64
  return [
67
- addressWithPrefixLength(this.prefix, this.prefixLength),
65
+ prefixIP(this.prefix, this.prefixLength),
68
66
  this.prefix + ".255".repeat((32 - this.prefixLength) / 8)
69
67
  ];
70
68
  }
71
69
 
72
- get longPrefix() {
73
- return addressWithPrefixLength(this.prefix, this.prefixLength);
74
- }
75
-
76
- get prefix() {
77
- const [prefix] = this.name.split("/");
78
- return prefix;
79
- }
80
-
81
- get prefixLength() {
82
- const m = this.name.match(/\/(\d+)$/);
83
- if (m) {
84
- return parseInt(m[1]);
85
- }
86
- }
87
-
88
70
  get address() {
89
71
  return this.name;
90
72
  }
package/src/utils.mjs CHANGED
@@ -77,205 +77,3 @@ export function asIterator(value) {
77
77
 
78
78
  return asArray(value);
79
79
  }
80
-
81
- export function isIPv4Address(address) {
82
- switch (typeof address) {
83
- case "string":
84
- return address.indexOf(".") >= 0;
85
- }
86
-
87
- return false;
88
- }
89
-
90
- export function isIPv6Address(address) {
91
- switch (typeof address) {
92
- case "string":
93
- return address.indexOf(":") >= 0;
94
- }
95
-
96
- return false;
97
- }
98
-
99
- export function isLinkLocal(address) {
100
- switch (typeof address) {
101
- case "string":
102
- return address.startsWith("fe80");
103
-
104
- case "bigint":
105
- return ((address >> 112n) & 0xffffn) === 0xfe80n;
106
- }
107
-
108
- return false;
109
- }
110
-
111
- export function generateEU64(mac) {
112
- //TODO
113
- }
114
-
115
- export function isLocalhost(address) {
116
- const eaddr = encodeIP(address);
117
- return eaddr === IPV4_LOCALHOST || eaddr === IPV6_LOCALHOST;
118
- }
119
-
120
- export function normalizeIPAddress(address) {
121
- address = address.replace(/\/\d+$/, "");
122
- if (isIPv4Address(address)) {
123
- return address;
124
- }
125
- const parts = address.split(":");
126
- const i = parts.indexOf("");
127
- if (i >= 0) {
128
- parts.splice(i, 1, ..."0".repeat(9 - parts.length));
129
- }
130
- return parts.map(s => s.padStart(4, "0")).join(":");
131
- }
132
-
133
- const ipv4 = {
134
- separator: ".",
135
- length: 32,
136
- segmentLength: 8,
137
- segmentMask: 0xffn,
138
- mask: 0xffffffffn,
139
- base: 10
140
- };
141
- const ipv6 = {
142
- separator: ":",
143
- compressor: "::",
144
- length: 128,
145
- segmentLength: 16,
146
- segmentMask: 0xffffn,
147
- mask: 0xffffffffffffffffffffffffffffffffn,
148
- base: 16
149
- };
150
-
151
- export function addressWithPrefixLength(address, prefixLength) {
152
- const definition = ipv4;
153
-
154
- return (
155
- address +
156
- ".0".repeat((definition.length - prefixLength) / definition.segmentLength)
157
- );
158
- }
159
-
160
- function _decode(definition, address, length = definition.length) {
161
- if (typeof address === "string") {
162
- return address;
163
- }
164
-
165
- let result = "";
166
- let compressed = 0;
167
- let shift = definition.length;
168
- let word;
169
- const last = length / definition.segmentLength;
170
-
171
- for (let i = 0, j = 0; i < last; j = j + 1, i = j) {
172
- for (; j < last; j++) {
173
- shift -= definition.segmentLength;
174
- word = (address >> BigInt(shift)) & definition.segmentMask;
175
-
176
- if (word !== 0n || !definition.compressor || compressed > 0) {
177
- break;
178
- }
179
- }
180
-
181
- if (j > i + 1) {
182
- compressed++;
183
- result += definition.compressor;
184
- } else {
185
- if (result.length > 0) {
186
- result += definition.separator;
187
- }
188
- }
189
-
190
- if (j < last) {
191
- result += word.toString(definition.base);
192
- }
193
- }
194
-
195
- return result;
196
- }
197
-
198
- export function _encode(definition, address) {
199
- if (typeof address !== "string") {
200
- return address;
201
- }
202
-
203
- let res = 0n;
204
- let shift = BigInt(definition.length);
205
-
206
- for (const word of normalizeIPAddress(address)
207
- .split(definition.separator)
208
- .map(a => parseInt(a, definition.base))) {
209
- shift -= BigInt(definition.segmentLength);
210
- res += BigInt(word) << shift;
211
- }
212
-
213
- return res;
214
- }
215
-
216
- export function decodeIPv6(address, length) {
217
- return _decode(ipv6, address, length);
218
- }
219
-
220
- export function encodeIPv6(address) {
221
- return _encode(ipv6, address);
222
- }
223
-
224
- export function decodeIPv4(address, length) {
225
- return _decode(ipv4, address, length);
226
- }
227
-
228
- export function encodeIPv4(address) {
229
- return _encode(ipv4, address);
230
- }
231
-
232
- export function decodeIP(address, length) {
233
- return _decode(isIPv4Address(address) ? ipv4 : ipv6, address, length);
234
- }
235
-
236
- export function encodeIP(address) {
237
- return _encode(isIPv4Address(address) ? ipv4 : ipv6, address);
238
- }
239
-
240
- export function formatCIDR(address, subnet) {
241
- return subnet ? `${address}/${subnet.prefixLength}` : address;
242
- }
243
-
244
- export function normalizeCIDR(address) {
245
- let [prefix, prefixLength] = address.split(/\//);
246
-
247
- if (!prefixLength && isLinkLocal(address)) {
248
- prefix = "fe80::";
249
- prefixLength = 64;
250
- } else {
251
- const definition = isIPv6Address(prefix) ? ipv6 : ipv4;
252
- let n = _encode(definition, prefix);
253
-
254
- if (prefixLength) {
255
- n = n & (definition.mask << BigInt(definition.length - prefixLength));
256
- prefix = _decode(definition, n, prefixLength);
257
- } else {
258
- if (n === IPV4_LOCALHOST) {
259
- prefixLength = 8;
260
- prefix = _decode(definition, n, prefixLength);
261
- } else if (n === IPV6_LOCALHOST) {
262
- prefixLength = 128;
263
- prefix = _decode(definition, n, prefixLength);
264
- } else {
265
- return {};
266
- }
267
- }
268
- }
269
-
270
- return { prefix, prefixLength, cidr: `${prefix}/${prefixLength}` };
271
- }
272
-
273
- export function hasWellKnownSubnet(address) {
274
- const n = encodeIP(address);
275
- return n === IPV4_LOCALHOST || n === IPV6_LOCALHOST || isLinkLocal(address);
276
- }
277
-
278
- export const IPV4_LOCALHOST = _encode(ipv4, "127.0.0.1");
279
- export const IPV6_LOCALHOST = _encode(ipv6, "::1");
280
- export const IPV6_LINK_LOCAL_BROADCAST = _encode(ipv6, "ff02::1");
281
- export const IPV6_ROUTER_BROADCAST = _encode(ipv6, "ff02::2");
@@ -7,5 +7,3 @@ export function dnsFormatParameters(parameters: any): string;
7
7
  export function dnsMergeParameters(a: any, b: any): {
8
8
  [k: string]: Set<any>;
9
9
  };
10
- export function reverseAddress(address: any): any;
11
- export function reverseArpaAddress(address: any): string;
@@ -74,43 +74,43 @@ export class ExtraSourceService extends Service {
74
74
  collection: boolean;
75
75
  writeable: boolean;
76
76
  };
77
- port: {
77
+ alias: {
78
78
  type: string;
79
79
  collection: boolean;
80
80
  writeable: boolean;
81
81
  };
82
- protocol: {
82
+ weight: {
83
83
  type: string;
84
84
  collection: boolean;
85
85
  writeable: boolean;
86
- values: string[];
86
+ default: number;
87
87
  };
88
- alias: {
88
+ systemd: {
89
89
  type: string;
90
90
  collection: boolean;
91
91
  writeable: boolean;
92
92
  };
93
- type: {
93
+ port: {
94
94
  type: string;
95
95
  collection: boolean;
96
96
  writeable: boolean;
97
97
  };
98
- weight: {
98
+ protocol: {
99
99
  type: string;
100
100
  collection: boolean;
101
101
  writeable: boolean;
102
- default: number;
102
+ values: string[];
103
103
  };
104
- tls: {
104
+ type: {
105
105
  type: string;
106
106
  collection: boolean;
107
107
  writeable: boolean;
108
- default: boolean;
109
108
  };
110
- systemd: {
109
+ tls: {
111
110
  type: string;
112
111
  collection: boolean;
113
112
  writeable: boolean;
113
+ default: boolean;
114
114
  };
115
115
  hostName: {
116
116
  type: string;
package/types/ip.d.mts ADDED
@@ -0,0 +1,36 @@
1
+ export function IPV4(...args: any[]): any;
2
+ export function IPV6(...args: any[]): any;
3
+ export function encodeIP(address: any): any;
4
+ export function encodeIPv6(address: any): any;
5
+ export function encodeIPv4(address: any): any;
6
+ export function _encode(definition: any, address: any): any;
7
+ export function decodeIPv6(address: any, length: any): string;
8
+ export function decodeIPv4(address: any, length: any): string;
9
+ export function decodeIP(address: any, length: any): string;
10
+ export function isIPv4(address: any): boolean;
11
+ export function isIPv6(address: any): boolean;
12
+ export function _is(definition: any, address: any): boolean;
13
+ export function asBigInt(address: any): bigint;
14
+ export function prefixIP(address: any, length: any): string;
15
+ export function _prefix(definition: any, address: any, length: any): bigint;
16
+ export function normalizeCIDR(address: any): {
17
+ longPrefix?: undefined;
18
+ prefix?: undefined;
19
+ prefixLength?: undefined;
20
+ cidr?: undefined;
21
+ } | {
22
+ longPrefix: any;
23
+ prefix: any;
24
+ prefixLength: any;
25
+ cidr: string;
26
+ };
27
+ export function formatCIDR(address: any, subnet: any): any;
28
+ export function normalizeIP(address: any): string;
29
+ export function reverseArpa(address: any): string;
30
+ export function isLocalhost(address: any): boolean;
31
+ export function isLinkLocal(address: any): boolean;
32
+ export function hasWellKnownSubnet(address: any): boolean;
33
+ export const IPV6_LINK_LOCAL_BROADCAST: any;
34
+ export const IPV6_ROUTER_BROADCAST: any;
35
+ export const IPV4_LOCALHOST: any;
36
+ export const IPV6_LOCALHOST: any;
@@ -1,9 +1,54 @@
1
1
  export function serviceAddresses(sources: any, filter: any, addressType?: string, addressFilter?: (a: any) => boolean): any[];
2
2
  export function serviceEndpoints(sources: any, filter: any): any[];
3
- export namespace ServiceTypeDefinition {
3
+ export namespace endpointProperties {
4
+ export namespace port {
5
+ let type: string;
6
+ let collection: boolean;
7
+ let writeable: boolean;
8
+ }
9
+ export namespace protocol {
10
+ let type_1: string;
11
+ export { type_1 as type };
12
+ let collection_1: boolean;
13
+ export { collection_1 as collection };
14
+ let writeable_1: boolean;
15
+ export { writeable_1 as writeable };
16
+ export let values: string[];
17
+ }
18
+ export namespace type_2 {
19
+ let type_3: string;
20
+ export { type_3 as type };
21
+ let collection_2: boolean;
22
+ export { collection_2 as collection };
23
+ let writeable_2: boolean;
24
+ export { writeable_2 as writeable };
25
+ }
26
+ export { type_2 as type };
27
+ export namespace tls {
28
+ let type_4: string;
29
+ export { type_4 as type };
30
+ let collection_3: boolean;
31
+ export { collection_3 as collection };
32
+ let writeable_3: boolean;
33
+ export { writeable_3 as writeable };
34
+ let _default: boolean;
35
+ export { _default as default };
36
+ }
37
+ }
38
+ export namespace EndpointTypeDefinition {
4
39
  export let name: string;
5
40
  export let owners: string[];
6
41
  export let priority: number;
42
+ export let specializations: {};
43
+ export { endpointProperties as properties };
44
+ }
45
+ export namespace ServiceTypeDefinition {
46
+ let name_1: string;
47
+ export { name_1 as name };
48
+ let owners_1: string[];
49
+ export { owners_1 as owners };
50
+ let priority_1: number;
51
+ export { priority_1 as priority };
7
52
  let _extends: {
8
53
  name: string;
9
54
  owners: any[];
@@ -52,7 +97,8 @@ export namespace ServiceTypeDefinition {
52
97
  };
53
98
  };
54
99
  export { _extends as extends };
55
- export let specializations: {};
100
+ let specializations_1: {};
101
+ export { specializations_1 as specializations };
56
102
  export function factoryFor(value: any): any;
57
103
  export let properties: {
58
104
  ipAddresses: {
@@ -60,43 +106,43 @@ export namespace ServiceTypeDefinition {
60
106
  collection: boolean;
61
107
  writeable: boolean;
62
108
  };
63
- port: {
109
+ alias: {
64
110
  type: string;
65
111
  collection: boolean;
66
112
  writeable: boolean;
67
113
  };
68
- protocol: {
114
+ weight: {
69
115
  type: string;
70
116
  collection: boolean;
71
117
  writeable: boolean;
72
- values: string[];
118
+ default: number;
73
119
  };
74
- alias: {
120
+ systemd: {
75
121
  type: string;
76
122
  collection: boolean;
77
123
  writeable: boolean;
78
124
  };
79
- type: {
125
+ port: {
80
126
  type: string;
81
127
  collection: boolean;
82
128
  writeable: boolean;
83
129
  };
84
- weight: {
130
+ protocol: {
85
131
  type: string;
86
132
  collection: boolean;
87
133
  writeable: boolean;
88
- default: number;
134
+ values: string[];
89
135
  };
90
- tls: {
136
+ type: {
91
137
  type: string;
92
138
  collection: boolean;
93
139
  writeable: boolean;
94
- default: boolean;
95
140
  };
96
- systemd: {
141
+ tls: {
97
142
  type: string;
98
143
  collection: boolean;
99
144
  writeable: boolean;
145
+ default: boolean;
100
146
  };
101
147
  hostName: {
102
148
  type: string;
@@ -185,43 +231,43 @@ export class Service extends Base {
185
231
  collection: boolean;
186
232
  writeable: boolean;
187
233
  };
188
- port: {
234
+ alias: {
189
235
  type: string;
190
236
  collection: boolean;
191
237
  writeable: boolean;
192
238
  };
193
- protocol: {
239
+ weight: {
194
240
  type: string;
195
241
  collection: boolean;
196
242
  writeable: boolean;
197
- values: string[];
243
+ default: number;
198
244
  };
199
- alias: {
245
+ systemd: {
200
246
  type: string;
201
247
  collection: boolean;
202
248
  writeable: boolean;
203
249
  };
204
- type: {
250
+ port: {
205
251
  type: string;
206
252
  collection: boolean;
207
253
  writeable: boolean;
208
254
  };
209
- weight: {
255
+ protocol: {
210
256
  type: string;
211
257
  collection: boolean;
212
258
  writeable: boolean;
213
- default: number;
259
+ values: string[];
214
260
  };
215
- tls: {
261
+ type: {
216
262
  type: string;
217
263
  collection: boolean;
218
264
  writeable: boolean;
219
- default: boolean;
220
265
  };
221
- systemd: {
266
+ tls: {
222
267
  type: string;
223
268
  collection: boolean;
224
269
  writeable: boolean;
270
+ default: boolean;
225
271
  };
226
272
  hostName: {
227
273
  type: string;
@@ -268,6 +314,7 @@ export class Service extends Base {
268
314
  get addresses(): any;
269
315
  get networks(): any;
270
316
  get endpoints(): any[];
317
+ findEndpoints(filter: any): Generator<any, void, any>;
271
318
  set alias(value: any);
272
319
  get alias(): any;
273
320
  set port(value: any);