@packtrack/layout 1.1.0 → 1.3.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.
Files changed (73) hide show
  1. package/.built/district.d.ts +2 -0
  2. package/.built/district.js +4 -3
  3. package/.built/index.d.ts +20 -17
  4. package/.built/index.js +20 -17
  5. package/.built/layout.d.ts +6 -0
  6. package/.built/layout.js +40 -11
  7. package/.built/monitor.d.ts +9 -0
  8. package/.built/monitor.js +15 -0
  9. package/.built/position.d.ts +3 -1
  10. package/.built/position.js +16 -0
  11. package/.built/positioner/point.d.ts +1 -1
  12. package/.built/source/device/channel.d.ts +2 -2
  13. package/.built/source/device/channel.js +4 -8
  14. package/.built/source/device/index.d.ts +10 -0
  15. package/.built/source/device/index.js +8 -0
  16. package/.built/source/district.d.ts +3 -7
  17. package/.built/source/district.js +4 -70
  18. package/.built/source/layout.d.ts +9 -6
  19. package/.built/source/layout.js +85 -86
  20. package/.built/source/monitor.d.ts +8 -0
  21. package/.built/source/monitor.js +8 -0
  22. package/.built/source/position.d.ts +3 -1
  23. package/.built/source/position.js +17 -5
  24. package/.built/source/positioner/index.d.ts +2 -0
  25. package/.built/source/positioner/index.js +2 -0
  26. package/.built/source/positioner/point.d.ts +12 -0
  27. package/.built/source/positioner/point.js +17 -0
  28. package/.built/source/positioner/responder-type.d.ts +4 -0
  29. package/.built/source/positioner/responder-type.js +6 -0
  30. package/.built/source/power-district/activator.d.ts +7 -0
  31. package/.built/source/power-district/activator.js +8 -0
  32. package/.built/source/power-district/index.d.ts +13 -0
  33. package/.built/source/power-district/index.js +14 -0
  34. package/.built/source/power-district/monitor.d.ts +7 -0
  35. package/.built/source/power-district/monitor.js +8 -0
  36. package/.built/source/power-district/reverser.d.ts +7 -0
  37. package/.built/source/power-district/reverser.js +8 -0
  38. package/.built/source/route.d.ts +0 -1
  39. package/.built/source/route.js +1 -8
  40. package/.built/source/router.d.ts +0 -4
  41. package/.built/source/router.js +1 -28
  42. package/.built/source/section.d.ts +1 -10
  43. package/.built/source/section.js +8 -57
  44. package/.built/source/span.d.ts +12 -0
  45. package/.built/source/span.js +77 -0
  46. package/.built/source/throttle.d.ts +8 -0
  47. package/.built/source/throttle.js +8 -0
  48. package/.built/source/tile.js +2 -7
  49. package/.built/source/track.d.ts +1 -2
  50. package/.built/source/track.js +3 -10
  51. package/.built/span.d.ts +12 -0
  52. package/.built/span.js +77 -0
  53. package/.built/throttle.d.ts +9 -0
  54. package/.built/throttle.js +15 -0
  55. package/index.ts +23 -0
  56. package/package.json +4 -4
  57. package/source/device/channel.ts +4 -4
  58. package/source/device/index.ts +2 -19
  59. package/source/district.ts +7 -83
  60. package/source/layout.ts +52 -74
  61. package/source/monitor.ts +10 -0
  62. package/source/position.ts +52 -32
  63. package/source/positioner/point.ts +2 -11
  64. package/source/positioner/responder-type.ts +1 -5
  65. package/source/power-district/index.ts +0 -5
  66. package/source/route.ts +2 -6
  67. package/source/router.ts +2 -31
  68. package/source/section.ts +10 -65
  69. package/source/span.ts +88 -0
  70. package/source/throttle.ts +10 -0
  71. package/source/track.ts +3 -7
  72. package/tsconfig.json +7 -8
  73. package/source/index.ts +0 -20
@@ -1,4 +1,5 @@
1
1
  import { Layout } from "./layout";
