pmcf 2.31.1 → 2.32.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/bin/pmcf-info CHANGED
@@ -3,17 +3,23 @@ import { prepare } from "../src/cli.mjs";
3
3
  const { root, args, options } = await prepare({
4
4
  service: {
5
5
  type: "string"
6
+ },
7
+ address: {
8
+ type: "string"
6
9
  }
7
10
  });
8
11
 
9
- const objectName = args[0];
10
-
11
- const object = objectName ? root.named(objectName) : root;
12
-
13
- if (options.service) {
14
- for (const service of root.findServices({ type: options.service })) {
15
- console.log(service.toString());
12
+ for (const name of args) {
13
+ const object = await root.load(name);
14
+ if (options.service) {
15
+ for (const service of root.findServices({ type: options.service })) {
16
+ console.log(service.toString());
17
+ }
18
+ } else if (options.address) {
19
+ for (const na of object.networkAddresses()) {
20
+ console.log(na.toString());
21
+ }
22
+ } else {
23
+ console.log(object.toJSON());
16
24
  }
17
- } else {
18
- console.log(object.toJSON());
19
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "2.31.1",
3
+ "version": "2.32.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,7 +38,7 @@
38
38
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
39
39
  },
40
40
  "dependencies": {
41
- "ip-utilties": "^1.3.0",
41
+ "ip-utilties": "^1.3.1",
42
42
  "npm-pkgbuild": "^18.0.1",
43
43
  "pacc": "^3.4.0",
44
44
  "pkg-dir": "^8.0.0"
package/src/base.mjs CHANGED
@@ -75,12 +75,12 @@ export class Base {
75
75
  }
76
76
 
77
77
  ownerFor(property, data) {
78
- for (const type of property.type.owners) {
78
+ for (const type of property.type[0].owners) {
79
79
  if (this.typeName === type?.name) {
80
80
  return this;
81
81
  }
82
82
  }
83
- for (const type of property.type.owners) {
83
+ for (const type of property.type[0].owners) {
84
84
  const owner = this[type?.name];
85
85
  if (owner) {
86
86
  return owner;
@@ -133,7 +133,7 @@ export class Base {
133
133
  };
134
134
 
135
135
  const instantiateAndAssign = (property, value) => {
136
- if (primitives.has(property.type)) {
136
+ if (primitives.has(property.type[0])) {
137
137
  assign(property, value);
138
138
  return;
139
139
  }
@@ -151,13 +151,21 @@ export class Base {
151
151
  case "string":
152
152
  {
153
153
  value = this.expand(value);
154
- let object = this.typeNamed(property.type.name, value);
154
+
155
+ let object;
156
+
157
+ for (const type of property.type) {
158
+ object = this.typeNamed(type.name, value);
159
+ if (object) {
160
+ break;
161
+ }
162
+ }
155
163
 
156
164
  if (object) {
157
165
  assign(property, object);
158
166
  } else {
159
- if (property.type.constructWithIdentifierOnly) {
160
- object = new property.type.clazz(
167
+ if (property.type[0].constructWithIdentifierOnly) {
168
+ object = new property.type[0].clazz(
161
169
  this.ownerFor(property, value),
162
170
  value
163
171
  );
@@ -165,32 +173,36 @@ export class Base {
165
173
  } else {
166
174
  this.finalize(() => {
167
175
  value = this.expand(value);
168
- const object =
169
- this.typeNamed(property.type.name, value) ||
170
- this.owner.typeNamed(property.type.name, value) ||
171
- this.root.typeNamed(property.type.name, value); // TODO
172
-
173
- if (object) {
174
- assign(property, object);
175
- } else {
176
- this.error(
177
- "Not found",
178
- property.name,
179
- property.type.name,
180
- value
181
- );
176
+
177
+ for (const type of property.type) {
178
+ const object =
179
+ this.typeNamed(type.name, value) ||
180
+ this.owner.typeNamed(type.name, value) ||
181
+ this.root.typeNamed(type.name, value); // TODO
182
+
183
+ if (object) {
184
+ assign(property, object);
185
+ return;
186
+ }
182
187
  }
188
+
189
+ this.error(
190
+ "Not found",
191
+ property.name,
192
+ property.type.map(t => t.name),
193
+ value
194
+ );
183
195
  });
184
196
  }
185
197
  }
186
198
  }
187
199
  break;
188
200
  case "object":
189
- if (value instanceof property.type.clazz) {
201
+ if (value instanceof property.type[0].clazz) {
190
202
  assign(property, value);
191
203
  } else {
192
204
  const factory =
193
- property.type.factoryFor?.(this, value) || property.type.clazz;
205
+ property.type[0].factoryFor?.(this, value) || property.type[0].clazz;
194
206
 
195
207
  assign(
196
208
  property,
@@ -570,7 +582,7 @@ export function extractFrom(
570
582
  value = [...value];
571
583
  }
572
584
 
573
- value = extractFrom(value, def.type);
585
+ value = extractFrom(value, def.type[0]);
574
586
  if (value !== undefined) {
575
587
  json[name] = value;
576
588
  }
package/src/filter.mjs CHANGED
@@ -52,7 +52,7 @@ export function* objectFilter(type, objects, filter) {
52
52
  };
53
53
  for (let t = type; t; t = t.extends) {
54
54
  for (const property of Object.values(t.properties)) {
55
- switch (property.type) {
55
+ switch (property.type[0]) {
56
56
  case "boolean":
57
57
  if (
58
58
  filter[property.name] !== undefined &&
package/src/host.mjs CHANGED
@@ -45,7 +45,20 @@ const HostTypeDefinition = {
45
45
  type: "string",
46
46
  collection: false,
47
47
  writeable: true,
48
- values: ["phone", "tablet", "router", "desktop", "server"]
48
+ values: [
49
+ "phone",
50
+ "tablet",
51
+ "router",
52
+ "gateway",
53
+ "desktop",
54
+ "notebook",
55
+ "server",
56
+ "monitor",
57
+ "camera",
58
+ "inverter",
59
+ "battery",
60
+ "virtual"
61
+ ]
49
62
  },
50
63
  architecture: {
51
64
  type: "string",
@@ -449,7 +462,7 @@ export class Host extends Base {
449
462
 
450
463
  *subnets() {
451
464
  for (const networkInterface of this.networkInterfaces.values()) {
452
- yield* networkInterface.subnets;
465
+ yield* networkInterface.subnets();
453
466
  }
454
467
  }
455
468
 
package/src/module.mjs CHANGED
@@ -3,7 +3,6 @@ export * from "./cluster.mjs";
3
3
  export * from "./owner.mjs";
4
4
  export * from "./location.mjs";
5
5
  export * from "./root.mjs";
6
- export * from "./address.mjs";
7
6
  export * from "./subnet.mjs";
8
7
  export * from "./network.mjs";
9
8
  export * from "./network-address.mjs";
@@ -1,8 +1,8 @@
1
- import { familyIP, formatCIDR } from "ip-utilties";
1
+ import { familyIP, formatCIDR, decodeIP } from "ip-utilties";
2
2
  import { Subnet } from "./subnet.mjs";
3
3
 
4
4
  /**
5
- *
5
+ *
6
6
  */
7
7
  export class NetworkAddress {
8
8
  /** @type {Subnet} */ subnet;
@@ -26,4 +26,8 @@ export class NetworkAddress {
26
26
  get cidrAddress() {
27
27
  return formatCIDR(this.address, this.subnet.prefixLength);
28
28
  }
29
+
30
+ toString() {
31
+ return `${this.networkInterface.fullName} ${decodeIP(this.address)}`;
32
+ }
29
33
  }
@@ -20,9 +20,9 @@ export const NetworkInterfaceTypeDefinition = {
20
20
  const kind = value.kind;
21
21
  const t = NetworkInterfaceTypeDefinition.specializations[kind];
22
22
 
23
- if (!t) {
23
+ /*if (!t) {
24
24
  console.warn("FACTORY", owner.name, value, t?.name);
25
- }
25
+ }*/
26
26
  if (t) {
27
27
  delete value.type;
28
28
  delete value.kind;
package/src/network.mjs CHANGED
@@ -39,6 +39,12 @@ export class Network extends Owner {
39
39
  return this;
40
40
  }
41
41
 
42
+ get address() {
43
+ for(const subnet of this.subnets()) {
44
+ return subnet.address;
45
+ }
46
+ }
47
+
42
48
  networkNamed(name) {
43
49
  if (this.isNamed(name)) {
44
50
  return this;
package/src/owner.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { normalizeCIDR } from "ip-utilties";
1
+ import { normalizeCIDR, familyIP } from "ip-utilties";
2
2
  import { asIterator } from "./utils.mjs";
3
3
  import { Base } from "./base.mjs";
4
- import { Subnet } from "./subnet.mjs";
4
+ import { Subnet, SUBNET_GLOBAL_IPV4, SUBNET_GLOBAL_IPV6 } from "./subnet.mjs";
5
5
  import { addType, types } from "./types.mjs";
6
6
  const OwnerTypeDefinition = {
7
7
  name: "owner",
@@ -182,19 +182,25 @@ export class Owner extends Base {
182
182
  }
183
183
 
184
184
  addSubnet(address) {
185
- const { cidr } = normalizeCIDR(address);
185
+ const { cidr, prefixLength } = normalizeCIDR(address);
186
186
 
187
- if (cidr) {
187
+ if (cidr && prefixLength !== 0) {
188
188
  return this.subnetNamed(cidr) || new Subnet(this, cidr);
189
189
  }
190
190
 
191
- const subnet = this.subnetForAddress(address);
191
+ let subnet = this.subnetForAddress(address);
192
+
192
193
  if (!subnet) {
194
+ subnet = familyIP(address) === 'IPv4' ? SUBNET_GLOBAL_IPV4 : SUBNET_GLOBAL_IPV6;
195
+
196
+ /*
193
197
  this.error(
194
198
  `Address without subnet ${address}`,
195
199
  [...this.subnets()].map(s => s.address)
196
200
  );
201
+ */
197
202
  }
203
+
198
204
  return subnet;
199
205
  }
200
206
 
package/src/service.mjs CHANGED
@@ -89,11 +89,11 @@ export const EndpointTypeDefinition = {
89
89
 
90
90
  export const ServiceTypeDefinition = {
91
91
  name: "service",
92
- owners: ["host", "cluster"],
92
+ owners: ["host", "cluster", "network_interface"],
93
93
  priority: 0.4,
94
94
  extends: Base.typeDefinition,
95
95
  specializations: {},
96
- factoryFor(owner,value) {
96
+ factoryFor(owner, value) {
97
97
  const type = value.type ?? value.name;
98
98
  const t = ServiceTypeDefinition.specializations[type];
99
99
 
@@ -145,15 +145,15 @@ export class Service extends Base {
145
145
  }
146
146
 
147
147
  get network() {
148
- return this.server.network;
148
+ return this.host.network;
149
149
  }
150
150
 
151
- get server() {
151
+ get host() {
152
152
  return this.owner;
153
153
  }
154
154
 
155
155
  get domainName() {
156
- return this.server.domainName;
156
+ return this.host.domainName;
157
157
  }
158
158
 
159
159
  get ipAddressOrDomainName() {
@@ -165,7 +165,7 @@ export class Service extends Base {
165
165
  }
166
166
 
167
167
  get address() {
168
- return this._ipAddresses?.[0] ?? this.server.address;
168
+ return this._ipAddresses?.[0] ?? this.host.address;
169
169
  }
170
170
 
171
171
  set ipAddresses(value) {
@@ -173,7 +173,7 @@ export class Service extends Base {
173
173
  }
174
174
 
175
175
  get networks() {
176
- return this.server.networks;
176
+ return this.host.networks;
177
177
  }
178
178
 
179
179
  endpoints(filter) {
@@ -188,7 +188,7 @@ export class Service extends Base {
188
188
  }
189
189
  ];
190
190
 
191
- const result = [...this.server.networkAddresses()]
191
+ const result = [...this.host.networkAddresses()]
192
192
  .map(na =>
193
193
  data.map(
194
194
  d =>
@@ -53,7 +53,7 @@ export class DHCPService extends Service {
53
53
  endpoints(filter) {
54
54
  const endpoints = super.endpoints(filter);
55
55
 
56
- for (const na of this.server.networkAddresses(
56
+ for (const na of this.host.networkAddresses(
57
57
  na => na.networkInterface.kind === "localhost"
58
58
  )) {
59
59
  endpoints.push(new Endpoint(this, na, controlAgentEndpoint));
@@ -65,7 +65,7 @@ export class DHCPService extends Service {
65
65
 
66
66
  async *preparePackages(dir) {
67
67
  const network = this.network;
68
- const host = this.server;
68
+ const host = this.host;
69
69
  const name = host.name;
70
70
 
71
71
  console.log("kea", host.name, network.name);
@@ -1,7 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import { createHmac } from "node:crypto";
3
3
  import { FileContentProvider } from "npm-pkgbuild";
4
- import { isLinkLocal, reverseArpa } from "ip-utilties";
4
+ import { isLinkLocal, reverseArpa, decodeIP } from "ip-utilties";
5
5
  import { writeLines } from "../utils.mjs";
6
6
  import {
7
7
  DNSRecord,
@@ -16,9 +16,11 @@ import {
16
16
  ExtraSourceService,
17
17
  ExtraSourceServiceTypeDefinition
18
18
  } from "../extra-source-service.mjs";
19
- import { subnets } from "../subnet.mjs";
19
+ import { addresses } from "../network-support.mjs";
20
20
  import { addHook } from "../hooks.mjs";
21
21
 
22
+ const address_types = ["network", "host", "network_interface"];
23
+
22
24
  const DNSServiceTypeDefinition = {
23
25
  name: "dns",
24
26
  specializationOf: ServiceTypeDefinition,
@@ -26,9 +28,13 @@ const DNSServiceTypeDefinition = {
26
28
  extends: ExtraSourceServiceTypeDefinition,
27
29
  priority: 0.1,
28
30
  properties: {
29
- trusted: { type: "network", collection: true, writeable: true },
30
- protected: { type: "network", collection: true, writeable: true },
31
- open: { type: "network", collection: true, writeable: true },
31
+ trusted: {
32
+ type: address_types,
33
+ collection: true,
34
+ writeable: true
35
+ },
36
+ protected: { type: address_types, collection: true, writeable: true },
37
+ open: { type: address_types, collection: true, writeable: true },
32
38
  hasSVRRecords: {
33
39
  type: "boolean",
34
40
  collection: false,
@@ -53,7 +59,7 @@ const DNSServiceTypeDefinition = {
53
59
  writeable: true
54
60
  },
55
61
 
56
- exclude: { type: "network", collection: true, writeable: true },
62
+ exclude: { type: address_types, collection: true, writeable: true },
57
63
  notify: {
58
64
  type: "boolean",
59
65
  collection: false,
@@ -87,9 +93,18 @@ const statisticsEndpoint = {
87
93
  const DNS_SERVICE_FILTER = { type: DNSServiceTypeDefinition.name };
88
94
 
89
95
  function addressList(objects) {
90
- return Array.from(objects).map(object =>
91
- typeof object === "string" ? object : object.name
92
- );
96
+ return Array.from(objects).map(object => {
97
+ switch (typeof object) {
98
+ case "string":
99
+ return object;
100
+ case "object":
101
+ if (object.name) {
102
+ return object.name;
103
+ }
104
+
105
+ return decodeIP(object);
106
+ }
107
+ });
93
108
  }
94
109
 
95
110
  function addressesStatement(prefix, objects, generateEmpty = false) {
@@ -141,7 +156,7 @@ export class DNSService extends ExtraSourceService {
141
156
  endpoints(filter) {
142
157
  const endpoints = super.endpoints(filter);
143
158
 
144
- for (const na of this.server.networkAddresses(
159
+ for (const na of this.owner.networkAddresses(
145
160
  na => na.networkInterface.kind === "localhost"
146
161
  )) {
147
162
  endpoints.push(new Endpoint(this, na, rdncEndpoint));
@@ -243,9 +258,9 @@ export class DNSService extends ExtraSourceService {
243
258
  }
244
259
 
245
260
  const acls = [
246
- addressesStatement("acl trusted", subnets(this.trusted)),
247
- addressesStatement("acl protected", subnets(this.protected)),
248
- addressesStatement("acl open", subnets(this.open), true)
261
+ addressesStatement("acl trusted", addresses(this.trusted)),
262
+ addressesStatement("acl protected", addresses(this.protected)),
263
+ addressesStatement("acl open", addresses(this.open), true)
249
264
  ].flat();
250
265
 
251
266
  if (acls.length) {
@@ -67,7 +67,7 @@ export class NTPService extends ExtraSourceService {
67
67
 
68
68
  async *preparePackages(dir) {
69
69
  const network = this.network;
70
- const host = this.server;
70
+ const host = this.host;
71
71
  const name = host.name;
72
72
 
73
73
  console.log("chrony", host.name, network.name);
package/src/subnet.mjs CHANGED
@@ -56,9 +56,8 @@ export class Subnet extends Base {
56
56
  try {
57
57
  return matchPrefixIP(this.address, this.prefixLength, address);
58
58
  } catch (e) {
59
- console.error(e, address, this.address, this.prefixLength);
59
+ console.error(e, this.toString(), address);
60
60
  }
61
-
62
61
  return false;
63
62
  }
64
63
 
@@ -92,6 +91,7 @@ export class Subnet extends Base {
92
91
 
93
92
  const _owner = { addObject() {} };
94
93
  export const SUBNET_GLOBAL_IPV4 = new Subnet(_owner, "0.0.0.0/0");
94
+ export const SUBNET_GLOBAL_IPV6 = new Subnet(_owner, "::0/0");
95
95
  export const SUBNET_LOCALHOST_IPV4 = new Subnet(_owner, "127.0.0.1/8");
96
96
  export const SUBNET_LOCALHOST_IPV6 = new Subnet(_owner, "::1/128");
97
97
 
package/src/types.mjs CHANGED
@@ -1,9 +1,11 @@
1
+ import { asArray } from "./utils.mjs";
2
+
1
3
  export const types = {};
2
4
 
3
5
  export function addType(clazz) {
4
6
  const type = clazz.typeDefinition;
5
7
 
6
- if(type.specializationOf) {
8
+ if (type.specializationOf) {
7
9
  type.specializationOf.specializations[type.name] = type;
8
10
  }
9
11
 
@@ -26,6 +28,32 @@ export function resolveTypeLinks() {
26
28
  type.identifier = property;
27
29
  }
28
30
 
31
+ const ts = [];
32
+
33
+ for (const type of asArray(property.type)) {
34
+ if (typeof type === "string") {
35
+ if (primitives.has(type)) {
36
+ ts.push(type);
37
+ } else {
38
+ const t = types[type];
39
+ if (t) {
40
+ ts.push(t);
41
+ } else {
42
+ console.error(
43
+ "Unknown type",
44
+ property.type,
45
+ type.name,
46
+ property.name
47
+ );
48
+ }
49
+ }
50
+ } else {
51
+ ts.push(type);
52
+ }
53
+ }
54
+ property.type = ts;
55
+
56
+ /*
29
57
  if (typeof property.type === "string") {
30
58
  if (!primitives.has(property.type)) {
31
59
  const type = types[property.type];
@@ -41,6 +69,9 @@ export function resolveTypeLinks() {
41
69
  }
42
70
  }
43
71
  }
72
+
73
+ property.type = asArray(property.type);
74
+ */
44
75
  }
45
76
  }
46
77
 
@@ -3,7 +3,6 @@ export * from "./cluster.mjs";
3
3
  export * from "./owner.mjs";
4
4
  export * from "./location.mjs";
5
5
  export * from "./root.mjs";
6
- export * from "./address.mjs";
7
6
  export * from "./subnet.mjs";
8
7
  export * from "./network.mjs";
9
8
  export * from "./network-address.mjs";
@@ -9,5 +9,6 @@ export class NetworkAddress {
9
9
  get domainNames(): any;
10
10
  get family(): any;
11
11
  get cidrAddress(): any;
12
+ toString(): string;
12
13
  }
13
14
  import { Subnet } from "./subnet.mjs";
@@ -201,6 +201,7 @@ export class Network extends Owner {
201
201
  gateway: any;
202
202
  _bridge: any;
203
203
  get network(): this;
204
+ get address(): any;
204
205
  set bridge(network: any);
205
206
  get bridge(): any;
206
207
  }
@@ -305,7 +305,6 @@ export class Service extends Base {
305
305
  _extends: any[];
306
306
  set extends(value: any[]);
307
307
  get extends(): any[];
308
- get server(): any;
309
308
  get domainName(): any;
310
309
  get ipAddressOrDomainName(): any;
311
310
  get addresses(): any;
@@ -265,17 +265,17 @@ export class DNSService extends ExtraSourceService {
265
265
  priority: number;
266
266
  properties: {
267
267
  trusted: {
268
- type: string;
268
+ type: string[];
269
269
  collection: boolean;
270
270
  writeable: boolean;
271
271
  };
272
272
  protected: {
273
- type: string;
273
+ type: string[];
274
274
  collection: boolean;
275
275
  writeable: boolean;
276
276
  };
277
277
  open: {
278
- type: string;
278
+ type: string[];
279
279
  collection: boolean;
280
280
  writeable: boolean;
281
281
  };
@@ -303,7 +303,7 @@ export class DNSService extends ExtraSourceService {
303
303
  writeable: boolean;
304
304
  };
305
305
  exclude: {
306
- type: string;
306
+ type: string[];
307
307
  collection: boolean;
308
308
  writeable: boolean;
309
309
  };
@@ -38,6 +38,7 @@ export class Subnet extends Base {
38
38
  _traverse(...args: any[]): boolean;
39
39
  }
40
40
  export const SUBNET_GLOBAL_IPV4: Subnet;
41
+ export const SUBNET_GLOBAL_IPV6: Subnet;
41
42
  export const SUBNET_LOCALHOST_IPV4: Subnet;
42
43
  export const SUBNET_LOCALHOST_IPV6: Subnet;
43
44
  import { Base } from "./base.mjs";
package/src/address.mjs DELETED
@@ -1,32 +0,0 @@
1
- import { Base } from "./base.mjs";
2
- import { addType } from "./types.mjs";
3
-
4
- const AddressTypeDefinition = {
5
- name: "address",
6
- owners: ["location", "owner", "network", "root"],
7
- priority: 0.6,
8
- constructWithIdentifierOnly: true,
9
- properties: {
10
- address: {
11
- type: "string",
12
- collection: false,
13
- writeable: false,
14
- identifier: true
15
- },
16
- }
17
- };
18
-
19
-
20
- export class Address extends Base {
21
- static {
22
- addType(this);
23
- }
24
-
25
- static get typeDefinition() {
26
- return AddressTypeDefinition;
27
- }
28
-
29
- constructor(owner, address) {
30
- super(owner, address);
31
- }
32
- }
@@ -1,17 +0,0 @@
1
- export class Address extends Base {
2
- static get typeDefinition(): {
3
- name: string;
4
- owners: string[];
5
- priority: number;
6
- constructWithIdentifierOnly: boolean;
7
- properties: {
8
- address: {
9
- type: string;
10
- collection: boolean;
11
- writeable: boolean;
12
- identifier: boolean;
13
- };
14
- };
15
- };
16
- }
17
- import { Base } from "./base.mjs";