@squawk/flightplan 0.3.2 → 0.4.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/README.md CHANGED
@@ -62,7 +62,7 @@ Creates a resolver from optional lookup providers.
62
62
  - `options.navaids` - navaid lookup (must provide `byIdent`)
63
63
  - `options.fixes` - fix lookup (must provide `byIdent`)
64
64
  - `options.airways` - airway lookup (must provide `byDesignation` and `expand`)
65
- - `options.procedures` - procedure lookup (must provide `byName` and `expand`)
65
+ - `options.procedures` - procedure lookup (must provide `byIdentifier` and `expand`)
66
66
 
67
67
  **Returns:** `FlightplanResolver` - an object with the `parse` method described below.
68
68
 
@@ -84,8 +84,8 @@ Each element has a `type` discriminant and a `raw` field with the original token
84
84
  | Type | Description | Key fields |
85
85
  | --------------- | ----------------------------------------- | ----------------------------------------------------------- |
86
86
  | `airport` | Resolved airport (ICAO or FAA ID) | `airport` |
87
- | `sid` | Standard Instrument Departure | `procedure`, `waypoints` |
88
- | `star` | Standard Terminal Arrival Route | `procedure`, `waypoints` |
87
+ | `sid` | Standard Instrument Departure | `procedure`, `legs` |
88
+ | `star` | Standard Terminal Arrival Route | `procedure`, `legs` |
89
89
  | `airway` | Airway segment between entry and exit fix | `airway`, `entryFix`, `exitFix`, `waypoints` |
90
90
  | `direct` | DCT (direct) indicator | - |
91
91
  | `waypoint` | Resolved fix or navaid | `fix` and/or `navaid`, `lat`, `lon` |
@@ -1,4 +1,4 @@
1
- import type { Airport, Airway, AirwayWaypoint, Fix, Navaid, Procedure, ProcedureWaypoint } from '@squawk/types';
1
+ import type { Airport, Airway, AirwayWaypoint, Fix, Navaid, Procedure, ProcedureLeg } from '@squawk/types';
2
2
  /**
3
3
  * Minimal airport lookup interface consumed by the flightplan resolver.
4
4
  * Structurally compatible with {@link @squawk/airports!AirportResolver}.
@@ -43,12 +43,12 @@ export interface FlightplanAirwayLookup {
43
43
  * Structurally compatible with {@link @squawk/procedures!ProcedureResolver}.
44
44
  */
45
45
  export interface FlightplanProcedureLookup {
46
- /** Looks up a procedure by FAA computer code (e.g. "AALLE4"). */
47
- byName(computerCode: string): Procedure | undefined;
48
- /** Expands a procedure into an ordered waypoint sequence. */
49
- expand(computerCode: string, transitionName?: string): {
46
+ /** Looks up every procedure that publishes the given CIFP identifier across airports. */
47
+ byIdentifier(identifier: string): Procedure[];
48
+ /** Expands a procedure into an ordered leg sequence. */
49
+ expand(airportId: string, identifier: string, transitionName?: string): {
50
50
  procedure: Procedure;
51
- waypoints: ProcedureWaypoint[];
51
+ legs: ProcedureLeg[];
52
52
  } | undefined;
53
53
  }
54
54
  /**
@@ -72,8 +72,8 @@ export interface SidRouteElement {
72
72
  raw: string;
73
73
  /** Resolved procedure record. */
74
74
  procedure: Procedure;
75
- /** Ordered waypoint sequence for the procedure. */
76
- waypoints: ProcedureWaypoint[];
75
+ /** Ordered legs for the procedure expansion. */
76
+ legs: ProcedureLeg[];
77
77
  }
78
78
  /**
79
79
  * A Standard Terminal Arrival Route (STAR) in the route.
@@ -85,8 +85,8 @@ export interface StarRouteElement {
85
85
  raw: string;
86
86
  /** Resolved procedure record. */
87
87
  procedure: Procedure;
88
- /** Ordered waypoint sequence for the procedure. */
89
- waypoints: ProcedureWaypoint[];
88
+ /** Ordered legs for the procedure expansion. */
89
+ legs: ProcedureLeg[];
90
90
  }