2
+ import { Monitor } from "./monitor";
2
3
  import { PowerDistrict } from "./power-district";
3
4
  import { Router } from "./router";
4
5
  import { Section } from "./section";
@@ -9,6 +10,7 @@ export declare class District {
9
10
  powerDistricts: PowerDistrict[];
10
11
  sections: Section[];
11
12
  routers: Router[];
13
+ monitors: Monitor[];
12
14
  constructor(name: string, parent: District | Layout);
13
15
  get domainName(): string;
14
16
  dump(): void;
@@ -6,6 +6,7 @@ export class District {
6
6
  powerDistricts = [];
7
7
  sections = [];
8
8
  routers = [];
9
+ monitors = [];
9
10
  constructor(name, parent) {
10
11
  this.name = name;
11
12
  this.parent = parent;
@@ -48,10 +49,10 @@ export class District {
48
49
  return `
49
50
  subgraph ${this.toDotReference()} {
50
51
  label = ${JSON.stringify(this.name)}
51
-
52
+
52
53
  ${this.sections.map(section => section.toDotDefinition()).join('')}
53
54
  ${this.routers.map(router => router.toDotDefinition()).join('')}
54
-
55
+
55
56
  ${this.children.map(child => child.toDotDefinition()).join('')}
56
57
  }
57
58
  `;
@@ -60,7 +61,7 @@ export class District {
60
61
  return `
61
62
  ${this.sections.map(section => section.toDotConnection()).join('')}
62
63
  ${this.routers.map(router => router.toDotConnection()).join('')}
63
-
64
+
64
65
  ${this.children.map(child => child.toDotConnection()).join('')}
65
66
  `;
66
67
  }
package/.built/index.d.ts CHANGED
@@ -1,17 +1,20 @@
1
- export * from './district';
2
- export * from './layout';
3
- export * from './position';
4
- export * from './route';
5
- export * from './router';
6
- export * from './section';
7
- export * from './tile';
8
- export * from './track';
9
- export * from './power-district/index';
10
- export * from './power-district/activator';
11
- export * from './power-district/monitor';
12
- export * from './power-district/reverser';
13
- export * from './positioner/index';
14
- export * from './positioner/point';
15
- export * from './positioner/responder-type';
16
- export * from './device/index';
17
- export * from './device/channel';
1
+ export * from './source/district';
2
+ export * from './source/layout';
3
+ export * from './source/position';
4
+ export * from './source/route';
5
+ export * from './source/router';
6
+ export * from './source/section';
7
+ export * from './source/span';
8
+ export * from './source/tile';
9
+ export * from './source/track';
10
+ export * from './source/monitor';
11
+ export * from './source/throttle';
12
+ export * from './source/power-district/index';
13
+ export * from './source/power-district/activator';
14
+ export * from './source/power-district/monitor';
15
+ export * from './source/power-district/reverser';
16
+ export * from './source/positioner/index';
17
+ export * from './source/positioner/point';
18
+ export * from './source/positioner/responder-type';
19
+ export * from './source/device/index';
20
+ export * from './source/device/channel';
package/.built/index.js CHANGED
@@ -1,17 +1,20 @@
1
- export * from './district';
2
- export * from './layout';
3
- export * from './position';
4
- export * from './route';
5
- export * from './router';
6
- export * from './section';
7
- export * from './tile';
8
- export * from './track';
9
- export * from './power-district/index';
10
- export * from './power-district/activator';
11
- export * from './power-district/monitor';
12
- export * from './power-district/reverser';
13
- export * from './positioner/index';
14
- export * from './positioner/point';
15
- export * from './positioner/responder-type';
16
- export * from './device/index';
17
- export * from './device/channel';
1
+ export * from './source/district';
2
+ export * from './source/layout';
3
+ export * from './source/position';
4
+ export * from './source/route';
5
+ export * from './source/router';
6
+ export * from './source/section';
7
+ export * from './source/span';
8
+ export * from './source/tile';
9
+ export * from './source/track';
10
+ export * from './source/monitor';
11
+ export * from './source/throttle';
12
+ export * from './source/power-district/index';
13
+ export * from './source/power-district/activator';
14
+ export * from './source/power-district/monitor';
15
+ export * from './source/power-district/reverser';
16
+ export * from './source/positioner/index';
17
+ export * from './source/positioner/point';
18
+ export * from './source/positioner/responder-type';
19
+ export * from './source/device/index';
20
+ export * from './source/device/channel';
@@ -5,13 +5,19 @@ import { Section } from "./section";
5
5
  import { Device } from "./device/index";
6
6
  import { ResponderType } from "./positioner/responder-type";
7
7
  import { Channel } from "./device/channel";
8
+ import { Monitor } from "./monitor";
9
+ import { Throttle } from "./throttle";
8
10
  export declare class Layout {
9
11
  name: string;
10
12
  districts: District[];
11
13
  devices: Device[];
12
14
  responderType: ResponderType[];
15
+ monitors: Monitor[];
16
+ throttles: Throttle[];
13
17
  get allDistricts(): District[];
14
18
  static from(document: any): Layout;
19
+ loadMonitor(source: any, parent: District | Layout): Monitor;
20
+ loadThrottle(source: any, parent: District | Layout): Throttle;
15
21
  loadDistrict(source: any, parent: District | Layout): District;
16
22
  linkDistrict(source: any, district: District): void;
17
23
  loadSection(source: any, district: District): void;
package/.built/layout.js CHANGED
@@ -12,11 +12,15 @@ import { PointPositioner } from "./positioner/point";
12
12
  import { PowerDistrictActivator } from "./power-district/activator";
13
13
  import { PowerDistrictReverser } from "./power-district/reverser";
14
14
  import { PowerDistrictMonitor } from "./power-district/monitor";
15
+ import { Monitor } from "./monitor";
16
+ import { Throttle } from "./throttle";
15
17
  export class Layout {
16
18
  name;
17
19
  districts = [];
18
20
  devices = [];
19
21
  responderType = [];
22
+ monitors = [];
23
+ throttles = [];
20
24
  get allDistricts() {
21
25
  const districts = [];
22
26
  function walkDistrict(district) {
@@ -36,28 +40,42 @@ export class Layout {
36
40
  layout.name = railway.getAttribute('name');
37
41
  const version = railway.getAttribute('version');
38
42
  if (version == '1') {
39
- let district = railway.firstChild;
40
- while (district) {
41
- if (district.tagName == 'district') {
42
- layout.districts.push(layout.loadDistrict(district, layout));
43
+ let child = railway.firstChild;
44
+ while (child) {
45
+ if (child.tagName == 'district') {
46
+ layout.districts.push(layout.loadDistrict(child, layout));
43
47
  }
44
- district = district.nextSibling;
48
+ if (child.tagName == 'monitor') {
49
+ layout.monitors.push(layout.loadMonitor(child, layout));
50
+ }
51
+ if (child.tagName == 'throttle') {
52
+ layout.throttles.push(layout.loadThrottle(child, layout));
53
+ }
54
+ child = child.nextSibling;
45
55
  }
46
- district = railway.firstChild;
56
+ child = railway.firstChild;
47
57
  let index = 0;
48
- while (district) {
49
- if (district.tagName == 'district') {
50
- layout.linkDistrict(district, layout.districts[index]);
58
+ while (child) {
59
+ if (child.tagName == 'district') {
60
+ layout.linkDistrict(child, layout.districts[index]);
51
61
  index++;
52
62
  }
53
- district = district.nextSibling;
63
+ child = child.nextSibling;
54
64
  }
55
65
  }
56
66
  else {
57
- throw new Error(`unsupported railway definition file version '${version}'`);
67
+ throw new Error(`Unsupported railway definition file version '${version}'`);
58
68
  }
59
69
  return layout;
60
70
  }
71
+ loadMonitor(source, parent) {
72
+ const montior = new Monitor(this.findDevice(source.getAttribute('device')), parent);
73
+ return montior;
74
+ }
75
+ loadThrottle(source, parent) {
76
+ const throttle = new Throttle(this.findDevice(source.getAttribute('device')), parent);
77
+ return throttle;
78
+ }
61
79
  loadDistrict(source, parent) {
62
80
  const district = new District(source.getAttribute('name'), parent);
63
81
  let child = source.firstChild;
@@ -80,6 +98,9 @@ export class Layout {
80
98
  if (child.tagName == 'district') {
81
99
  district.children.push(this.loadDistrict(child, district));
82
100
  }
101
+ if (child.tagName == 'monitor') {
102
+ district.monitors.push(this.loadMonitor(child, district));
103
+ }
83
104
  child = child.nextSibling;
84
105
  }
85
106
  return district;
@@ -220,6 +241,7 @@ export class Layout {
220
241
  }
221
242
  linkRouter(source, router) {
222
243
  let child = source.firstChild;
244
+ let active;
223
245
  while (child) {
224
246
  if (child.tagName == 'route') {
225
247
  const route = new Route(child.getAttribute('name'), router);
@@ -227,10 +249,17 @@ export class Layout {
227
249
  route.in.out = router;
228
250
  route.out = this.findSection(child.getAttribute('out'), router.district);
229
251
  route.out.in = router;
252
+ if (child.hasAttribute('active')) {
253
+ if (active) {
254
+ throw new Error(`Router '${router.domainName}' has multiple active routes (${active.name}, ${route.name}).`);
255
+ }
256
+ active = route;
257
+ }
230
258
  router.routes.push(route);
231
259
  }
232
260
  child = child.nextSibling;
233
261
  }
262
+ router.activeRoute = active;
234
263
  }
235
264
  loadPowerDistrict(source, district) {
236
265
  const powerDistrict = new PowerDistrict(source.getAttribute('name'), district);
@@ -0,0 +1,9 @@
1
+ import { Device } from "./device";
2
+ import { District } from "./district";
3
+ import { Layout } from "./layout";
4
+ export declare class Monitor {
5
+ device: Device;
6
+ scope: District | Layout;
7
+ constructor(device: Device, scope: District | Layout);
8
+ dump(): void;
9
+ }
@@ -0,0 +1,15 @@
1
+ import { Layout } from "./layout";
2
+ export class Monitor {
3
+ device;
4
+ scope;
5
+ constructor(device, scope) {
6
+ this.device = device;
7
+ this.scope = scope;
8
+ }
9
+ dump() {
10
+ console.group('Monitor');
11
+ console.log('scope:', this.scope instanceof Layout ? '*' : this.scope.domainName);
12
+ this.device.dump();
13
+ console.groupEnd();
14
+ }
15
+ }
@@ -5,6 +5,8 @@ export declare class SectionPosition {
5
5
  reversed: boolean;
6
6
  constructor(section: Section, offset: number, reversed: boolean);
7
7
  get absolutePosition(): number;
8
- advance(distance: number): any;
8
+ advance(distance: number): SectionPosition;
9
+ private invert;
9
10
  toString(): string;
11
+ toPackTrackValue(): string;
10
12
  }
@@ -6,14 +6,23 @@ export class SectionPosition {
6
6
  this.section = section;
7
7
  this.offset = offset;
8
8
  this.reversed = reversed;
9
+ if (offset > section.length || offset < 0) {
10
+ throw new Error(`Offset ${offset} out of range for section '${section.domainName}' (0 - ${section.length})`);
11
+ }
9
12
  }
13
+ // returns the absolute position of the point inside the section
14
+ // regardless of direction
10
15
  get absolutePosition() {
11
16
  if (this.reversed) {
12
17
  return this.section.length - this.offset;
13
18
  }
14
19
  return this.offset;
15
20
  }
21
+ // TODO verify reverse
16
22
  advance(distance) {
23
+ if (distance < 0) {
24
+ return this.invert().advance(-distance).invert();
25
+ }
17
26
  if (this.offset + distance > this.section.length) {
18
27
  const next = this.section.next(this.reversed);
19
28
  if (!next) {
@@ -23,7 +32,14 @@ export class SectionPosition {
23
32
  }
24
33
  return new SectionPosition(this.section, this.offset + distance, this.reversed);
25
34
  }
35
+ // reverse direction
36
+ invert() {
37
+ return new SectionPosition(this.section, this.section.length - this.offset, !this.reversed);
38
+ }
26
39
  toString() {
27
40
  return `${this.section.name} @ ${this.offset.toFixed(1)} ${this.reversed ? 'backward' : 'forward'}`;
28
41
  }
42
+ toPackTrackValue() {
43
+ return `${this.section.domainName}@${this.offset}${this.reversed ? 'R' : 'F'}`;
44
+ }
29
45
  }
@@ -8,6 +8,6 @@ export declare class PointPositioner extends Positioner {
8
8
  channel: Channel;
9
9
  responder: ResponderType;
10
10
  constructor(track: Track, offset: number, channel: Channel, responder: ResponderType);
11
- get position(): any;
11
+ get position(): import("..").SectionPosition;
12
12
  dump(): void;
13
13
  }
@@ -1,8 +1,8 @@
1
- import { Device } from "./device";
1
+ import { Device } from "./index";
2
2
  export declare class Channel {
3
3
  device: Device;
4
4
  name: string;
5
5
  constructor(device: Device, name: string);
6
- dump(): void;
7
6
  publish(data: any): void;
7
+ toString(): string;
8
8
  }
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Channel = void 0;
4
- class Channel {
1
+ export class Channel {
5
2
  device;
6
3
  name;
7
4
  constructor(device, name) {
8
5
  this.device = device;
9
6
  this.name = name;
10
7
  }
11
- dump() {
12
- console.log(`Channel '${this.name}' on ${this.device.identifier}`);
13
- }
14
8
  publish(data) { }
9
+ toString() {
10
+ return `${this.device.identifier}/${this.name}`;
11
+ }
15
12
  }
16
- exports.Channel = Channel;
@@ -0,0 +1,10 @@
1
+ import { Channel } from "./channel";
2
+ export declare class Device {
3
+ identifier: string;
4
+ channels: Channel[];
5
+ lastDiscovery: {
6
+ date: Date;
7
+ address: string;
8
+ };
9
+ constructor(identifier: string);
10
+ }
@@ -0,0 +1,8 @@
1
+ export class Device {
2
+ identifier;
3
+ channels = [];
4
+ lastDiscovery;
5
+ constructor(identifier) {
6
+ this.identifier = identifier;
7
+ }
8
+ }
@@ -1,5 +1,6 @@
1
1
  import { Layout } from "./layout";
2
- import { PowerDistrict } from "./power-district";
2
+ import { Monitor } from "./monitor";
3
+ import { PowerDistrict } from "./power-district/index";
3
4
  import { Router } from "./router";
4
5
  import { Section } from "./section";
5
6
  export declare class District {
@@ -9,12 +10,7 @@ export declare class District {
9
10
  powerDistricts: PowerDistrict[];
10
11
  sections: Section[];
11
12
  routers: Router[];
13
+ monitors: Monitor[];
12
14
  constructor(name: string, parent: District | Layout);
13
15
  get domainName(): string;
14
- dump(): void;
15
- toDotReference(): any;
16
- toDotDefinition(): any;
17
- toDotConnection(): any;
18
- toSVG(): any;
19
- findSVGPositions(): any;
20
16
  }
@@ -1,86 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.District = void 0;
4
- const layout_1 = require("./layout");
5
- class District {
1
+ import { Layout } from "./layout";
2
+ export class District {
6
3
  name;
7
4
  parent;
8
5
  children = [];
9
6
  powerDistricts = [];
10
7
  sections = [];
11
8
  routers = [];
9
+ monitors = [];
12
10
  constructor(name, parent) {
13
11
  this.name = name;
14
12
  this.parent = parent;
15
13
  }
16
14
  get domainName() {
17
- if (this.parent instanceof layout_1.Layout) {
15
+ if (this.parent instanceof Layout) {
18
16
  return `${this.name}.${this.parent.name}`;
19
17
  }
20
18
  return `${this.name}.${this.parent.domainName}`;
21
19
  }
22
- dump() {
23
- console.group(`District ${this.domainName}`);
24
- if (this.powerDistricts.length) {
25
- console.group('power districts');
26
- for (let district of this.powerDistricts) {
27
- district.dump();
28
- }
29
- console.groupEnd();
30
- }
31
- if (this.sections.length) {
32
- console.group('sections');
33
- for (let section of this.sections) {
34
- section.dump();
35
- }
36
- console.groupEnd();
37
- }
38
- if (this.children.length) {
39
- console.group('children');
40
- for (let district of this.children) {
41
- district.dump();
42
- }
43
- console.groupEnd();
44
- }
45
- console.groupEnd();
46
- }
47
- toDotReference() {
48
- return `cluster_${this.name.replace(/-/g, '_')}${this.parent instanceof District ? this.parent.toDotReference() : ''}`;
49
- }
50
- toDotDefinition() {
51
- return `
52
- subgraph ${this.toDotReference()} {
53
- label = ${JSON.stringify(this.name)}
54
-
55
- ${this.sections.map(section => section.toDotDefinition()).join('')}
56
- ${this.routers.map(router => router.toDotDefinition()).join('')}
57
-
58
- ${this.children.map(child => child.toDotDefinition()).join('')}
59
- }
60
- `;
61
- }
62
- toDotConnection() {
63
- return `
64
- ${this.sections.map(section => section.toDotConnection()).join('')}
65
- ${this.routers.map(router => router.toDotConnection()).join('')}
66
-
67
- ${this.children.map(child => child.toDotConnection()).join('')}
68
- `;
69
- }
70
- toSVG() {
71
- return `
72
- <g id=${JSON.stringify(this.domainName)}>
73
- ${this.sections.map(section => section.toSVG()).join('')}
74
-
75
- ${this.children.map(child => child.toSVG()).join('')}
76
- </g>
77
- `;
78
- }
79
- findSVGPositions() {
80
- return [
81
- ...this.sections.map(section => section.findSVGPositions()),
82
- ...this.children.map(child => child.findSVGPositions())
83
- ];
84
- }
85
20
  }
86
- exports.District = District;
@@ -1,17 +1,23 @@
1
1
  import { District } from "./district";
2
- import { PowerDistrict } from "./power-district";
2
+ import { PowerDistrict } from "./power-district/index";
3
3
  import { Router } from "./router";
4
4
  import { Section } from "./section";
5
- import { Device } from "./device/device";
6
- import { ResponderType } from "../positioner/responder-type";
5
+ import { Device } from "./device/index";
6
+ import { ResponderType } from "./positioner/responder-type";
7
7
  import { Channel } from "./device/channel";
8
+ import { Monitor } from "./monitor";
9
+ import { Throttle } from "./throttle";
8
10
  export declare class Layout {
9
11
  name: string;
10
12
  districts: District[];
11
13
  devices: Device[];
12
14
  responderType: ResponderType[];
15
+ monitors: Monitor[];
16
+ throttles: Throttle[];
13
17
  get allDistricts(): District[];
14
18
  static from(document: any): Layout;
19
+ loadMonitor(source: any, parent: District | Layout): Monitor;
20
+ loadThrottle(source: any, parent: District | Layout): Throttle;
15
21
  loadDistrict(source: any, parent: District | Layout): District;
16
22
  linkDistrict(source: any, district: District): void;
17
23
  loadSection(source: any, district: District): void;
@@ -23,7 +29,4 @@ export declare class Layout {
23
29
  loadRouter(source: any, district: District): Router;
24
30
  linkRouter(source: any, router: Router): void;
25
31
  loadPowerDistrict(source: any, district: District): PowerDistrict;
26
- toDot(): string;
27
- toSVG(inject?: string): string;
28
- dump(): void;
29
32
  }