@dwp/govuk-casa 7.0.7 → 7.0.8

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 (101) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/assets/css/casa-ie8.css +1 -0
  3. package/dist/assets/css/casa.css +1 -0
  4. package/dist/casa/css/casa-ie8.css +1 -1
  5. package/dist/casa/css/casa.css +1 -1
  6. package/dist/casa.d.ts +11 -0
  7. package/dist/casa.js +46 -0
  8. package/dist/lib/CasaTemplateLoader.d.ts +29 -0
  9. package/dist/lib/CasaTemplateLoader.js +74 -0
  10. package/dist/lib/JourneyContext.d.ts +297 -0
  11. package/dist/lib/JourneyContext.js +581 -0
  12. package/dist/lib/MutableRouter.d.ts +155 -0
  13. package/dist/lib/MutableRouter.js +277 -0
  14. package/dist/lib/Plan.d.ts +154 -0
  15. package/dist/lib/Plan.js +442 -0
  16. package/dist/lib/ValidationError.d.ts +74 -0
  17. package/dist/lib/ValidationError.js +159 -0
  18. package/dist/lib/ValidatorFactory.d.ts +83 -0
  19. package/dist/lib/ValidatorFactory.js +106 -0
  20. package/dist/lib/configuration-ingestor.d.ts +262 -0
  21. package/dist/lib/configuration-ingestor.js +490 -0
  22. package/dist/lib/configure.d.ts +90 -0
  23. package/dist/lib/configure.js +192 -0
  24. package/dist/lib/dirname.cjs +1 -0
  25. package/dist/lib/dirname.d.cts +2 -0
  26. package/dist/lib/end-session.d.ts +13 -0
  27. package/dist/lib/end-session.js +43 -0
  28. package/dist/lib/field.d.ts +77 -0
  29. package/dist/lib/field.js +255 -0
  30. package/dist/lib/index.d.ts +14 -0
  31. package/dist/lib/index.js +54 -0
  32. package/dist/lib/logger.d.ts +9 -0
  33. package/dist/lib/logger.js +18 -0
  34. package/dist/lib/nunjucks-filters.d.ts +26 -0
  35. package/dist/lib/nunjucks-filters.js +90 -0
  36. package/dist/lib/nunjucks.d.ts +23 -0
  37. package/dist/lib/nunjucks.js +49 -0
  38. package/dist/lib/utils.d.ts +48 -0
  39. package/dist/lib/utils.js +111 -0
  40. package/dist/lib/validators/dateObject.d.ts +4 -0
  41. package/dist/lib/validators/dateObject.js +135 -0
  42. package/dist/lib/validators/email.d.ts +4 -0
  43. package/dist/lib/validators/email.js +46 -0
  44. package/dist/lib/validators/inArray.d.ts +4 -0
  45. package/dist/lib/validators/inArray.js +60 -0
  46. package/dist/lib/validators/index.d.ts +21 -0
  47. package/dist/lib/validators/index.js +47 -0
  48. package/dist/lib/validators/nino.d.ts +4 -0
  49. package/dist/lib/validators/nino.js +46 -0
  50. package/dist/lib/validators/postalAddressObject.d.ts +4 -0
  51. package/dist/lib/validators/postalAddressObject.js +123 -0
  52. package/dist/lib/validators/regex.d.ts +4 -0
  53. package/dist/lib/validators/regex.js +40 -0
  54. package/dist/lib/validators/required.d.ts +4 -0
  55. package/dist/lib/validators/required.js +56 -0
  56. package/dist/lib/validators/strlen.d.ts +4 -0
  57. package/dist/lib/validators/strlen.js +51 -0
  58. package/dist/lib/validators/wordCount.d.ts +5 -0
  59. package/dist/lib/validators/wordCount.js +54 -0
  60. package/dist/lib/waypoint-url.d.ts +23 -0
  61. package/dist/lib/waypoint-url.js +52 -0
  62. package/dist/middleware/body-parser.d.ts +1 -0
  63. package/dist/middleware/body-parser.js +24 -0
  64. package/dist/middleware/csrf.d.ts +1 -0
  65. package/dist/middleware/csrf.js +31 -0
  66. package/dist/middleware/data.d.ts +5 -0
  67. package/dist/middleware/data.js +53 -0
  68. package/dist/middleware/dirname.cjs +1 -0
  69. package/dist/middleware/dirname.d.cts +2 -0
  70. package/dist/middleware/gather-fields.d.ts +6 -0
  71. package/dist/middleware/gather-fields.js +48 -0
  72. package/dist/middleware/i18n.d.ts +4 -0
  73. package/dist/middleware/i18n.js +88 -0
  74. package/dist/middleware/post.d.ts +3 -0
  75. package/dist/middleware/post.js +57 -0
  76. package/dist/middleware/pre.d.ts +3 -0
  77. package/dist/middleware/pre.js +51 -0
  78. package/dist/middleware/progress-journey.d.ts +6 -0
  79. package/dist/middleware/progress-journey.js +80 -0
  80. package/dist/middleware/sanitise-fields.d.ts +5 -0
  81. package/dist/middleware/sanitise-fields.js +53 -0
  82. package/dist/middleware/session.d.ts +11 -0
  83. package/dist/middleware/session.js +121 -0
  84. package/dist/middleware/skip-waypoint.d.ts +5 -0
  85. package/dist/middleware/skip-waypoint.js +43 -0
  86. package/dist/middleware/steer-journey.d.ts +7 -0
  87. package/dist/middleware/steer-journey.js +62 -0
  88. package/dist/middleware/validate-fields.d.ts +7 -0
  89. package/dist/middleware/validate-fields.js +67 -0
  90. package/dist/mjs/esm-wrapper.js +11 -0
  91. package/dist/mjs/package.json +3 -0
  92. package/dist/package.json +3 -0
  93. package/dist/routes/ancillary.d.ts +11 -0
  94. package/dist/routes/ancillary.js +27 -0
  95. package/dist/routes/dirname.cjs +1 -0
  96. package/dist/routes/dirname.d.cts +2 -0
  97. package/dist/routes/journey.d.ts +8 -0
  98. package/dist/routes/journey.js +127 -0
  99. package/dist/routes/static.d.ts +26 -0
  100. package/dist/routes/static.js +68 -0
  101. package/package.json +19 -19