91
91
  /**
92
92
  * A segment along a published airway between an entry fix and exit fix.
@@ -1 +1 @@
1
- {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,MAAM,EACN,cAAc,EACd,GAAG,EACH,MAAM,EACN,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAMvB;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,mEAAmE;IACnE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAC5C,sDAAsD;IACtD,MAAM,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H,MAAM,MAAM,YAAY,GACpB,mBAAmB,GACnB,eAAe,GACf,gBAAgB,GAChB,kBAAkB,GAClB,kBAAkB,GAClB,oBAAoB,GACpB,sBAAsB,GACtB,yBAAyB,GACzB,sBAAsB,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAMD;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IACnC,8BAA8B;IAC9B,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,2BAA2B;IAC3B,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,8BAA8B;IAC9B,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,iCAAiC;IACjC,UAAU,CAAC,EAAE,yBAAyB,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,CAAC;CACzC;AA6ND;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB,CA6I/F"}
package/dist/resolver.js CHANGED
@@ -101,33 +101,50 @@ function tryAirport(token, airports) {
101
101
  return undefined;
102
102
  }
103
103
  /**
104
- * Attempts to resolve a token as a SID or STAR procedure.
104
+ * Attempts to resolve a token as a SID or STAR procedure at a given
105
+ * airport context. The airport context is the identifier of the most
106
+ * recently seen airport (for SIDs, the departure airport; for STARs,
107
+ * the arrival airport - but since the route is parsed left-to-right,
108
+ * the most recent airport is the best available hint).
105
109
  *
106
- * Accepts both the bare computer code (e.g. "NUBLE4") and the dotted
107
- * procedure-with-transition form (e.g. "NUBLE4.JJIMY"). When a transition
108
- * is supplied, it is forwarded to the procedure resolver so that the
109
- * transition's waypoints are merged into the expansion.
110
+ * Accepts both the bare CIFP identifier (e.g. `NUBLE4`) and the dotted
111
+ * identifier-with-transition form (e.g. `NUBLE4.JJIMY`). When a
112
+ * transition is supplied it is forwarded to the procedure resolver so
113
+ * that the transition's legs are merged into the expansion.
110
114
  */
