pmcf 1.0.2 → 1.1.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 +1 -1
- package/src/model.mjs +34 -41
package/package.json
CHANGED
package/src/model.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
export class Base {
|
|
5
5
|
owner;
|
|
6
6
|
name;
|
|
7
|
+
description;
|
|
7
8
|
|
|
8
9
|
static get typeName() {
|
|
9
10
|
return "base";
|
|
@@ -31,8 +32,14 @@ export class Base {
|
|
|
31
32
|
|
|
32
33
|
constructor(owner, data) {
|
|
33
34
|
this.owner = owner;
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
if (data) {
|
|
37
|
+
if (data.name) {
|
|
38
|
+
this.name = data.name;
|
|
39
|
+
}
|
|
40
|
+
if (data.description) {
|
|
41
|
+
this.description = data.description;
|
|
42
|
+
}
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
|
|
@@ -54,6 +61,15 @@ export class Base {
|
|
|
54
61
|
return this.owner.network;
|
|
55
62
|
}
|
|
56
63
|
|
|
64
|
+
#directory;
|
|
65
|
+
set directory(directory) {
|
|
66
|
+
this.#directory = directory;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get directory() {
|
|
70
|
+
return this.#directory || this.name;
|
|
71
|
+
}
|
|
72
|
+
|
|
57
73
|
expand(object) {
|
|
58
74
|
if (typeof object === "string") {
|
|
59
75
|
return object.replaceAll(/\$\{([^\}]*)\}/g, (match, m1) => {
|
|
@@ -79,7 +95,9 @@ export class Base {
|
|
|
79
95
|
toJSON() {
|
|
80
96
|
return {
|
|
81
97
|
name: this.name,
|
|
82
|
-
|
|
98
|
+
directory: this.directory,
|
|
99
|
+
owner: this.owner.name,
|
|
100
|
+
description: this.description
|
|
83
101
|
};
|
|
84
102
|
}
|
|
85
103
|
}
|
|
@@ -92,7 +110,6 @@ export class World {
|
|
|
92
110
|
directory;
|
|
93
111
|
#byName = new Map();
|
|
94
112
|
|
|
95
|
-
/** @typedef {Map<string,Location>} */ #locations = new Map();
|
|
96
113
|
/** @typedef {Map<string,Host>} */ #hosts = new Map();
|
|
97
114
|
|
|
98
115
|
constructor(directory) {
|
|
@@ -114,7 +131,6 @@ export class World {
|
|
|
114
131
|
await readFile(join(this.directory, name), "utf8")
|
|
115
132
|
);
|
|
116
133
|
|
|
117
|
-
data.directory = baseName;
|
|
118
134
|
data.name = baseName;
|
|
119
135
|
const object = new type(this, data);
|
|
120
136
|
this.#byName.set(data.name, object);
|
|
@@ -124,20 +140,17 @@ export class World {
|
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
async named(name) {
|
|
143
|
+
await this.load();
|
|
127
144
|
return this.#byName.get(name);
|
|
128
145
|
}
|
|
129
146
|
|
|
130
147
|
async *locations() {
|
|
131
|
-
|
|
132
|
-
for (const location of this.#locations.values()) {
|
|
133
|
-
yield location;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
148
|
+
await this.load();
|
|
136
149
|
|
|
137
|
-
for
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
for (const object of this.#byName.values()) {
|
|
151
|
+
if (object instanceof Location) {
|
|
152
|
+
yield object;
|
|
153
|
+
}
|
|
141
154
|
}
|
|
142
155
|
}
|
|
143
156
|
|
|
@@ -162,29 +175,7 @@ export class World {
|
|
|
162
175
|
}
|
|
163
176
|
|
|
164
177
|
async location(name) {
|
|
165
|
-
|
|
166
|
-
if (name === undefined) {
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
let location = this.#locations.get(name);
|
|
171
|
-
if (location) {
|
|
172
|
-
return location;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const directory = join(this.directory, name);
|
|
176
|
-
try {
|
|
177
|
-
const data = JSON.parse(
|
|
178
|
-
await readFile(join(directory, Location.typeFileName), "utf8")
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
data.directory = directory;
|
|
182
|
-
data.name = name;
|
|
183
|
-
|
|
184
|
-
location = new Location(this, data);
|
|
185
|
-
} catch {} // TODO
|
|
186
|
-
this.#locations.set(name, location);
|
|
187
|
-
return location;
|
|
178
|
+
return this.#byName.get(Location.baseName(name));
|
|
188
179
|
}
|
|
189
180
|
|
|
190
181
|
async host(name) {
|
|
@@ -248,7 +239,6 @@ export class World {
|
|
|
248
239
|
}
|
|
249
240
|
|
|
250
241
|
export class Host extends Base {
|
|
251
|
-
directory;
|
|
252
242
|
networkInterfaces = {};
|
|
253
243
|
services = {};
|
|
254
244
|
postinstall = [];
|
|
@@ -413,7 +403,6 @@ export class Host extends Base {
|
|
|
413
403
|
...super.toJSON(),
|
|
414
404
|
...Object.fromEntries(
|
|
415
405
|
[
|
|
416
|
-
"directory",
|
|
417
406
|
"location",
|
|
418
407
|
"model",
|
|
419
408
|
"os",
|
|
@@ -438,7 +427,6 @@ export class Host extends Base {
|
|
|
438
427
|
export class Model extends Host {}
|
|
439
428
|
|
|
440
429
|
export class Location extends Base {
|
|
441
|
-
directory;
|
|
442
430
|
domain;
|
|
443
431
|
dns;
|
|
444
432
|
#administratorEmail;
|
|
@@ -608,6 +596,8 @@ export class Location extends Base {
|
|
|
608
596
|
export class Network extends Base {
|
|
609
597
|
#hosts = new Map();
|
|
610
598
|
kind;
|
|
599
|
+
scope;
|
|
600
|
+
metric;
|
|
611
601
|
ipv4;
|
|
612
602
|
ipv4_netmask;
|
|
613
603
|
subnet;
|
|
@@ -650,7 +640,10 @@ export class Network extends Base {
|
|
|
650
640
|
toJSON() {
|
|
651
641
|
return {
|
|
652
642
|
...super.toJSON(),
|
|
653
|
-
kind: this.kind
|
|
643
|
+
kind: this.kind,
|
|
644
|
+
ipv4: this.ipv4,
|
|
645
|
+
scope: this.scope,
|
|
646
|
+
metric: this.metric
|
|
654
647
|
};
|
|
655
648
|
}
|
|
656
649
|
}
|