pmcf 1.1.0 → 1.2.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 +28 -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,11 @@ export class World {
|
|
|
132
136
|
);
|
|
133
137
|
|
|
134
138
|
data.name = baseName;
|
|
139
|
+
|
|
140
|
+
const t2 = type.refinedType(data);
|
|
141
|
+
if (t2) {
|
|
142
|
+
type = t2;
|
|
143
|
+
}
|
|
135
144
|
const object = new type(this, data);
|
|
136
145
|
this.#byName.set(data.name, object);
|
|
137
146
|
}
|
|
@@ -155,16 +164,12 @@ export class World {
|
|
|
155
164
|
}
|
|
156
165
|
|
|
157
166
|
async *hosts() {
|
|
158
|
-
|
|
159
|
-
for (const host of this.#hosts.values()) {
|
|
160
|
-
yield host;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
167
|
+
await this.load();
|
|
163
168
|
|
|
164
|
-
for
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
169
|
+
for (const object of this.#byName.values()) {
|
|
170
|
+
if (object instanceof Host) {
|
|
171
|
+
yield object;
|
|
172
|
+
}
|
|
168
173
|
}
|
|
169
174
|
}
|
|
170
175
|
|
|
@@ -175,27 +180,14 @@ export class World {
|
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
async location(name) {
|
|
183
|
+
await this.load();
|
|
178
184
|
return this.#byName.get(Location.baseName(name));
|
|
179
185
|
}
|
|
180
186
|
|
|
181
187
|
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;
|
|
188
|
+
await this.load();
|
|
189
|
+
return this.#byName.get(Host.baseName(name));
|
|
190
|
+
/*
|
|
199
191
|
|
|
200
192
|
if (!data.name) {
|
|
201
193
|
data.name = name;
|
|
@@ -216,11 +208,7 @@ export class World {
|
|
|
216
208
|
if (data.extends) {
|
|
217
209
|
data.extends = await Promise.all(data.extends.map(e => this.host(e)));
|
|
218
210
|
}
|
|
219
|
-
|
|
220
|
-
host = new (data.name.indexOf("model/") >= 0 ? Model : Host)(this, data);
|
|
221
|
-
|
|
222
|
-
this.#hosts.set(name, host);
|
|
223
|
-
return host;
|
|
211
|
+
*/
|
|
224
212
|
}
|
|
225
213
|
|
|
226
214
|
async *subnets() {
|
|
@@ -256,6 +244,14 @@ export class Host extends Base {
|
|
|
256
244
|
return "host";
|
|
257
245
|
}
|
|
258
246
|
|
|
247
|
+
static refinedType(data) {
|
|
248
|
+
if (data.name?.indexOf("model/") >= 0) {
|
|
249
|
+
return Model;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
|
|
259
255
|
constructor(owner, data) {
|
|
260
256
|
super(owner, data);
|
|
261
257
|
|