111
- function tryProcedure(token, procedures) {
115
+ function tryProcedure(token, procedures, airportContext) {
112
116
  if (!procedures) {
113
117
  return undefined;
114
118
  }
115
119
  const dotIndex = token.indexOf('.');
116
- const computerCode = dotIndex >= 0 ? token.slice(0, dotIndex) : token;
120
+ const identifier = dotIndex >= 0 ? token.slice(0, dotIndex) : token;
117
121
  const transitionName = dotIndex >= 0 ? token.slice(dotIndex + 1) : undefined;
118
- if (computerCode.length === 0) {
122
+ if (identifier.length === 0) {
119
123
  return undefined;
120
124
  }
121
- const proc = procedures.byName(computerCode);
122
- if (!proc) {
125
+ const candidates = procedures.byIdentifier(identifier);
126
+ if (candidates.length === 0) {
123
127
  return undefined;
124
128
  }
125
- const expansion = procedures.expand(computerCode, transitionName);
126
- const waypoints = expansion ? expansion.waypoints : [];
129
+ let proc;
130
+ if (airportContext !== undefined) {
131
+ const upperAirport = airportContext.toUpperCase();
132
+ proc = candidates.find((c) => c.airports.some((a) => a.toUpperCase() === upperAirport));
133
+ }
134
+ if (proc === undefined) {
135
+ proc = candidates[0];
136
+ }
137
+ if (proc === undefined || proc.type === 'IAP') {
138
+ return undefined;
139
+ }
140
+ const airportForExpansion = proc.airports[0];
141
+ const legs = airportForExpansion === undefined
142
+ ? []
143
+ : (procedures.expand(airportForExpansion, identifier, transitionName)?.legs ?? []);
127
144
  if (proc.type === 'SID') {
128
- return { type: 'sid', raw: token, procedure: proc, waypoints };
145
+ return { type: 'sid', raw: token, procedure: proc, legs };
129
146
  }
130
- return { type: 'star', raw: token, procedure: proc, waypoints };
147
+ return { type: 'star', raw: token, procedure: proc, legs };
131
148
  }
132
149
  /**
133
150
  * Attempts to resolve a token as a fix waypoint.
@@ -208,6 +225,7 @@ export function createFlightplanResolver(options) {
208
225
  const tokens = raw.split(/\s+/);
209
226
  const elements = [];
210
227
  let lastWaypointIdent;
228
+ let lastAirportIdent;
211
229
  let i = 0;
212
230
  while (i < tokens.length) {
213
231
  const token = tokens[i].toUpperCase();
@@ -279,17 +297,22 @@ export function createFlightplanResolver(options) {
279
297
  // use it as the entry fix (e.g. "BOS V16 CCC" where BOS is both an
280
298
  // airport and a navaid on V16).
281
299
  lastWaypointIdent = token;
300
+ lastAirportIdent = airportElement.airport.icao ?? airportElement.airport.faaId;
282
301
  i++;
283
302
  continue;
284
303
  }
285
304
  // Try procedure (SID/STAR)
286
- const procElement = tryProcedure(token, procedures);
305
+ const procElement = tryProcedure(token, procedures, lastAirportIdent);
287
306
  if (procElement) {
288
307
  elements.push(procElement);
289
- // Update last waypoint to the last fix in the procedure
290
- if (procElement.waypoints.length > 0) {
291
- lastWaypointIdent =
292
- procElement.waypoints[procElement.waypoints.length - 1].fixIdentifier;
308
+ // Update last waypoint to the last fix in the procedure expansion
309
+ // that actually terminates at a fix (some leg types have no fix).
310
+ for (let j = procElement.legs.length - 1; j >= 0; j--) {
311
+ const fixIdent = procElement.legs[j]?.fixIdentifier;
312
+ if (fixIdent !== undefined) {
313
+ lastWaypointIdent = fixIdent;
314
+ break;
315
+ }
293
316
  }
294
317
  i++;
295
318
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"route-distance.d.ts","sourceRoot":"","sources":["../src/route-distance.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAM/D;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;IACnB,8FAA8F;IAC9F,oBA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 @@ function extractGeoPoints(elements) {
70
70
  break;
71
71
  case 'sid':
72
72
  case 'star':
73
- for (const wp of el.waypoints) {
74
- emit({ label: wp.fixIdentifier, lat: wp.lat, lon: wp.lon });
73
+ for (const leg of el.legs) {
74
+ if (leg.fixIdentifier === undefined || leg.lat === undefined || leg.lon === undefined) {
75
+ continue;
76
+ }
77
+ emit({ label: leg.fixIdentifier, lat: leg.lat, lon: leg.lon });
75
78
  }
76
79
  break;
77
80
  case 'unresolved':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squawk/flightplan",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Flight plan route string parsing and resolution using composed navigation resolvers",
6
6
  "author": "Neil Cochran",
@@ -34,20 +34,20 @@
34
34
  "lint:pack": "publint && attw --pack . --profile esm-only"
35
35
  },
36
36
  "dependencies": {
37
- "@squawk/geo": "*",
38
- "@squawk/types": "*"
37
+ "@squawk/geo": "^0.3.0",
38
+ "@squawk/types": "^0.5.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@squawk/airport-data": "*",
42
- "@squawk/airports": "*",
43
- "@squawk/airway-data": "*",
44
- "@squawk/airways": "*",
45
- "@squawk/fix-data": "*",
46
- "@squawk/fixes": "*",
47
- "@squawk/navaid-data": "*",
48
- "@squawk/navaids": "*",
49
- "@squawk/procedure-data": "*",
50
- "@squawk/procedures": "*",
41
+ "@squawk/airport-data": "^0.5.0",
42
+ "@squawk/airports": "^0.4.0",
43
+ "@squawk/airway-data": "^0.4.0",
44
+ "@squawk/airways": "^0.3.0",
45
+ "@squawk/fix-data": "^0.5.0",
46
+ "@squawk/fixes": "^0.2.0",
47
+ "@squawk/navaid-data": "^0.5.0",
48
+ "@squawk/navaids": "^0.3.0",
49
+ "@squawk/procedure-data": "^0.5.0",
50
+ "@squawk/procedures": "^0.4.0",
51
51
  "@types/node": "^25.6.0"
52
52
  },
53
53
  "keywords": [