pmcf 2.16.0 → 2.17.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": "2.16.0",
3
+ "version": "2.17.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/ip.mjs CHANGED
@@ -21,8 +21,7 @@ const ipv6 = {
21
21
  if (i >= 0) {
22
22
  parts.splice(i, 1, ..."0".repeat(9 - parts.length));
23
23
  }
24
- return parts /*.map(s => s.padStart(4, "0"))*/
25
- .join(":");
24
+ return parts.join(":");
26
25
  },
27
26
  separator: ":",
28
27
  compressor: "::",
@@ -51,7 +50,8 @@ function _create(definition, ...args) {
51
50
  }
52
51
 
53
52
  export function encodeIP(address) {
54
- return _encode(isIPv4(address) ? ipv4 : ipv6, address);
53
+ const d = _definition(address);
54
+ return d && _encode(d, address);
55
55
  }
56
56
 
57
57
  export function encodeIPv6(address) {
@@ -76,6 +76,9 @@ export function _encode(definition, address) {
76
76
 
77
77
  return res;
78
78
 
79
+ case "bigint":
80
+ return _encodeBigInt(definition, address);
81
+
79
82
  case "object":
80
83
  if (
81
84
  address instanceof definition.factory &&
@@ -156,6 +159,14 @@ export function isIPv6(address) {
156
159
  return _is(ipv6, address);
157
160
  }
158
161
 
162
+ function _definition(address) {
163
+ for (const defintion of [ipv4, ipv6]) {
164
+ if (_is(defintion, address)) {
165
+ return defintion;
166
+ }
167
+ }
168
+ }
169
+
159
170
  export function _is(definition, address) {
160
171
  switch (typeof address) {
161
172
  case "string":
@@ -215,6 +226,24 @@ export function _prefix(definition, address, length) {
215
226
  );
216
227
  }
217
228
 
229
+ export function rangeIP(address, prefix, lowerAdd = 0, upperReduce = 0) {
230
+ const definition = isIPv4(address) ? ipv4 : ipv6;
231
+
232
+ const from = _prefix(definition, address, prefix);
233
+ const to = _encode(definition, from); // /*from ||*/ definition.mask >> BigInt(prefix);
234
+
235
+ for (
236
+ let i = prefix / definition.segmentLength;
237
+ i < definition.segments;
238
+ i++
239
+ ) {
240
+ to[i] = 0xffff;
241
+ }
242
+
243
+ //console.log(from, to);
244
+ return [_encode(definition, from + BigInt(lowerAdd)), to];
245
+ }
246
+
218
247
  export function normalizeCIDR(address) {
219
248
  let [prefix, prefixLength] = address.split(/\//);
220
249
  let longPrefix;
@@ -244,7 +273,12 @@ export function normalizeCIDR(address) {
244
273
  longPrefix = _decode(definition, n);
245
274
  }
246
275
 
247
- return { longPrefix, prefix, prefixLength, cidr: `${prefix}/${prefixLength}` };
276
+ return {
277
+ longPrefix,
278
+ prefix,
279
+ prefixLength,
280
+ cidr: `${prefix}/${prefixLength}`
281
+ };
248
282
  }
249
283
 
250
284
  export function formatCIDR(address, subnet) {
@@ -285,7 +319,7 @@ export function isLocalhost(address) {
285
319
 
286
320
  export function isLinkLocal(address) {
287
321
  const eaddr = encodeIP(address);
288
- return eaddr[0] === 0xfe80;
322
+ return eaddr?.[0] === 0xfe80;
289
323
  }
290
324
 
291
325
  export function hasWellKnownSubnet(address) {
@@ -170,10 +170,10 @@ export class DNSService extends ExtraSourceService {
170
170
  async *preparePackages(dir) {
171
171
  const location = this.owner.owner;
172
172
  const name = location.name;
173
- const p1 = join(dir, "p1");
173
+ const p1 = join(dir, "p1") + "/";
174
174
  const packageData = {
175
175
  dir: p1,
176
- sources: [new FileContentProvider(p1 + "/")],
176
+ sources: [new FileContentProvider(p1)],
177
177
  outputs: this.outputs,
178
178
  properties: {
179
179
  name: `named-${name}`,
@@ -207,10 +207,10 @@ export class DNSService extends ExtraSourceService {
207
207
  yield packageData;
208
208
  }
209
209
 
210
- const p2 = join(dir, "p2");
210
+ const p2 = join(dir, "p2") + "/";
211
211
 
212
+ packageData.dir = p2;
212
213
  packageData.properties = {
213
- dir: p2,
214
214
  name: `named-zones-${name}`,
215
215
  description: `zone definitions for ${location.fullName}`,
216
216
  dependencies: ["mf-named"],
@@ -221,7 +221,7 @@ export class DNSService extends ExtraSourceService {
221
221
 
222
222
  packageData.sources = [
223
223
  new FileContentProvider(
224
- p2 + "/",
224
+ p2,
225
225
  {
226
226
  mode: 0o644,
227
227
  owner: "named",
package/src/subnet.mjs CHANGED
@@ -1,4 +1,11 @@
1
- import { normalizeCIDR, isLinkLocal, isIPv4, isIPv6, prefixIP } from "./ip.mjs";
1
+ import {
2
+ normalizeCIDR,
3
+ isLinkLocal,
4
+ isIPv4,
5
+ isIPv6,
6
+ rangeIP,
7
+ decodeIP
8
+ } from "./ip.mjs";
2
9
  import { Base } from "./base.mjs";
3
10
  import { addType } from "./types.mjs";
4
11
 
@@ -61,10 +68,7 @@ export class Subnet extends Base {
61
68
  }
62
69
 
63
70
  get addressRange() {
64
- return [
65
- prefixIP(this.prefix, this.prefixLength),
66
- this.prefix + ".255".repeat((32 - this.prefixLength) / 8)
67
- ];
71
+ return rangeIP(this.prefix, this.prefixLength, 0, 0).map(a => decodeIP(a));
68
72
  }
69
73
 
70
74
  get address() {
package/types/ip.d.mts CHANGED
@@ -13,6 +13,7 @@ export function _is(definition: any, address: any): boolean;
13
13
  export function asBigInt(address: any): bigint;
14
14
  export function prefixIP(address: any, length: any): string;
15
15
  export function _prefix(definition: any, address: any, length: any): bigint;
16
+ export function rangeIP(address: any, prefix: any, lowerAdd?: number, upperReduce?: number): any[];
16
17
  export function normalizeCIDR(address: any): {
17
18
  longPrefix?: undefined;
18
19
  prefix?: undefined;