pmcf 1.3.0 → 1.4.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.
@@ -57,7 +57,7 @@ async function generateLocationDefs(location, dir) {
57
57
  await mkdir(locationDir, { recursive: true });
58
58
 
59
59
  copyFile(
60
- join(location.directory, "location.json"),
60
+ join(world.directory, location.directory, "location.json"),
61
61
  join(locationDir, "location.json")
62
62
  );
63
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -18,7 +18,7 @@ export class Base {
18
18
  return "**/" + this.typeFileName;
19
19
  }
20
20
 
21
- static refinedType(data) {
21
+ static async prepareData(world, data) {
22
22
  return this;
23
23
  }
24
24
 
@@ -121,23 +121,35 @@ export class World {
121
121
  return "";
122
122
  }
123
123
 
124
+ async _loadType(name, type) {
125
+ const baseName = type.baseName(name);
126
+
127
+ let object = this.#byName.get(baseName);
128
+
129
+ if (!object) {
130
+ const data = JSON.parse(
131
+ await readFile(
132
+ join(this.directory, baseName, type.typeFileName),
133
+ "utf8"
134
+ )
135
+ );
136
+
137
+ data.name = baseName;
138
+
139
+ type = await type.prepareData(this, data);
140
+ object = new type(this, data);
141
+ this.#byName.set(data.name, object);
142
+ }
143
+
144
+ return object;
145
+ }
146
+
124
147
  async load() {
125
148
  for (let type of Object.values(World.types)) {
126
149
  for await (const name of glob(type.fileNameGlob, {
127
150
  cwd: this.directory
128
151
  })) {
129
- const baseName = type.baseName(name);
130
- if (!this.#byName.get(baseName)) {
131
- const data = JSON.parse(
132
- await readFile(join(this.directory, name), "utf8")
133
- );
134
-
135
- data.name = baseName;
136
-
137
- type = type.refinedType(data);
138
- const object = new type(this, data);
139
- this.#byName.set(data.name, object);
140
- }
152
+ await this._loadType(name, type);
141
153
  }
142
154
  }
143
155
  }
@@ -174,34 +186,11 @@ export class World {
174
186
  }
175
187
 
176
188
  async location(name) {
177
- await this.load();
178
- return this.#byName.get(Location.baseName(name));
189
+ return this._loadType(name, Location);
179
190
  }
180
191
 
181
192
  async host(name) {
182
- await this.load();
183
- return this.#byName.get(Host.baseName(name));
184
- /*
185
- if (!data.name) {
186
- data.name = name;
187
- } else {
188
- name = data.name;
189
- }
190
-
191
- if (!data.location) {
192
- const parts = name.split(/\//);
193
-
194
- if (parts.length > 1 && parts[0] !== "services" && parts[0] !== "model") {
195
- data.location = parts[0];
196
- }
197
- }
198
-
199
- data.location = await this.location(data.location);
200
-
201
- if (data.extends) {
202
- data.extends = await Promise.all(data.extends.map(e => this.host(e)));
203
- }
204
- */
193
+ return this._loadType(name, Host);
205
194
  }
206
195
 
207
196
  async *subnets() {
@@ -237,7 +226,15 @@ export class Host extends Base {
237
226
  return "host";
238
227
  }
239
228
 
240
- static refinedType(data) {
229
+ static async prepareData(world, data) {
230
+ if (data.location) {
231
+ data.location = await world.location(data.location);
232
+ }
233
+
234
+ if (data.extends) {
235
+ data.extends = await Promise.all(data.extends.map(e => world.host(e)));
236
+ }
237
+
241
238
  if (data.name?.indexOf("model/") >= 0) {
242
239
  return Model;
243
240
  }
package/types/model.d.mts CHANGED
@@ -4,7 +4,7 @@ export class Base {
4
4
  static get typeName(): string;
5
5
  static get typeFileName(): string;
6
6
  static get fileNameGlob(): string;
7
- static refinedType(data: any): typeof Base;
7
+ static prepareData(world: any, data: any): Promise<typeof Base>;
8
8
  static baseName(name: any): any;
9
9
  constructor(owner: any, data: any);
10
10
  owner: any;
@@ -28,6 +28,7 @@ export class World {
28
28
  constructor(directory: any);
29
29
  directory: any;
30
30
  get name(): string;
31
+ _loadType(name: any, type: any): Promise<any>;
31
32
  load(): Promise<void>;
32
33
  named(name: any): Promise<any>;
33
34
  locations(): AsyncGenerator<Location, void, unknown>;
@@ -43,7 +44,7 @@ export class World {
43
44
  #private;
44
45
  }
45
46
  export class Host extends Base {
46
- static refinedType(data: any): typeof Host;
47
+ static prepareData(world: any, data: any): Promise<typeof Host>;
47
48
  networkInterfaces: {};
48
49
  services: {};
49
50
  postinstall: any[];