pmcf 1.23.0 → 1.23.2

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.
@@ -2,14 +2,15 @@
2
2
 
3
3
  import { writeFile, mkdir, copyFile, glob } from "node:fs/promises";
4
4
  import { join } from "node:path";
5
+ import { Host } from "pmcf";
5
6
  import { writeLines, sectionLines } from "../src/utils.mjs";
6
- import { prepare } from "../src/cmd.mjs";
7
+ import { prepare, } from "../src/cmd.mjs";
7
8
 
8
9
  const { world, args, options } = prepare();
9
10
 
10
11
  const hostName = args[0];
11
12
 
12
- const host = await world.host(hostName);
13
+ const host = await world.load(hostName,{ type: Host });
13
14
 
14
15
  await generateNetworkDefs(host, options.output);
15
16
  await generateMachineInfo(host, options.output);
@@ -2,12 +2,13 @@
2
2
 
3
3
  import { mkdir, copyFile } from "node:fs/promises";
4
4
  import { join } from "node:path";
5
+ import { Location } from "pmcf";
5
6
  import { writeLines, sectionLines } from "../src/utils.mjs";
6
7
  import { prepare } from "../src/cmd.mjs";
7
8
 
8
9
  const { world, args, options } = prepare();
9
10
 
10
- const location = await world.location(args[0] || "SW");
11
+ const location = await world.load(args[0], { type: Location });
11
12
 
12
13
  await generateLocationDefs(location, options.output);
13
14
 
@@ -2,12 +2,13 @@
2
2
 
3
3
  import { join } from "node:path";
4
4
  import { createHmac } from "node:crypto";
5
+ import { Location } from "pmcf";
5
6
  import { writeLines, isIPv4Address } from "../src/utils.mjs";
6
7
  import { prepare } from "../src/cmd.mjs";
7
8
 
8
9
  const { world, args, options } = prepare();
9
10
 
10
- const location = await world.location(args[0] || "SW");
11
+ const location = await world.load(args[0], { type: Location });
11
12
  const updates = [
12
13
  Math.ceil(Date.now() / 1000),
13
14
  36000,
package/bin/pmcf-network CHANGED
@@ -4,7 +4,7 @@ import { prepare } from "../src/cmd.mjs";
4
4
 
5
5
  const { world, args } = prepare();
6
6
 
7
- const location = await world.location(args[0] || "SW");
7
+ const location = await world.load(args[0]);
8
8
 
9
9
  function q(str) {
10
10
  return str.match(/^\w+$/) ? str : `"${str}"`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.23.0",
3
+ "version": "1.23.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -58,15 +58,15 @@ export class Base {
58
58
  }
59
59
 
60
60
  get location() {
61
- return this.owner.location;
61
+ return this.owner?.location;
62
62
  }
63
63
 
64
64
  get host() {
65
- return this.owner.host;
65
+ return this.owner?.host;
66
66
  }
67
67
 
68
- async network(name) {
69
- return this.owner.network(name);
68
+ get network() {
69
+ return this.owner?.network;
70
70
  }
71
71
 
72
72
  #directory;
@@ -158,7 +158,7 @@ export function extractFrom(object, propertyNames) {
158
158
  const value = object[p];
159
159
 
160
160
  if (value !== undefined) {
161
- if (value instanceof Base && value.name) {
161
+ if (value instanceof Base && value.name !== undefined) {
162
162
  json[p] = { name: value.name };
163
163
  } else {
164
164
  json[p] = value;
package/src/model.mjs CHANGED
@@ -92,7 +92,7 @@ export class Owner extends Base {
92
92
  }
93
93
  }
94
94
 
95
- network(name) {
95
+ networkNamed(name) {
96
96
  return this.#networks.get(name);
97
97
  }
98
98
 
@@ -128,7 +128,7 @@ export class Owner extends Base {
128
128
  }
129
129
 
130
130
  for (const name of asArray(destinationNetworks)) {
131
- const other = this.network(name);
131
+ const other = this.networkNamed(name);
132
132
  if (other) {
133
133
  bridge.add(other);
134
134
  other.bridge = bridge;
@@ -147,7 +147,7 @@ export class Owner extends Base {
147
147
  this.info(bridgeToJSON(bridge));
148
148
  for (const network of bridge) {
149
149
  if (typeof network === "string") {
150
- const other = this.network(network);
150
+ const other = this.networkNamed(network);
151
151
 
152
152
  if (other) {
153
153
  bridge.delete(network);
@@ -326,14 +326,6 @@ export class World extends Owner {
326
326
  yield location.domain;
327
327
  }
328
328
  }
329
-
330
- async location(name) {
331
- return this.load(name, { type: Location });
332
- }
333
-
334
- async host(name) {
335
- return this.load(name, { type: Host });
336
- }
337
329
  }
338
330
 
339
331
  export class Location extends Owner {
@@ -443,12 +435,12 @@ export class Host extends Base {
443
435
 
444
436
  static async prepareData(world, data) {
445
437
  if (data.location) {
446
- data.location = await world.location(data.location);
438
+ data.location = await world.load(data.location, { type: Location });
447
439
  }
448
440
 
449
441
  if (data.extends) {
450
442
  data.extends = await Promise.all(
451
- asArray(data.extends).map(e => world.host(e))
443
+ asArray(data.extends).map(e => world.load(e, { type: Host }))
452
444
  );
453
445
  }
454
446
 
@@ -745,7 +737,7 @@ export class NetworkInterface extends Base {
745
737
  }
746
738
 
747
739
  if (data.network) {
748
- let network = owner.owner.network(data.network);
740
+ let network = owner.owner.networkNamed(data.network);
749
741
 
750
742
  if (network) {
751
743
  this.network = network;
@@ -790,7 +782,7 @@ export class NetworkInterface extends Base {
790
782
 
791
783
  set network(networkOrName) {
792
784
  if (!(networkOrName instanceof Network)) {
793
- let network = this.owner.owner.network(networkOrName);
785
+ let network = this.owner.owner.networkNamed(networkOrName);
794
786
 
795
787
  if (network) {
796
788
  this.#network = network;
package/types/base.d.mts CHANGED
@@ -14,7 +14,7 @@ export class Base {
14
14
  get world(): any;
15
15
  get location(): any;
16
16
  get host(): any;
17
- network(name: any): Promise<any>;
17
+ get network(): any;
18
18
  set directory(directory: any);
19
19
  get directory(): any;
20
20
  get fullName(): any;
package/types/model.d.mts CHANGED
@@ -9,7 +9,7 @@ export class Owner extends Base {
9
9
  addHost(host: any): void;
10
10
  service(filter: any): Promise<any>;
11
11
  services(filter: any): AsyncGenerator<any, void, unknown>;
12
- network(name: any): any;
12
+ networkNamed(name: any): any;
13
13
  networks(): AsyncGenerator<any, void, unknown>;
14
14
  addNetwork(network: any): void;
15
15
  addBridge(network: any, destinationNetworks: any): any;
@@ -40,8 +40,6 @@ export class World extends Owner {
40
40
  locations(): AsyncGenerator<Location, void, unknown>;
41
41
  hosts(): AsyncGenerator<Host, void, unknown>;
42
42
  domains(): AsyncGenerator<any, void, unknown>;
43
- location(name: any): Promise<any>;
44
- host(name: any): Promise<any>;
45
43
  #private;
46
44
  }
47
45
  export class Location extends Owner {