@dwp/govuk-casa 8.2.3 → 8.2.6
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/CHANGELOG.md +9 -0
- package/README.md +1 -0
- package/dist/casa.d.ts +212 -5
- package/dist/casa.js +144 -7
- package/dist/lib/CasaTemplateLoader.d.ts +4 -0
- package/dist/lib/CasaTemplateLoader.js +5 -0
- package/dist/lib/JourneyContext.d.ts +85 -13
- package/dist/lib/JourneyContext.js +103 -16
- package/dist/lib/Plan.d.ts +122 -49
- package/dist/lib/Plan.js +161 -37
- package/dist/lib/ValidationError.d.ts +38 -48
- package/dist/lib/ValidationError.js +30 -42
- package/dist/lib/ValidatorFactory.d.ts +42 -52
- package/dist/lib/ValidatorFactory.js +37 -48
- package/dist/lib/configuration-ingestor.d.ts +15 -0
- package/dist/lib/configuration-ingestor.js +17 -0
- package/dist/lib/configure.d.ts +6 -2
- package/dist/lib/configure.js +19 -3
- package/dist/lib/end-session.d.ts +3 -2
- package/dist/lib/end-session.js +2 -1
- package/dist/lib/field.d.ts +97 -35
- package/dist/lib/field.js +90 -41
- package/dist/lib/nunjucks-filters.d.ts +12 -2
- package/dist/lib/nunjucks-filters.js +11 -1
- package/dist/lib/nunjucks.d.ts +1 -0
- package/dist/lib/nunjucks.js +1 -0
- package/dist/lib/utils.d.ts +46 -14
- package/dist/lib/utils.js +44 -27
- package/dist/lib/validators/dateObject.d.ts +75 -1
- package/dist/lib/validators/dateObject.js +29 -18
- package/dist/lib/validators/email.d.ts +28 -1
- package/dist/lib/validators/email.js +20 -9
- package/dist/lib/validators/inArray.d.ts +34 -1
- package/dist/lib/validators/inArray.js +21 -0
- package/dist/lib/validators/index.js +3 -0
- package/dist/lib/validators/nino.d.ts +34 -1
- package/dist/lib/validators/nino.js +17 -7
- package/dist/lib/validators/postalAddressObject.d.ts +68 -1
- package/dist/lib/validators/postalAddressObject.js +27 -15
- package/dist/lib/validators/regex.d.ts +35 -1
- package/dist/lib/validators/regex.js +17 -7
- package/dist/lib/validators/required.d.ts +28 -1
- package/dist/lib/validators/required.js +19 -6
- package/dist/lib/validators/strlen.d.ts +40 -1
- package/dist/lib/validators/strlen.js +18 -8
- package/dist/lib/validators/wordCount.d.ts +40 -1
- package/dist/lib/validators/wordCount.js +18 -8
- package/dist/lib/waypoint-url.d.ts +1 -0
- package/dist/lib/waypoint-url.js +10 -0
- package/dist/middleware/data.js +21 -5
- package/dist/middleware/gather-fields.js +1 -0
- package/dist/middleware/pre.js +1 -0
- package/dist/middleware/steer-journey.js +2 -1
- package/dist/middleware/strip-proxy-path.js +6 -2
- package/dist/middleware/validate-fields.js +3 -0
- package/dist/routes/ancillary.d.ts +16 -5
- package/dist/routes/ancillary.js +7 -3
- package/dist/routes/journey.d.ts +30 -6
- package/dist/routes/journey.js +27 -0
- package/dist/routes/static.d.ts +1 -0
- package/dist/routes/static.js +2 -1
- package/package.json +16 -11
- package/views/casa/components/character-count/README.md +1 -1
- package/views/casa/components/input/README.md +1 -1
- package/views/casa/components/radios/README.md +2 -2
- package/views/casa/components/textarea/README.md +1 -1
|
@@ -43,14 +43,21 @@ const utils_js_1 = require("./utils.js");
|
|
|
43
43
|
const { cloneDeep, isPlainObject, isObject, has, isEqual, } = lodash_1.default; // CommonJS
|
|
44
44
|
const log = (0, logger_js_1.default)('lib:journey-context');
|
|
45
45
|
/**
|
|
46
|
+
* @access private
|
|
46
47
|
* @typedef {import('../casa').Page} Page
|
|
47
48
|
*/
|
|
48
49
|
/**
|
|
50
|
+
* @access private
|
|
49
51
|
* @typedef {import('../casa').ContextEventHandler} ContextEventHandler
|
|
50
52
|
*/
|
|
51
53
|
/**
|
|
54
|
+
* @access private
|
|
52
55
|
* @typedef {import('../casa').ContextEvent} ContextEvent
|
|
53
56
|
*/
|
|
57
|
+
/**
|
|
58
|
+
* @access private
|
|
59
|
+
* @typedef {import('express').Request} ExpressRequest
|
|
60
|
+
*/
|
|
54
61
|
function validateObjectKey(key = '') {
|
|
55
62
|
const keyLower = String.prototype.toLowerCase.call(key);
|
|
56
63
|
if (keyLower === 'prototype' || keyLower === '__proto__' || keyLower === 'constructor') {
|
|
@@ -59,6 +66,9 @@ function validateObjectKey(key = '') {
|
|
|
59
66
|
return String(key);
|
|
60
67
|
}
|
|
61
68
|
exports.validateObjectKey = validateObjectKey;
|
|
69
|
+
/**
|
|
70
|
+
* @memberof module:@dwp/govuk-casa
|
|
71
|
+
*/
|
|
62
72
|
class JourneyContext {
|
|
63
73
|
/**
|
|
64
74
|
* Constructor.
|
|
@@ -165,6 +175,11 @@ class JourneyContext {
|
|
|
165
175
|
}
|
|
166
176
|
throw new TypeError(`Page must be a string or Page object. Got ${typeof page}`);
|
|
167
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Get all data.
|
|
180
|
+
*
|
|
181
|
+
* @returns {object} Page data
|
|
182
|
+
*/
|
|
168
183
|
getData() {
|
|
169
184
|
return __classPrivateFieldGet(this, _JourneyContext_data, "f");
|
|
170
185
|
}
|
|
@@ -181,11 +196,6 @@ class JourneyContext {
|
|
|
181
196
|
/**
|
|
182
197
|
* Write field form data from a page HTML form, into the `data` model.
|
|
183
198
|
*
|
|
184
|
-
* By default this will store the data as-is, keyed against the page's
|
|
185
|
-
* waypoint ID. However, when passing a `Page` instance, its
|
|
186
|
-
* `fieldWriter()` method will be called to transform the provided formData
|
|
187
|
-
* before storing in `data`
|
|
188
|
-
*
|
|
189
199
|
* @param {string | Page} page Page waypoint ID, or Page object
|
|
190
200
|
* @param {object} webFormData Data to overwrite with
|
|
191
201
|
* @returns {JourneyContext} Chain
|
|
@@ -268,6 +278,14 @@ class JourneyContext {
|
|
|
268
278
|
var _a;
|
|
269
279
|
return (_a = __classPrivateFieldGet(this, _JourneyContext_validation, "f")[validateObjectKey(pageId)]) !== null && _a !== void 0 ? _a : [];
|
|
270
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Same as `getValidationErrorsForPage()`, but the return value is
|
|
283
|
+
* an object whose keys are the field names, and values are the list of errors
|
|
284
|
+
* associated with that particular field.
|
|
285
|
+
*
|
|
286
|
+
* @param {string} pageId Page ID.
|
|
287
|
+
* @returns {object} Object indexed by field names; values containing list of errors
|
|
288
|
+
*/
|
|
271
289
|
getValidationErrorsForPageByField(pageId) {
|
|
272
290
|
const errors = this.getValidationErrorsForPage(pageId);
|
|
273
291
|
const obj = Object.create(null);
|
|
@@ -362,6 +380,14 @@ class JourneyContext {
|
|
|
362
380
|
__classPrivateFieldSet(this, _JourneyContext_eventListenerPreState, this.toObject(), "f");
|
|
363
381
|
return this;
|
|
364
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Execute all listeners for the given event.
|
|
385
|
+
*
|
|
386
|
+
* @param {object} params Params
|
|
387
|
+
* @param {string} params.event Event (waypoint-change | context-change)
|
|
388
|
+
* @param {object} params.session Session
|
|
389
|
+
* @returns {JourneyContext} Chain
|
|
390
|
+
*/
|
|
365
391
|
applyEventListeners({ event, session }) {
|
|
366
392
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
367
393
|
if (!__classPrivateFieldGet(this, _JourneyContext_eventListeners, "f").length) {
|
|
@@ -440,10 +466,19 @@ class JourneyContext {
|
|
|
440
466
|
* @returns {void}
|
|
441
467
|
*/
|
|
442
468
|
static initContextStore(session) {
|
|
469
|
+
// For existing sessions that were created prior to `journeyContextList`
|
|
470
|
+
// being remodelled as an array, we need to convert the "legacy" structure
|
|
471
|
+
// into an equivalent array.
|
|
472
|
+
if (isPlainObject(session === null || session === void 0 ? void 0 : session.journeyContextList)) {
|
|
473
|
+
log.trace('Session context list already initialised as an object (legacy structure). Will convert from object to array.');
|
|
474
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
475
|
+
session.journeyContextList = Object.entries(session.journeyContextList);
|
|
476
|
+
}
|
|
477
|
+
// Initialise new context list in the session
|
|
443
478
|
if (!has(session, 'journeyContextList')) {
|
|
444
479
|
log.trace('Initialising session with a default journey context list');
|
|
445
480
|
/* eslint-disable-next-line no-param-reassign */
|
|
446
|
-
session.journeyContextList =
|
|
481
|
+
session.journeyContextList = [];
|
|
447
482
|
const defaultContext = new JourneyContext();
|
|
448
483
|
defaultContext.identity.id = JourneyContext.DEFAULT_CONTEXT_ID;
|
|
449
484
|
JourneyContext.putContext(session, defaultContext);
|
|
@@ -471,6 +506,16 @@ class JourneyContext {
|
|
|
471
506
|
}
|
|
472
507
|
return id;
|
|
473
508
|
}
|
|
509
|
+
/**
|
|
510
|
+
* Retrieve the default Journey Context. This is just a convenient wrapper
|
|
511
|
+
* around `getContextById()`.
|
|
512
|
+
*
|
|
513
|
+
* @param {object} session Request session
|
|
514
|
+
* @returns {JourneyContext} The default Journey Context
|
|
515
|
+
*/
|
|
516
|
+
static getDefaultContext(session) {
|
|
517
|
+
return JourneyContext.getContextById(session, JourneyContext.DEFAULT_CONTEXT_ID);
|
|
518
|
+
}
|
|
474
519
|
/**
|
|
475
520
|
* Lookup context from session using the ID.
|
|
476
521
|
*
|
|
@@ -479,10 +524,11 @@ class JourneyContext {
|
|
|
479
524
|
* @returns {JourneyContext} The discovered JourneyContext instance
|
|
480
525
|
*/
|
|
481
526
|
static getContextById(session, id) {
|
|
482
|
-
|
|
527
|
+
const list = new Map(session === null || session === void 0 ? void 0 : session.journeyContextList);
|
|
528
|
+
if (list.has(id)) {
|
|
483
529
|
// ESLint disabled as `id` has been verified as an "own" property
|
|
484
530
|
/* eslint-disable-next-line security/detect-object-injection */
|
|
485
|
-
return JourneyContext.fromObject(
|
|
531
|
+
return JourneyContext.fromObject(list.get(id));
|
|
486
532
|
}
|
|
487
533
|
return undefined;
|
|
488
534
|
}
|
|
@@ -495,7 +541,8 @@ class JourneyContext {
|
|
|
495
541
|
*/
|
|
496
542
|
static getContextByName(session, name) {
|
|
497
543
|
if (session) {
|
|
498
|
-
const
|
|
544
|
+
const list = new Map(session === null || session === void 0 ? void 0 : session.journeyContextList);
|
|
545
|
+
const context = [...list.values()].find((c) => (c.identity.name === name));
|
|
499
546
|
if (context) {
|
|
500
547
|
return JourneyContext.fromObject(context);
|
|
501
548
|
}
|
|
@@ -511,7 +558,8 @@ class JourneyContext {
|
|
|
511
558
|
*/
|
|
512
559
|
static getContextsByTag(session, tag) {
|
|
513
560
|
if (session) {
|
|
514
|
-
|
|
561
|
+
const list = new Map(session === null || session === void 0 ? void 0 : session.journeyContextList);
|
|
562
|
+
return [...list.values()].filter((c) => { var _a; return ((_a = c.identity.tags) === null || _a === void 0 ? void 0 : _a.includes(tag)); }).map((c) => (JourneyContext.fromObject(c)));
|
|
515
563
|
}
|
|
516
564
|
return undefined;
|
|
517
565
|
}
|
|
@@ -523,7 +571,7 @@ class JourneyContext {
|
|
|
523
571
|
*/
|
|
524
572
|
static getContexts(session) {
|
|
525
573
|
if (has(session, 'journeyContextList')) {
|
|
526
|
-
return
|
|
574
|
+
return session.journeyContextList.map(([, contextObj]) => (JourneyContext.fromObject(contextObj)));
|
|
527
575
|
}
|
|
528
576
|
return [];
|
|
529
577
|
}
|
|
@@ -558,8 +606,10 @@ class JourneyContext {
|
|
|
558
606
|
event: 'context-change',
|
|
559
607
|
session,
|
|
560
608
|
});
|
|
609
|
+
const list = new Map(session.journeyContextList);
|
|
610
|
+
list.set(context.identity.id, context.toObject());
|
|
561
611
|
/* eslint-disable-next-line no-param-reassign */
|
|
562
|
-
session.journeyContextList
|
|
612
|
+
session.journeyContextList = [...list.entries()];
|
|
563
613
|
}
|
|
564
614
|
/**
|
|
565
615
|
* Remove a context from the session store.
|
|
@@ -573,22 +623,59 @@ class JourneyContext {
|
|
|
573
623
|
JourneyContext.removeContextById(session, context.identity.id);
|
|
574
624
|
}
|
|
575
625
|
}
|
|
626
|
+
/**
|
|
627
|
+
* Remove context from session using the ID.
|
|
628
|
+
*
|
|
629
|
+
* @param {object} session Request session
|
|
630
|
+
* @param {string} id Context ID
|
|
631
|
+
* @returns {void}
|
|
632
|
+
*/
|
|
576
633
|
static removeContextById(session, id) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
634
|
+
var _a;
|
|
635
|
+
const index = ((_a = session === null || session === void 0 ? void 0 : session.journeyContextList) !== null && _a !== void 0 ? _a : []).findIndex(([contextId]) => contextId === id);
|
|
636
|
+
if (index > -1) {
|
|
637
|
+
session.journeyContextList.splice(index, 1);
|
|
581
638
|
}
|
|
582
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Remove context from session using the name.
|
|
642
|
+
*
|
|
643
|
+
* @param {object} session Request session
|
|
644
|
+
* @param {string} name Context name
|
|
645
|
+
* @returns {void}
|
|
646
|
+
*/
|
|
583
647
|
static removeContextByName(session, name) {
|
|
584
648
|
JourneyContext.removeContext(session, JourneyContext.getContextByName(session, name));
|
|
585
649
|
}
|
|
650
|
+
/**
|
|
651
|
+
* Remove context from session using the tag.
|
|
652
|
+
*
|
|
653
|
+
* @param {object} session Request session
|
|
654
|
+
* @param {string} tag Context tag
|
|
655
|
+
* @returns {void}
|
|
656
|
+
*/
|
|
586
657
|
static removeContextsByTag(session, tag) {
|
|
587
658
|
JourneyContext.getContextsByTag(session, tag).forEach((c) => JourneyContext.removeContext(session, c));
|
|
588
659
|
}
|
|
660
|
+
/**
|
|
661
|
+
* Remove call contexts.
|
|
662
|
+
*
|
|
663
|
+
* @param {object} session Request session
|
|
664
|
+
* @returns {void}
|
|
665
|
+
*/
|
|
589
666
|
static removeContexts(session) {
|
|
590
667
|
JourneyContext.getContexts(session).forEach((c) => JourneyContext.removeContext(session, c));
|
|
591
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* Extract the Journey Context referred to in the incoming request.
|
|
671
|
+
*
|
|
672
|
+
* This will look in `req.params`, `req.query` and
|
|
673
|
+
* `req.body` for a `contextid` parameter, and use that
|
|
674
|
+
* to load the correct Journey Context from the session.
|
|
675
|
+
*
|
|
676
|
+
* @param {ExpressRequest} req ExpressJS incoming request
|
|
677
|
+
* @returns {JourneyContext} The Journey Context
|
|
678
|
+
*/
|
|
592
679
|
static extractContextFromRequest(req) {
|
|
593
680
|
JourneyContext.initContextStore(req.session);
|
|
594
681
|
let contextId;
|
package/dist/lib/Plan.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @memberof module:@dwp/govuk-casa
|
|
3
|
+
*/
|
|
1
4
|
export default class Plan {
|
|
2
5
|
/**
|
|
3
6
|
* Waypoints using the url:// protocol are known as "exit nodes" as they
|
|
@@ -10,15 +13,15 @@ export default class Plan {
|
|
|
10
13
|
/**
|
|
11
14
|
* Create a Plan.
|
|
12
15
|
*
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {boolean} [opts.validateBeforeRouteCondition=true] Check page validity before conditions
|
|
15
|
-
* @param {Function|string} [opts.arbiter=undefined] Arbitration mechanism
|
|
16
|
+
* @param {PlanConstructorOptions} opts Options
|
|
16
17
|
*/
|
|
17
|
-
constructor(opts?:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
constructor(opts?: PlanConstructorOptions);
|
|
19
|
+
/**
|
|
20
|
+
* Retrieve the options set on this Plan.
|
|
21
|
+
*
|
|
22
|
+
* @returns {PlanConstructorOptions} Options map
|
|
23
|
+
*/
|
|
24
|
+
getOptions(): PlanConstructorOptions;
|
|
22
25
|
/**
|
|
23
26
|
* Retrieve the list of skippable waypoints.
|
|
24
27
|
*
|
|
@@ -29,7 +32,7 @@ export default class Plan {
|
|
|
29
32
|
* Add one or more skippable waypoints.
|
|
30
33
|
*
|
|
31
34
|
* @param {...string} waypoints Waypoints
|
|
32
|
-
* @returns {Plan}
|
|
35
|
+
* @returns {Plan} Chain
|
|
33
36
|
*/
|
|
34
37
|
addSkippables(...waypoints: string[]): Plan;
|
|
35
38
|
/**
|
|
@@ -39,40 +42,87 @@ export default class Plan {
|
|
|
39
42
|
* @returns {boolean} True if waypoint can be skipped
|
|
40
43
|
*/
|
|
41
44
|
isSkippable(waypoint: string): boolean;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve all waypoints in this Plan (order is arbitrary).
|
|
47
|
+
*
|
|
48
|
+
* @returns {string[]} List of waypoints
|
|
49
|
+
*/
|
|
50
|
+
getWaypoints(): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Determine if the given waypoint exists in this Plan.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} waypoint Waypoint to search for
|
|
55
|
+
* @returns {boolean} Result
|
|
56
|
+
*/
|
|
57
|
+
containsWaypoint(waypoint: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Get all route information.
|
|
60
|
+
*
|
|
61
|
+
* @returns {PlanRoute[]} Routes
|
|
62
|
+
*/
|
|
63
|
+
getRoutes(): PlanRoute[];
|
|
64
|
+
/**
|
|
65
|
+
* Get the condition function for the given parameters.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} src Source waypoint
|
|
68
|
+
* @param {string} tgt Target waypoint
|
|
69
|
+
* @param {string} name Route name
|
|
70
|
+
* @returns {PlanRouteCondition} Route condition function
|
|
71
|
+
*/
|
|
72
|
+
getRouteCondition(src: string, tgt: string, name: string): PlanRouteCondition;
|
|
46
73
|
/**
|
|
47
74
|
* Return all outward routes (out-edges) from the given waypoint, to the
|
|
48
75
|
* optional target waypoint.
|
|
49
76
|
*
|
|
50
77
|
* @param {string} src Source waypoint.
|
|
51
|
-
* @param {string} tgt Target waypoint
|
|
52
|
-
* @returns {
|
|
78
|
+
* @param {string} [tgt] Target waypoint.
|
|
79
|
+
* @returns {PlanRoute[]} Route objects found.
|
|
53
80
|
*/
|
|
54
|
-
getOutwardRoutes(src: string, tgt?: string):
|
|
81
|
+
getOutwardRoutes(src: string, tgt?: string | undefined): PlanRoute[];
|
|
55
82
|
/**
|
|
56
83
|
* Return all outward routes (out-edges) from the given waypoint, to the
|
|
57
84
|
* optional target waypoint, matching the "prev" name.
|
|
58
85
|
*
|
|
59
86
|
* @param {string} src Source waypoint.
|
|
60
|
-
* @param {string} tgt Target waypoint
|
|
61
|
-
* @returns {
|
|
87
|
+
* @param {string} [tgt] Target waypoint.
|
|
88
|
+
* @returns {PlanRoute[]} Route objects found.
|
|
62
89
|
*/
|
|
63
|
-
getPrevOutwardRoutes(src: string, tgt?: string):
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
90
|
+
getPrevOutwardRoutes(src: string, tgt?: string | undefined): PlanRoute[];
|
|
91
|
+
/**
|
|
92
|
+
* Add a sequence of waypoints that will follow on from each other, with no
|
|
93
|
+
* routing logic between them.
|
|
94
|
+
*
|
|
95
|
+
* @param {...string} waypoints Waypoints to add
|
|
96
|
+
* @returns {void}
|
|
97
|
+
*/
|
|
98
|
+
addSequence(...waypoints: string[]): void;
|
|
99
|
+
/**
|
|
100
|
+
* Create a new directed route between two waypoints, labelled as "next".
|
|
101
|
+
*
|
|
102
|
+
* @param {string} src Source waypoint
|
|
103
|
+
* @param {string} tgt Target waypoint
|
|
104
|
+
* @param {PlanRouteCondition} follow Route condition function
|
|
105
|
+
* @returns {Plan} Chain
|
|
106
|
+
*/
|
|
107
|
+
setNextRoute(src: string, tgt: string, follow: PlanRouteCondition): Plan;
|
|
108
|
+
/**
|
|
109
|
+
* Create a new directed route between two waypoints, labelled as "prev".
|
|
110
|
+
*
|
|
111
|
+
* @param {string} src Source waypoint
|
|
112
|
+
* @param {string} tgt Target waypoint
|
|
113
|
+
* @param {PlanRouteCondition} follow Route condition function
|
|
114
|
+
* @returns {Plan} Chain
|
|
115
|
+
*/
|
|
116
|
+
setPrevRoute(src: string, tgt: string, follow: PlanRouteCondition): Plan;
|
|
67
117
|
/**
|
|
68
118
|
* Adds both a "next" and "prev" route between the two waypoints.
|
|
69
119
|
*
|
|
70
|
-
* By default, the "prev" route will use the same "follow"
|
|
71
|
-
* route. This makes sense in that in order to get the target, the
|
|
72
|
-
*
|
|
73
|
-
* to be true.
|
|
120
|
+
* By default, the "prev" route will use the same "follow" condition as the
|
|
121
|
+
* "next" route. This makes sense in that in order to get to the target, the
|
|
122
|
+
* condition must be true, and so to reverse the direction we also need that
|
|
123
|
+
* same condition to be true.
|
|
74
124
|
*
|
|
75
|
-
* However, if the condition function uses the `source`/`target`
|
|
125
|
+
* However, if the condition function uses the `source`/`target` property
|
|
76
126
|
* of the route in some way, then we must reverse these before passing to the
|
|
77
127
|
* condition on the "prev" route because `source` in the condition will almost
|
|
78
128
|
* certainly be referring to the source of the "next" route.
|
|
@@ -82,11 +132,11 @@ export default class Plan {
|
|
|
82
132
|
*
|
|
83
133
|
* @param {string} src Source waypoint.
|
|
84
134
|
* @param {string} tgt Target waypoint.
|
|
85
|
-
* @param {
|
|
86
|
-
* @param {
|
|
87
|
-
* @returns {Plan}
|
|
135
|
+
* @param {PlanRouteCondition} [followNext] Follow test function.
|
|
136
|
+
* @param {PlanRouteCondition} [followPrev] Follow test function.
|
|
137
|
+
* @returns {Plan} Chain
|
|
88
138
|
*/
|
|
89
|
-
setRoute(src: string, tgt: string, followNext?:
|
|
139
|
+
setRoute(src: string, tgt: string, followNext?: import("../casa").PlanRouteCondition | undefined, followPrev?: import("../casa").PlanRouteCondition | undefined): Plan;
|
|
90
140
|
/**
|
|
91
141
|
* Create a named route between two waypoints, and give that route a function
|
|
92
142
|
* that determine whether it should be followed during traversal operations.
|
|
@@ -103,22 +153,38 @@ export default class Plan {
|
|
|
103
153
|
* @param {string} src Source waypoint.
|
|
104
154
|
* @param {string} tgt Target waypoint.
|
|
105
155
|
* @param {string} name Name of the route (must be unique for this waypoint pairing).
|
|
106
|
-
* @param {
|
|
156
|
+
* @param {PlanRouteCondition} follow Test function to determine if route can be followed.
|
|
107
157
|
* @returns {Plan} Chain
|
|
108
158
|
* @throws {Error} If attempting to create a "next" route from an exit node
|
|
109
159
|
*/
|
|
110
|
-
setNamedRoute(src: string, tgt: string, name: string, follow:
|
|
160
|
+
setNamedRoute(src: string, tgt: string, name: string, follow: PlanRouteCondition): Plan;
|
|
111
161
|
/**
|
|
112
162
|
* This is a convenience method for traversing all "next" routes, and returning
|
|
113
163
|
* the IDs of all waypoints visited along the way.
|
|
114
164
|
*
|
|
115
|
-
* @param {JourneyContext} context Journey Context
|
|
116
|
-
* @param {
|
|
117
|
-
* @returns {
|
|
165
|
+
* @param {JourneyContext} context Journey Context
|
|
166
|
+
* @param {PlanTraverseOptions} options Options
|
|
167
|
+
* @returns {string[]} List of traversed waypoints
|
|
118
168
|
*/
|
|
119
|
-
traverse(context: JourneyContext, options?:
|
|
120
|
-
|
|
121
|
-
|
|
169
|
+
traverse(context: JourneyContext, options?: PlanTraverseOptions): string[];
|
|
170
|
+
/**
|
|
171
|
+
* Traverse the Plan by following all "next" routes, and returning the IDs of
|
|
172
|
+
* all waypoints visited along the way.
|
|
173
|
+
*
|
|
174
|
+
* @param {JourneyContext} context Journey Context
|
|
175
|
+
* @param {PlanTraverseOptions} options Options
|
|
176
|
+
* @returns {PlanRoute[]} List of traversed waypoints
|
|
177
|
+
*/
|
|
178
|
+
traverseNextRoutes(context: JourneyContext, options?: PlanTraverseOptions): PlanRoute[];
|
|
179
|
+
/**
|
|
180
|
+
* Traverse the Plan by following all "prev" routes, and returning the IDs of
|
|
181
|
+
* all waypoints visited along the way.
|
|
182
|
+
*
|
|
183
|
+
* @param {JourneyContext} context Journey Context
|
|
184
|
+
* @param {PlanTraverseOptions} options Options
|
|
185
|
+
* @returns {PlanRoute[]} List of traversed waypoints
|
|
186
|
+
*/
|
|
187
|
+
traversePrevRoutes(context: JourneyContext, options?: PlanTraverseOptions): PlanRoute[];
|
|
122
188
|
/**
|
|
123
189
|
* Traverse through the plan from a particular starting waypoint. This is a
|
|
124
190
|
* non-exhaustive Graph Exploration.
|
|
@@ -129,19 +195,12 @@ export default class Plan {
|
|
|
129
195
|
* If a cyclical set of routes are encountered, traversal will stop after
|
|
130
196
|
* reaching the first repeated waypoint.
|
|
131
197
|
*
|
|
132
|
-
* Options:
|
|
133
|
-
* string startWaypoint = Waypoint from which to start traversal
|
|
134
|
-
* string routeName = Follow routes matching this name (next | prev)
|
|
135
|
-
* Map history = Used to detect loops in traversal (internal use)
|
|
136
|
-
* function stopCondition = Condition that, if true, will stop traversal (useful for performance)
|
|
137
|
-
* function|string arbiter = If mutliple target routes found, this decides which to use (if any)
|
|
138
|
-
*
|
|
139
198
|
* @param {JourneyContext} context Journey context
|
|
140
|
-
* @param {
|
|
141
|
-
* @returns {
|
|
199
|
+
* @param {PlanTraverseOptions} options Options
|
|
200
|
+
* @returns {PlanRoute[]} Routes that were traversed
|
|
142
201
|
* @throws {TypeError} When context is not a JourneyContext
|
|
143
202
|
*/
|
|
144
|
-
traverseRoutes(context: JourneyContext, options?:
|
|
203
|
+
traverseRoutes(context: JourneyContext, options?: PlanTraverseOptions): PlanRoute[];
|
|
145
204
|
/**
|
|
146
205
|
* Get raw graph data structure. This can be used with other libraries to
|
|
147
206
|
* generate graph visualisations, for example.
|
|
@@ -151,4 +210,18 @@ export default class Plan {
|
|
|
151
210
|
getGraphStructure(): Graph;
|
|
152
211
|
#private;
|
|
153
212
|
}
|
|
213
|
+
export type PlanRoute = import('../casa').PlanRoute;
|
|
214
|
+
export type PlanRouteCondition = import('../casa').PlanRouteCondition;
|
|
215
|
+
export type PlanTraverseOptions = import('../casa').PlanTraverseOptions;
|
|
216
|
+
export type PlanArbiter = import('../casa').PlanArbiter;
|
|
217
|
+
export type PlanConstructorOptions = {
|
|
218
|
+
/**
|
|
219
|
+
* Check page validity before conditions
|
|
220
|
+
*/
|
|
221
|
+
validateBeforeRouteCondition?: boolean | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* Arbitration mechanism
|
|
224
|
+
*/
|
|
225
|
+
arbiter?: string | import("../casa").PlanArbiter | undefined;
|
|
226
|
+
};
|
|
154
227
|
import JourneyContext from "./JourneyContext.js";
|