@@ -0,0 +1,155 @@
1
+ export default class MutableRouter {
2
+ /**
3
+ * Seals this router to make it immutable. Returns the ExpressJS router.
4
+ *
5
+ * @returns {Router} ExpressJS Router
6
+ */
7
+ seal(): Router;
8
+ /**
9
+ * Prepend middleware function(s) using the `all()` method.
10
+ *
11
+ * @param {string} path route path
12
+ * @param {...Function} callbacks Middleware functions
13
+ * @returns {void}
14
+ */
15
+ prependAll(path: string, ...callbacks: Function[]): void;
16
+ /**
17
+ * Prepend middleware function(s) using the `get()` method.
18
+ *
19
+ * @param {string} path route path
20
+ * @param {...Function} callbacks Middleware functions
21
+ * @returns {void}
22
+ */
23
+ prependGet(path: string, ...callbacks: Function[]): void;
24
+ /**
25
+ * Prepend middleware function(s) using the `post()` method.
26
+ *
27
+ * @param {string} path route path
28
+ * @param {...Function} callbacks Middleware functions
29
+ * @returns {void}
30
+ */
31
+ prependPost(path: string, ...callbacks: Function[]): void;
32
+ /**
33
+ * Prepend middleware function(s) using the `delete()` method.
34
+ *
35
+ * @param {string} path route path
36
+ * @param {...Function} callbacks Middleware functions
37
+ * @returns {void}
38
+ */
39
+ prependDelete(path: string, ...callbacks: Function[]): void;
40
+ /**
41
+ * Prepend middleware function(s) using the `put()` method.
42
+ *
43
+ * @param {string} path route path
44
+ * @param {...Function} callbacks Middleware functions
45
+ * @returns {void}
46
+ */
47
+ prependPut(path: string, ...callbacks: Function[]): void;
48
+ /**
49
+ * Prepend middleware function(s) using the `use()` method.
50
+ *
51
+ * @param {string} path route path
52
+ * @param {...Function} callbacks Middleware functions
53
+ * @returns {void}
54
+ */
55
+ prependUse(path: string, ...callbacks: Function[]): void;
56
+ /**
57
+ * Replace middleware function(s) that were mounted using the `all()` method.
58
+ *
59
+ * @param {string} path route path
60
+ * @param {...Function} callbacks Middleware functions
61
+ * @returns {void}
62
+ */
63
+ replaceAll(path: string, ...callbacks: Function[]): void;
64
+ /**
65
+ * Replace middleware function(s) that were mounted using the `get()` method.
66
+ *
67
+ * @param {string} path route path
68
+ * @param {...Function} callbacks Middleware functions
69
+ * @returns {void}
70
+ */
71
+ replaceGet(path: string, ...callbacks: Function[]): void;
72
+ /**
73
+ * Replace middleware function(s) that were mounted using the `post()` method.
74
+ *
75
+ * @param {string} path route path
76
+ * @param {...Function} callbacks Middleware functions
77
+ * @returns {void}
78
+ */
79
+ replacePost(path: string, ...callbacks: Function[]): void;
80
+ /**
81
+ * Replace middleware function(s) that were mounted using the `delete()` method.
82
+ *
83
+ * @param {string} path route path
84
+ * @param {...Function} callbacks Middleware functions
85
+ * @returns {void}
86
+ */
87
+ replaceDelete(path: string, ...callbacks: Function[]): void;
88
+ /**
89
+ * Replace middleware function(s) that were mounted using the `put()` method.
90
+ *
91
+ * @param {string} path route path
92
+ * @param {...Function} callbacks Middleware functions
93
+ * @returns {void}
94
+ */
95
+ replacePut(path: string, ...callbacks: Function[]): void;
96
+ /**
97
+ * Replace middleware function(s) that were mounted using the `use()` method.
98
+ *
99
+ * @param {string} path route path
100
+ * @param {...Function} callbacks Middleware functions
101
+ * @returns {void}
102
+ */
103
+ replaceUse(path: string, ...callbacks: Function[]): void;
104
+ /**
105
+ * Append middleware function(s) using the `all()` method.
106
+ *
107
+ * @param {string} path route path
108
+ * @param {...Function} callbacks Middleware functions
109
+ * @returns {void}
110
+ */
111
+ all(path: string, ...callbacks: Function[]): void;
112
+ /**
113
+ * Append middleware function(s) using the `get()` method.
114
+ *
115
+ * @param {string} path route path
116
+ * @param {...Function} callbacks Middleware functions
117
+ * @returns {void}
118
+ */
119
+ get(path: string, ...callbacks: Function[]): void;
120
+ /**
121
+ * Append middleware function(s) using the `post()` method.
122
+ *
123
+ * @param {string} path route path
124
+ * @param {...Function} callbacks Middleware functions
125
+ * @returns {void}
126
+ */
127
+ post(path: string, ...callbacks: Function[]): void;
128
+ /**
129
+ * Append middleware function(s) using the `delete()` method.
130
+ *
131
+ * @param {string} path route path
132
+ * @param {...Function} callbacks Middleware functions
133
+ * @returns {void}
134
+ */
135
+ delete(path: string, ...callbacks: Function[]): void;
136
+ /**
137
+ * Append middleware function(s) using the `put()` method.
138
+ *
139
+ * @param {string} path route path
140
+ * @param {...Function} callbacks Middleware functions
141
+ * @returns {void}
142
+ */
143
+ put(path: string, ...callbacks: Function[]): void;
144
+ /**
145
+ * Append middleware function(s) using the `use()` method.
146
+ *
147
+ * @param {string} path route path
148
+ * @param {...Function} callbacks Middleware functions
149
+ * @returns {void}
150
+ */
151
+ use(path: string, ...callbacks: Function[]): void;
152
+ route(): void;
153
+ #private;
154
+ }
155
+ import { Router } from "express";
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _MutableRouter_instances, _MutableRouter_stack, _MutableRouter_router, _MutableRouter_sealed, _MutableRouter_append, _MutableRouter_prepend, _MutableRouter_replace;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ /* eslint-disable sonarjs/no-duplicate-string,class-methods-use-this */
16
+ const express_1 = require("express");
17
+ class MutableRouter {
18
+ /**
19
+ * Mutable router.
20
+ *
21
+ * @class
22
+ */
23
+ constructor() {
24
+ _MutableRouter_instances.add(this);
25
+ /**
26
+ * @type {Array}
27
+ */
28
+ _MutableRouter_stack.set(this, void 0);
29
+ /**
30
+ * @type {Router}
31
+ */
32
+ _MutableRouter_router.set(this, void 0);
33
+ /**
34
+ * @type {boolean}
35
+ */
36
+ _MutableRouter_sealed.set(this, void 0);
37
+ __classPrivateFieldSet(this, _MutableRouter_router, new express_1.Router(), "f");
38
+ __classPrivateFieldSet(this, _MutableRouter_stack, [], "f");
39
+ __classPrivateFieldSet(this, _MutableRouter_sealed, false, "f");
40
+ }
41
+ /**
42
+ * Seals this router to make it immutable. Returns the ExpressJS router.
43
+ *
44
+ * @returns {Router} ExpressJS Router
45
+ */
46
+ seal() {
47
+ if (__classPrivateFieldGet(this, _MutableRouter_sealed, "f")) {
48
+ return __classPrivateFieldGet(this, _MutableRouter_router, "f");
49
+ }
50
+ __classPrivateFieldGet(this, _MutableRouter_stack, "f").forEach(({ method, args }) => {
51
+ __classPrivateFieldGet(this, _MutableRouter_router, "f")[method].call(__classPrivateFieldGet(this, _MutableRouter_router, "f"), ...args);
52
+ });
53
+ __classPrivateFieldSet(this, _MutableRouter_sealed, true, "f");
54
+ return __classPrivateFieldGet(this, _MutableRouter_router, "f");
55
+ }
56
+ /* ------------------------------------------------------------- prependers */
57
+ /**
58
+ * Prepend middleware function(s) using the `all()` method.
59
+ *
60
+ * @param {string} path route path
61
+ * @param {...Function} callbacks Middleware functions
62
+ * @returns {void}
63
+ */
64
+ prependAll(path, ...callbacks) {
65
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'all', path, ...callbacks);
66
+ }
67
+ /**
68
+ * Prepend middleware function(s) using the `get()` method.
69
+ *
70
+ * @param {string} path route path
71
+ * @param {...Function} callbacks Middleware functions
72
+ * @returns {void}
73
+ */
74
+ prependGet(path, ...callbacks) {
75
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'get', path, ...callbacks);
76
+ }
77
+ /**
78
+ * Prepend middleware function(s) using the `post()` method.
79
+ *
80
+ * @param {string} path route path
81
+ * @param {...Function} callbacks Middleware functions
82
+ * @returns {void}
83
+ */
84
+ prependPost(path, ...callbacks) {
85
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'post', path, ...callbacks);
86
+ }
87
+ /**
88
+ * Prepend middleware function(s) using the `delete()` method.
89
+ *
90
+ * @param {string} path route path
91
+ * @param {...Function} callbacks Middleware functions
92
+ * @returns {void}
93
+ */
94
+ prependDelete(path, ...callbacks) {
95
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'delete', path, ...callbacks);
96
+ }
97
+ /**
98
+ * Prepend middleware function(s) using the `put()` method.
99
+ *
100
+ * @param {string} path route path
101
+ * @param {...Function} callbacks Middleware functions
102
+ * @returns {void}
103
+ */
104
+ prependPut(path, ...callbacks) {
105
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'put', path, ...callbacks);
106
+ }
107
+ /**
108
+ * Prepend middleware function(s) using the `use()` method.
109
+ *
110
+ * @param {string} path route path
111
+ * @param {...Function} callbacks Middleware functions
112
+ * @returns {void}
113
+ */
114
+ prependUse(path, ...callbacks) {
115
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'use', path, ...callbacks);
116
+ }
117
+ /* -------------------------------------------------------------- replacers */
118
+ // TODO: How do we handle multiple routes on the same path?
119
+ /**
120
+ * Replace middleware function(s) that were mounted using the `all()` method.
121
+ *
122
+ * @param {string} path route path
123
+ * @param {...Function} callbacks Middleware functions
124
+ * @returns {void}
125
+ */
126
+ replaceAll(path, ...callbacks) {
127
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'all', path, ...callbacks);
128
+ }
129
+ /**
130
+ * Replace middleware function(s) that were mounted using the `get()` method.
131
+ *
132
+ * @param {string} path route path
133
+ * @param {...Function} callbacks Middleware functions
134
+ * @returns {void}
135
+ */
136
+ replaceGet(path, ...callbacks) {
137
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'get', path, ...callbacks);
138
+ }
139
+ /**
140
+ * Replace middleware function(s) that were mounted using the `post()` method.
141
+ *
142
+ * @param {string} path route path
143
+ * @param {...Function} callbacks Middleware functions
144
+ * @returns {void}
145
+ */
146
+ replacePost(path, ...callbacks) {
147
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'post', path, ...callbacks);
148
+ }
149
+ /**
150
+ * Replace middleware function(s) that were mounted using the `delete()` method.
151
+ *
152
+ * @param {string} path route path
153
+ * @param {...Function} callbacks Middleware functions
154
+ * @returns {void}
155
+ */
156
+ replaceDelete(path, ...callbacks) {
157
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'delete', path, ...callbacks);
158
+ }
159
+ /**
160
+ * Replace middleware function(s) that were mounted using the `put()` method.
161
+ *
162
+ * @param {string} path route path
163
+ * @param {...Function} callbacks Middleware functions
164
+ * @returns {void}
165
+ */
166
+ replacePut(path, ...callbacks) {
167
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'put', path, ...callbacks);
168
+ }
169
+ /**
170
+ * Replace middleware function(s) that were mounted using the `use()` method.
171
+ *
172
+ * @param {string} path route path
173
+ * @param {...Function} callbacks Middleware functions
174
+ * @returns {void}
175
+ */
176
+ replaceUse(path, ...callbacks) {
177
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'use', path, ...callbacks);
178
+ }
179
+ /* ---------------------------------------------- express.Router() wrappers */
180
+ /**
181
+ * Append middleware function(s) using the `all()` method.
182
+ *
183
+ * @param {string} path route path
184
+ * @param {...Function} callbacks Middleware functions
185
+ * @returns {void}
186
+ */
187
+ all(path, ...callbacks) {
188
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'all', path, ...callbacks);
189
+ }
190
+ /**
191
+ * Append middleware function(s) using the `get()` method.
192
+ *
193
+ * @param {string} path route path
194
+ * @param {...Function} callbacks Middleware functions
195
+ * @returns {void}
196
+ */
197
+ get(path, ...callbacks) {
198
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'get', path, ...callbacks);
199
+ }
200
+ /**
201
+ * Append middleware function(s) using the `post()` method.
202
+ *
203
+ * @param {string} path route path
204
+ * @param {...Function} callbacks Middleware functions
205
+ * @returns {void}
206
+ */
207
+ post(path, ...callbacks) {
208
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'post', path, ...callbacks);
209
+ }
210
+ /**
211
+ * Append middleware function(s) using the `delete()` method.
212
+ *
213
+ * @param {string} path route path
214
+ * @param {...Function} callbacks Middleware functions
215
+ * @returns {void}
216
+ */
217
+ delete(path, ...callbacks) {
218
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'delete', path, ...callbacks);
219
+ }
220
+ /**
221
+ * Append middleware function(s) using the `put()` method.
222
+ *
223
+ * @param {string} path route path
224
+ * @param {...Function} callbacks Middleware functions
225
+ * @returns {void}
226
+ */
227
+ put(path, ...callbacks) {
228
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'put', path, ...callbacks);
229
+ }
230
+ /**
231
+ * Append middleware function(s) using the `use()` method.
232
+ *
233
+ * @param {string} path route path
234
+ * @param {...Function} callbacks Middleware functions
235
+ * @returns {void}
236
+ */
237
+ use(path, ...callbacks) {
238
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'use', path, ...callbacks);
239
+ }
240
+ route() {
241
+ throw new Error('route() method is not supported on MutableRouter. Use verb methods for now.');
242
+ }
243
+ }
244
+ exports.default = MutableRouter;
245
+ _MutableRouter_stack = new WeakMap(), _MutableRouter_router = new WeakMap(), _MutableRouter_sealed = new WeakMap(), _MutableRouter_instances = new WeakSet(), _MutableRouter_append = function _MutableRouter_append(method, path, ...callbacks) {
246
+ if (__classPrivateFieldGet(this, _MutableRouter_sealed, "f")) {
247
+ throw new Error('Cannot alter middleware in a sealed mutable router');
248
+ }
249
+ __classPrivateFieldGet(this, _MutableRouter_stack, "f").push({
250
+ method,
251
+ path,
252
+ args: [path, ...callbacks],
253
+ });
254
+ }, _MutableRouter_prepend = function _MutableRouter_prepend(method, path, ...callbacks) {
255
+ if (__classPrivateFieldGet(this, _MutableRouter_sealed, "f")) {
256
+ throw new Error('Cannot alter middleware in a sealed mutable router');
257
+ }
258
+ __classPrivateFieldGet(this, _MutableRouter_stack, "f").splice(0, 0, {
259
+ method,
260
+ path,
261
+ args: [path, ...callbacks],
262
+ });
263
+ }, _MutableRouter_replace = function _MutableRouter_replace(method, path, ...callbacks) {
264
+ if (__classPrivateFieldGet(this, _MutableRouter_sealed, "f")) {
265
+ throw new Error('Cannot alter middleware in a sealed mutable router');
266
+ }
267
+ const finder = (command) => `${command.method}|${command.path}` === `${method}|${path}`;
268
+ const index = __classPrivateFieldGet(this, _MutableRouter_stack, "f").findIndex(finder);
269
+ if (index > -1) {
270
+ __classPrivateFieldGet(this, _MutableRouter_stack, "f").splice(index, 1, {
271
+ method,
272
+ path,
273
+ args: [path, ...callbacks],
274
+ });
275
+ __classPrivateFieldSet(this, _MutableRouter_stack, __classPrivateFieldGet(this, _MutableRouter_stack, "f").filter((command, idx) => idx <= index || !finder(command)), "f");
276
+ }
277
+ };
@@ -0,0 +1,154 @@
1
+ export default class Plan {
2
+ /**
3
+ * Waypoints using the url:// protocol are known as "exit nodes" as they
4
+ * indicate an exit point to another Plan.
5
+ *
6
+ * @param {string} name Waypoint name
7
+ * @returns {boolean} True if the waypoint is a url:// type
8
+ */
9
+ static isExitNode(name: string): boolean;
10
+ /**
11
+ * Create a Plan.
12
+ *
13
+ * @param {object} opts Options
14
+ * @param {boolean} [opts.validateBeforeRouteCondition=true] Check page validity before conditions
15
+ * @param {Function|string} [opts.arbiter=undefined] Arbitration mechanism
16
+ */
17
+ constructor(opts?: {
18
+ validateBeforeRouteCondition?: boolean | undefined;
19
+ arbiter?: string | Function | undefined;
20
+ });
21
+ getOptions(): any;
22
+ /**
23
+ * Retrieve the list of skippable waypoints.
24
+ *
25
+ * @returns {string[]} List of skippable waypoints
26
+ */
27
+ getSkippables(): string[];
28
+ /**
29
+ * Add one or more skippable waypoints.
30
+ *
31
+ * @param {...string} waypoints Waypoints
32
+ * @returns {Plan}{ Chain}
33
+ */
34
+ addSkippables(...waypoints: string[]): Plan;
35
+ /**
36
+ * Check if the user can skip the named waypoint.
37
+ *
38
+ * @param {string} waypoint Waypoint
39
+ * @returns {boolean} True if waypoint can be skipped
40
+ */
41
+ isSkippable(waypoint: string): boolean;
42
+ getWaypoints(): any;
43
+ containsWaypoint(waypoint: any): any;
44
+ getRoutes(): any;
45
+ getRouteCondition(src: any, tgt: any, name: any): any;
46
+ /**
47
+ * Return all outward routes (out-edges) from the given waypoint, to the
48
+ * optional target waypoint.
49
+ *
50
+ * @param {string} src Source waypoint.
51
+ * @param {string} tgt Target waypoint (optional).
52
+ * @returns {Array<object>} Route objects found.
53
+ */
54
+ getOutwardRoutes(src: string, tgt?: string): Array<object>;
55
+ /**
56
+ * Return all outward routes (out-edges) from the given waypoint, to the
57
+ * optional target waypoint, matching the "prev" name.
58
+ *
59
+ * @param {string} src Source waypoint.
60
+ * @param {string} tgt Target waypoint (optional).
61
+ * @returns {Array<object>} Route objects found.
62
+ */
63
+ getPrevOutwardRoutes(src: string, tgt?: string): Array<object>;
64
+ addSequence(...waypoints: any[]): void;
65
+ setNextRoute(src: any, tgt: any, follow: any): Plan;
66
+ setPrevRoute(src: any, tgt: any, follow: any): Plan;
67
+ /**
68
+ * Adds both a "next" and "prev" route between the two waypoints.
69
+ *
70
+ * By default, the "prev" route will use the same "follow" test as the "next"
71
+ * route. This makes sense in that in order to get the target, the test must
72
+ * have been true, and so to reverse the direction we also need that same test
73
+ * to be true.
74
+ *
75
+ * However, if the condition function uses the `source`/`target`
76
+ * of the route in some way, then we must reverse these before passing to the
77
+ * condition on the "prev" route because `source` in the condition will almost
78
+ * certainly be referring to the source of the "next" route.
79
+ *
80
+ * If `tgt` is an egress node, do not create a `prev` route for it, because
81
+ * there's no way back from that point to this Plan.
82
+ *
83
+ * @param {string} src Source waypoint.
84
+ * @param {string} tgt Target waypoint.
85
+ * @param {Function} followNext Follow test function.
86
+ * @param {Function} followPrev Follow test function.
87
+ * @returns {Plan} Self.
88
+ */
89
+ setRoute(src: string, tgt: string, followNext?: Function, followPrev?: Function): Plan;
90
+ /**
91
+ * Create a named route between two waypoints, and give that route a function
92
+ * that determine whether it should be followed during traversal operations.
93
+ * Note that the source waypoint must be in a successful validation state
94
+ * to be considered for traversal, regardless of what the custom function
95
+ * determines.
96
+ *
97
+ * You may also define routes that take the user to any generic URL within the
98
+ * same domain by using the `url://` protocol. These are considered
99
+ * "exit nodes".
100
+ *
101
+ * setNamedRoute("my-waypoint", "url:///some/absolute/url");
102
+ *
103
+ * @param {string} src Source waypoint.
104
+ * @param {string} tgt Target waypoint.
105
+ * @param {string} name Name of the route (must be unique for this waypoint pairing).
106
+ * @param {Function} follow Test function to determine if route can be followed.
107
+ * @returns {Plan} Chain
108
+ * @throws {Error} If attempting to create a "next" route from an exit node
109
+ */
110
+ setNamedRoute(src: string, tgt: string, name: string, follow: Function): Plan;
111
+ /**
112
+ * This is a convenience method for traversing all "next" routes, and returning
113
+ * the IDs of all waypoints visited along the way.
114
+ *
115
+ * @param {JourneyContext} context Journey Context.
116
+ * @param {object} options Options.
117
+ * @returns {Array<string>} List of traversed waypoints.
118
+ */
119
+ traverse(context: JourneyContext, options?: object): Array<string>;
120
+ traverseNextRoutes(context: any, options?: {}): object[];
121
+ traversePrevRoutes(context: any, options?: {}): object[];
122
+ /**
123
+ * Traverse through the plan from a particular starting waypoint. This is a
124
+ * non-exhaustive Graph Exploration.
125
+ *
126
+ * The last route in the list will contain the source of the last waypoint that
127
+ * can be reached, i.e. The waypoint that has no further satisfiable out-edges.
128
+ *
129
+ * If a cyclical set of routes are encountered, traversal will stop after
130
+ * reaching the first repeated waypoint.
131
+ *
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
+ * @param {JourneyContext} context Journey context
140
+ * @param {object} options Options
141
+ * @returns {Array<object>} Routes that were traversed
142
+ * @throws {TypeError} When context is not a JourneyContext
143
+ */
144
+ traverseRoutes(context: JourneyContext, options?: object): Array<object>;
145
+ /**
146
+ * Get raw graph data structure. This can be used with other libraries to
147
+ * generate graph visualisations, for example.
148
+ *
149
+ * @returns {Graph} Graph data structure.
150
+ */
151
+ getGraphStructure(): Graph;
152
+ #private;
153
+ }
154
+ import JourneyContext from "./JourneyContext.js";