pmcf 1.1.0 → 1.2.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 +1 -1
- package/src/model.mjs +25 -32
package/package.json
CHANGED
package/src/model.mjs
CHANGED
|
@@ -18,6 +18,10 @@ export class Base {
|
|
|
18
18
|
return "**/" + this.typeFileName;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
static refinedType(data) {
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
static baseName(name) {
|
|
22
26
|
if (!name) {
|
|
23
27
|
return undefined;
|
|
@@ -121,7 +125,7 @@ export class World {
|
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
async load() {
|
|
124
|
-
for (
|
|
128
|
+
for (let type of Object.values(World.types)) {
|
|
125
129
|
for await (const name of glob(type.fileNameGlob, {
|
|
126
130
|
cwd: this.directory
|
|
127
131
|
})) {
|
|
@@ -132,6 +136,8 @@ export class World {
|
|
|
132
136
|
);
|
|
133
137
|
|
|
134
138
|
data.name = baseName;
|
|
139
|
+
|
|
140
|
+
type = type.refinedType(data);
|
|
135
141
|
const object = new type(this, data);
|
|
136
142
|
this.#byName.set(data.name, object);
|
|
137
143
|
}
|
|
@@ -155,16 +161,12 @@ export class World {
|
|
|
155
161
|
}
|
|
156
162
|
|
|
157
163
|
async *hosts() {
|
|
158
|
-
|
|
159
|
-
for (const host of this.#hosts.values()) {
|
|
160
|
-
yield host;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
164
|
+
await this.load();
|
|
163
165
|
|
|
164
|
-
for
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
for (const object of this.#byName.values()) {
|
|
167
|
+
if (object instanceof Host) {
|
|
168
|
+
yield object;
|
|
169
|
+
}
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
172
|
|
|
@@ -175,27 +177,14 @@ export class World {
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
async location(name) {
|
|
180
|
+
await this.load();
|
|
178
181
|
return this.#byName.get(Location.baseName(name));
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
async host(name) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return undefined;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let host = this.#hosts.get(name);
|
|
189
|
-
if (host) {
|
|
190
|
-
return host;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const directory = join(this.directory, name);
|
|
194
|
-
const data = JSON.parse(
|
|
195
|
-
await readFile(join(directory, Host.typeFileName), "utf8")
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
data.directory = directory;
|
|
185
|
+
await this.load();
|
|
186
|
+
return this.#byName.get(Host.baseName(name));
|
|
187
|
+
/*
|
|
199
188
|
|
|
200
189
|
if (!data.name) {
|
|
201
190
|
data.name = name;
|
|
@@ -216,11 +205,7 @@ export class World {
|
|
|
216
205
|
if (data.extends) {
|
|
217
206
|
data.extends = await Promise.all(data.extends.map(e => this.host(e)));
|
|
218
207
|
}
|
|
219
|
-
|
|
220
|
-
host = new (data.name.indexOf("model/") >= 0 ? Model : Host)(this, data);
|
|
221
|
-
|
|
222
|
-
this.#hosts.set(name, host);
|
|
223
|
-
return host;
|
|
208
|
+
*/
|
|
224
209
|
}
|
|
225
210
|
|
|
226
211
|
async *subnets() {
|
|
@@ -256,6 +241,14 @@ export class Host extends Base {
|
|
|
256
241
|
return "host";
|
|
257
242
|
}
|
|
258
243
|
|
|
244
|
+
static refinedType(data) {
|
|
245
|
+
if (data.name?.indexOf("model/") >= 0) {
|
|
246
|
+
return Model;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
|
|
259
252
|
constructor(owner, data) {
|
|
260
253
|
super(owner, data);
|
|
261
254
|
|