pmcf 1.2.1 → 1.3.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/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![npm](https://img.shields.io/npm/v/pmcf.svg)](https://www.npmjs.com/package/pmcf)
2
2
  [![License](https://img.shields.io/badge/License-0BSD-blue.svg)](https://spdx.org/licenses/0BSD.html)
3
+ [![Typed with TypeScript](https://flat.badgen.net/badge/icon/Typed?icon=typescript\&label\&labelColor=blue\&color=555555)](https://typescriptlang.org)
3
4
  [![bundlejs](https://deno.bundlejs.com/?q=pmcf\&badge=detailed)](https://bundlejs.com/?q=pmcf)
4
5
  [![downloads](http://img.shields.io/npm/dm/pmcf.svg?style=flat-square)](https://npmjs.org/package/pmcf)
5
6
  [![GitHub Issues](https://img.shields.io/github/issues/arlac77/pmcf.svg?style=flat-square)](https://github.com/arlac77/pmcf/issues)
@@ -4,12 +4,11 @@ import { World } from "../src/model.mjs";
4
4
 
5
5
  const world = new World(argv[2] || cwd());
6
6
 
7
- const locationName = argv[3];
7
+ const objectName = argv[3];
8
8
 
9
- if (locationName) {
10
- const location = await world.location(locationName);
11
- await location.load();
12
- console.log(location.toJSON());
9
+ if (objectName) {
10
+ const object = await world.named(objectName);
11
+ console.log(object.toJSON());
13
12
  } else {
14
13
  for await (const location of world.locations()) {
15
14
  console.log(location.name);
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
+ "exports": {
8
+ ".": {
9
+ "default": "./src/model.mjs"
10
+ }
11
+ },
7
12
  "description": "Poor mans configuration management",
8
13
  "keywords": [
9
- "config management",
10
- "config"
14
+ "config",
15
+ "config management"
11
16
  ],
12
17
  "contributors": [
13
18
  {
@@ -17,26 +22,30 @@
17
22
  ],
18
23
  "license": "0BSD",
19
24
  "bin": {
20
- "gen-host-defs": "./bin/gen-host-defs",
21
- "gen-location-defs": "./bin/gen-location-defs",
22
- "gen-named-defs": "./bin/gen-named-defs",
23
- "host-info": "./bin/host-info",
24
- "location-info": "./bin/location-info",
25
- "network": "./bin/network"
25
+ "pmcf-host-defs": "./bin/pmcf-host-defs",
26
+ "pmcf-info": "./bin/pmcf-info",
27
+ "pmcf-location-defs": "./bin/pmcf-location-defs",
28
+ "pmcf-named-defs": "./bin/pmcf-named-defs",
29
+ "pmcf-network": "./bin/pmcf-network"
26
30
  },
27
31
  "scripts": {
32
+ "prepare": "node --run prepare:typescript",
33
+ "prepare:typescript": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext --rootDir src ./src**/*.mjs",
28
34
  "test": "node --run test:ava",
29
35
  "test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
30
36
  "cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
31
37
  "docs": "documentation readme --section=API ./src**/*.mjs",
32
- "lint": "node --run lint:docs",
33
- "lint:docs": "documentation lint ./src**/*.mjs"
38
+ "lint": "node --run lint:docs && node --run lint:typescript",
39
+ "lint:docs": "documentation lint ./src**/*.mjs",
40
+ "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
34
41
  },
35
42
  "devDependencies": {
43
+ "@types/node": "^22.10.7",
36
44
  "ava": "^6.2.0",
37
45
  "c8": "^10.1.3",
38
46
  "documentation": "^14.0.3",
39
- "semantic-release": "^24.2.1"
47
+ "semantic-release": "^24.2.1",
48
+ "typescript": "^5.7.3"
40
49
  },
41
50
  "engines": {
42
51
  "node": ">=22.13.0"
@@ -52,7 +61,8 @@
52
61
  "template": {
53
62
  "inheritFrom": [
54
63
  "arlac77/template-arlac77-github",
55
- "arlac77/template-node-app"
64
+ "arlac77/template-node-app",
65
+ "arlac77/template-typescript"
56
66
  ]
57
67
  }
58
68
  }
package/src/model.mjs CHANGED
@@ -96,13 +96,12 @@ export class Base {
96
96
  return this.typeName + ":" + this.owner.name + "/" + this.name;
97
97
  }
98
98
 
99
+ get propertyNames() {
100
+ return ["name", "description", "directory", "owner"];
101
+ }
102
+
99
103
  toJSON() {
100
- return {
101
- name: this.name,
102
- directory: this.directory,
103
- owner: this.owner.name,
104
- description: this.description
105
- };
104
+ return extractFrom(this, this.propertyNames);
106
105
  }
107
106
  }
108
107
 
@@ -114,8 +113,6 @@ export class World {
114
113
  directory;
115
114
  #byName = new Map();
116
115
 
117
- /** @typedef {Map<string,Host>} */ #hosts = new Map();
118
-
119
116
  constructor(directory) {
120
117
  this.directory = directory;
121
118
  }
@@ -185,7 +182,6 @@ export class World {
185
182
  await this.load();
186
183
  return this.#byName.get(Host.baseName(name));
187
184
  /*
188
-
189
185
  if (!data.name) {
190
186
  data.name = name;
191
187
  } else {
@@ -391,24 +387,24 @@ export class Host extends Base {
391
387
  return readFile(join(this.directory, `ssh_host_${type}_key.pub`), "utf8");
392
388
  }
393
389
 
390
+ get propertyNames() {
391
+ return [
392
+ ...super.propertyNames,
393
+ "os",
394
+ "distribution",
395
+ "deployment",
396
+ "master",
397
+ "location",
398
+ "model",
399
+ "replaces",
400
+ "depends",
401
+ "networkInterfaces"
402
+ ];
403
+ }
404
+
394
405
  toJSON() {
395
406
  return {
396
407
  ...super.toJSON(),
397
- ...Object.fromEntries(
398
- [
399
- "location",
400
- "model",
401
- "os",
402
- "distribution",
403
- "deployment",
404
- "replaces",
405
- "depends",
406
- "master",
407
- "networkInterfaces"
408
- ]
409
- .filter(p => this[p])
410
- .map(p => [p, this[p]])
411
- ),
412
408
  extends: this.extends.map(host => host.name),
413
409
  services: Object.fromEntries(
414
410
  Object.values(this.services).map(s => [s.name, s.toJSON()])
@@ -577,10 +573,13 @@ export class Location extends Base {
577
573
  return this.#administratorEmail || "admin@" + this.domain;
578
574
  }
579
575
 
576
+ get propertyNames() {
577
+ return [...super.propertyNames, "domain"];
578
+ }
579
+
580
580
  toJSON() {
581
581
  return {
582
582
  ...super.toJSON(),
583
- domain: this.domain,
584
583
  hosts: [...this.#hosts.keys()].sort()
585
584
  };
586
585
  }
@@ -630,14 +629,8 @@ export class Network extends Base {
630
629
  this.#hosts.set(host.name, host);
631
630
  }
632
631
 
633
- toJSON() {
634
- return {
635
- ...super.toJSON(),
636
- kind: this.kind,
637
- ipv4: this.ipv4,
638
- scope: this.scope,
639
- metric: this.metric
640
- };
632
+ get propertyNames() {
633
+ return [...super.propertyNames, "kind", "ipv4", "scope", "metric"];
641
634
  }
642
635
  }
643
636
 
@@ -737,16 +730,16 @@ export class Service extends Base {
737
730
  return this.#type || this.name;
738
731
  }
739
732
 
740
- toJSON() {
741
- return {
742
- ...super.toJSON(),
743
- ipAddress: this.ipAddress,
744
- alias: this.alias,
745
- type: this.type,
746
- master: this.master,
747
- priority: this.priority,
748
- weight: this.weight
749
- };
733
+ get propertyNames() {
734
+ return [
735
+ ...super.propertyNames,
736
+ "ipAddress",
737
+ "alias",
738
+ "type",
739
+ "master",
740
+ "priority",
741
+ "weight"
742
+ ];
750
743
  }
751
744
  }
752
745
 
@@ -779,3 +772,14 @@ export function sectionLines(sectionName, values) {
779
772
 
780
773
  return lines;
781
774
  }
775
+
776
+ function extractFrom(object, propertyNames) {
777
+ const json = {};
778
+ for (const p of propertyNames) {
779
+ const value = object[p];
780
+ if (value !== undefined) {
781
+ json[p] = value;
782
+ }
783
+ }
784
+ return json;
785
+ }
@@ -0,0 +1,126 @@
1
+ export function writeLines(dir: any, name: any, lines: any): Promise<void>;
2
+ export function sectionLines(sectionName: any, values: any): string[];
3
+ export class Base {
4
+ static get typeName(): string;
5
+ static get typeFileName(): string;
6
+ static get fileNameGlob(): string;
7
+ static refinedType(data: any): typeof Base;
8
+ static baseName(name: any): any;
9
+ constructor(owner: any, data: any);
10
+ owner: any;
11
+ name: any;
12
+ description: any;
13
+ get typeName(): any;
14
+ get host(): any;
15
+ get network(): any;
16
+ set directory(directory: any);
17
+ get directory(): any;
18
+ expand(object: any): any;
19
+ toString(): string;
20
+ get propertyNames(): string[];
21
+ toJSON(): {};
22
+ #private;
23
+ }
24
+ export class World {
25
+ static get types(): {
26
+ [k: string]: typeof Host | typeof Network | typeof Location | typeof Subnet | typeof Service;
27
+ };
28
+ constructor(directory: any);
29
+ directory: any;
30
+ get name(): string;
31
+ load(): Promise<void>;
32
+ named(name: any): Promise<any>;
33
+ locations(): AsyncGenerator<Location, void, unknown>;
34
+ hosts(): AsyncGenerator<Host, void, unknown>;
35
+ domains(): AsyncGenerator<any, void, unknown>;
36
+ location(name: any): Promise<any>;
37
+ host(name: any): Promise<any>;
38
+ subnets(): AsyncGenerator<any, void, unknown>;
39
+ networkAddresses(): AsyncGenerator<{
40
+ address: any;
41
+ networkInterface: any;
42
+ }, void, unknown>;
43
+ #private;
44
+ }
45
+ export class Host extends Base {
46
+ static refinedType(data: any): typeof Host;
47
+ networkInterfaces: {};
48
+ services: {};
49
+ postinstall: any[];
50
+ location: any;
51
+ get deployment(): any;
52
+ get extends(): any[];
53
+ get provides(): Set<any>;
54
+ get replaces(): Set<any>;
55
+ get _depends(): Set<any>;
56
+ get depends(): any;
57
+ get master(): boolean;
58
+ get os(): any;
59
+ get distribution(): any;
60
+ get model(): Model;
61
+ get domain(): any;
62
+ get modelName(): any;
63
+ get hostName(): any;
64
+ get domainName(): string;
65
+ networkAddresses(): Generator<{
66
+ address: any;
67
+ networkInterface: any;
68
+ }, void, unknown>;
69
+ get ipAddress(): any;
70
+ publicKey(type?: string): Promise<string>;
71
+ toJSON(): {
72
+ extends: any[];
73
+ services: any;
74
+ };
75
+ #private;
76
+ }
77
+ export class Model extends Host {
78
+ }
79
+ export class Location extends Base {
80
+ domain: any;
81
+ dns: any;
82
+ load(): Promise<void>;
83
+ hosts(): AsyncGenerator<any, void, unknown>;
84
+ service(filter: any): Promise<any>;
85
+ services(filter: any): AsyncGenerator<any, void, unknown>;
86
+ network(name: any): any;
87
+ networkAddresses(): AsyncGenerator<any, void, unknown>;
88
+ networks(): AsyncGenerator<any, void, unknown>;
89
+ subnets(): AsyncGenerator<any, void, unknown>;
90
+ addNetwork(data: any): any;
91
+ addHost(host: any): void;
92
+ get dnsAllowedUpdates(): any;
93
+ get dnsRecordTTL(): any;
94
+ get administratorEmail(): any;
95
+ toJSON(): {
96
+ hosts: any[];
97
+ };
98
+ #private;
99
+ }
100
+ export class Network extends Base {
101
+ kind: any;
102
+ scope: any;
103
+ metric: any;
104
+ ipv4: any;
105
+ ipv4_netmask: any;
106
+ subnet: any;
107
+ get subnetAddress(): any;
108
+ hosts(): AsyncGenerator<any, void, unknown>;
109
+ addHost(host: any): void;
110
+ #private;
111
+ }
112
+ export class Subnet extends Base {
113
+ networks: Set<any>;
114
+ get address(): any;
115
+ }
116
+ export class Service extends Base {
117
+ alias: any;
118
+ get prefix(): any;
119
+ get ipAddress(): any;
120
+ get port(): any;
121
+ get priority(): any;
122
+ get weight(): any;
123
+ get master(): any;
124
+ get type(): any;
125
+ #private;
126
+ }
package/bin/host-info DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- import { cwd, argv } from "node:process";
3
- import { World } from "../src/model.mjs";
4
-
5
- const world = new World(argv[2] || cwd());
6
-
7
- const hostName = argv[3];
8
-
9
- if (hostName) {
10
- const host = await world.host(hostName);
11
- console.log(host.toJSON());
12
- } else {
13
- for await (const host of world.hosts()) {
14
- console.log(host.name);
15
- }
16
- }
File without changes
File without changes
File without changes
File without changes