@dwp/govuk-casa 7.0.6 → 8.0.0-alpha1

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 (219) hide show
  1. package/README.md +22 -17
  2. package/dist/{casa → assets}/css/casa-ie8.css +1 -1
  3. package/dist/assets/css/casa.css +1 -0
  4. package/dist/casa.d.ts +10 -0
  5. package/dist/casa.js +44 -0
  6. package/dist/lib/CasaTemplateLoader.d.ts +19 -0
  7. package/dist/lib/CasaTemplateLoader.js +57 -0
  8. package/dist/lib/JourneyContext.d.ts +255 -0
  9. package/dist/lib/JourneyContext.js +681 -0
  10. package/dist/lib/MutableRouter.d.ts +155 -0
  11. package/dist/lib/MutableRouter.js +272 -0
  12. package/dist/lib/Plan.d.ts +119 -0
  13. package/dist/lib/Plan.js +382 -0
  14. package/dist/lib/ValidationError.d.ts +70 -0
  15. package/dist/lib/ValidationError.js +156 -0
  16. package/dist/lib/ValidatorFactory.d.ts +24 -0
  17. package/dist/lib/ValidatorFactory.js +87 -0
  18. package/dist/lib/configure.d.ts +205 -0
  19. package/dist/lib/configure.js +215 -0
  20. package/dist/lib/dirname.cjs +1 -0
  21. package/dist/lib/end-session.d.ts +12 -0
  22. package/dist/lib/end-session.js +24 -0
  23. package/dist/lib/field.d.ts +79 -0
  24. package/dist/lib/field.js +223 -0
  25. package/dist/lib/logger.d.ts +8 -0
  26. package/dist/lib/logger.js +19 -0
  27. package/dist/lib/nunjucks-filters.d.ts +26 -0
  28. package/dist/lib/nunjucks-filters.js +112 -0
  29. package/dist/lib/nunjucks.d.ts +22 -0
  30. package/dist/lib/nunjucks.js +49 -0
  31. package/dist/lib/utils.d.ts +22 -0
  32. package/dist/lib/utils.js +44 -0
  33. package/dist/lib/validators/dateObject.d.ts +4 -0
  34. package/dist/lib/validators/dateObject.js +135 -0
  35. package/dist/lib/validators/email.d.ts +4 -0
  36. package/dist/lib/validators/email.js +46 -0
  37. package/dist/lib/validators/inArray.d.ts +4 -0
  38. package/dist/lib/validators/inArray.js +60 -0
  39. package/dist/lib/validators/index.d.ts +21 -0
  40. package/dist/lib/validators/index.js +47 -0
  41. package/dist/lib/validators/nino.d.ts +4 -0
  42. package/dist/lib/validators/nino.js +46 -0
  43. package/dist/lib/validators/postalAddressObject.d.ts +4 -0
  44. package/dist/lib/validators/postalAddressObject.js +123 -0
  45. package/dist/lib/validators/regex.d.ts +4 -0
  46. package/dist/lib/validators/regex.js +40 -0
  47. package/dist/lib/validators/required.d.ts +4 -0
  48. package/dist/lib/validators/required.js +56 -0
  49. package/dist/lib/validators/strlen.d.ts +4 -0
  50. package/dist/lib/validators/strlen.js +51 -0
  51. package/dist/lib/validators/wordCount.d.ts +5 -0
  52. package/dist/lib/validators/wordCount.js +54 -0
  53. package/dist/lib/waypoint-url.d.ts +17 -0
  54. package/dist/lib/waypoint-url.js +46 -0
  55. package/dist/middleware/body-parser.d.ts +1 -0
  56. package/dist/middleware/body-parser.js +24 -0
  57. package/dist/middleware/csrf.d.ts +1 -0
  58. package/dist/middleware/csrf.js +31 -0
  59. package/dist/middleware/data.d.ts +6 -0
  60. package/dist/middleware/data.js +53 -0
  61. package/dist/middleware/dirname.cjs +1 -0
  62. package/dist/middleware/gather-fields.d.ts +5 -0
  63. package/dist/middleware/gather-fields.js +39 -0
  64. package/dist/middleware/i18n.d.ts +4 -0
  65. package/dist/middleware/i18n.js +87 -0
  66. package/dist/middleware/post.d.ts +1 -0
  67. package/dist/middleware/post.js +42 -0
  68. package/dist/middleware/pre.d.ts +3 -0
  69. package/dist/middleware/pre.js +38 -0
  70. package/dist/middleware/progress-journey.d.ts +6 -0
  71. package/dist/middleware/progress-journey.js +82 -0
  72. package/dist/middleware/sanitise-fields.d.ts +5 -0
  73. package/dist/middleware/sanitise-fields.js +48 -0
  74. package/dist/middleware/session.d.ts +10 -0
  75. package/dist/middleware/session.js +115 -0
  76. package/dist/middleware/skip-waypoint.d.ts +5 -0
  77. package/dist/middleware/skip-waypoint.js +40 -0
  78. package/dist/middleware/steer-journey.d.ts +6 -0
  79. package/dist/middleware/steer-journey.js +44 -0
  80. package/dist/middleware/validate-fields.d.ts +7 -0
  81. package/dist/middleware/validate-fields.js +76 -0
  82. package/dist/mjs/esm-wrapper.js +10 -0
  83. package/dist/mjs/package.json +3 -0
  84. package/dist/package.json +3 -0
  85. package/dist/routes/ancillary.d.ts +4 -0
  86. package/dist/routes/ancillary.js +19 -0
  87. package/dist/routes/dirname.cjs +1 -0
  88. package/dist/routes/journey.d.ts +8 -0
  89. package/dist/routes/journey.js +130 -0
  90. package/dist/routes/static.d.ts +26 -0
  91. package/dist/routes/static.js +67 -0
  92. package/package.json +45 -86
  93. package/views/casa/components/checkboxes/template.njk +4 -1
  94. package/views/casa/components/date-input/template.njk +3 -3
  95. package/views/casa/components/journey-form/README.md +3 -1
  96. package/views/casa/components/journey-form/template.njk +1 -1
  97. package/views/casa/components/postal-address-object/template.njk +5 -5
  98. package/views/casa/components/radios/template.njk +1 -1
  99. package/views/casa/layouts/journey.njk +26 -9
  100. package/views/casa/layouts/main.njk +6 -19
  101. package/views/casa/partials/scripts.njk +8 -3
  102. package/views/casa/partials/styles.njk +2 -2
  103. package/casa.js +0 -208
  104. package/definitions/review-page.js +0 -60
  105. package/dist/casa/css/casa.css +0 -1
  106. package/dist/casa/js/casa.js +0 -1
  107. package/index.d.ts +0 -121
  108. package/lib/ConfigIngestor.js +0 -588
  109. package/lib/GatherModifier.js +0 -14
  110. package/lib/I18n.js +0 -160
  111. package/lib/JourneyContext.d.ts +0 -97
  112. package/lib/JourneyContext.js +0 -552
  113. package/lib/JourneyMap.js +0 -233
  114. package/lib/JourneyRoad.js +0 -330
  115. package/lib/Logger.js +0 -59
  116. package/lib/PageDictionary.d.ts +0 -11
  117. package/lib/PageDirectory.js +0 -77
  118. package/lib/Plan.js +0 -423
  119. package/lib/RoadConverter.js +0 -153
  120. package/lib/UserJourney.js +0 -8
  121. package/lib/Util.js +0 -227
  122. package/lib/Validation.js +0 -20
  123. package/lib/bootstrap/end-session.js +0 -44
  124. package/lib/bootstrap/load-definitions.js +0 -64
  125. package/lib/commonBodyParser.js +0 -15
  126. package/lib/enums.js +0 -6
  127. package/lib/gather-modifiers/index.js +0 -7
  128. package/lib/gather-modifiers/trimPostalAddressObject.js +0 -75
  129. package/lib/gather-modifiers/trimWhitespace.js +0 -16
  130. package/lib/utils/createGetRequest.d.ts +0 -5
  131. package/lib/utils/createGetRequest.js +0 -59
  132. package/lib/utils/index.js +0 -11
  133. package/lib/utils/parseRequest.d.ts +0 -5
  134. package/lib/utils/parseRequest.js +0 -72
  135. package/lib/utils/sanitise.js +0 -74
  136. package/lib/utils/validate.js +0 -32
  137. package/lib/validation/ArrayObjectField.js +0 -49
  138. package/lib/validation/ObjectField.js +0 -53
  139. package/lib/validation/SimpleField.d.ts +0 -11
  140. package/lib/validation/SimpleField.js +0 -46
  141. package/lib/validation/ValidationError.d.ts +0 -14
  142. package/lib/validation/ValidationError.js +0 -170
  143. package/lib/validation/ValidatorFactory.d.ts +0 -32
  144. package/lib/validation/ValidatorFactory.js +0 -91
  145. package/lib/validation/index.js +0 -22
  146. package/lib/validation/processor/flattenErrorArray.js +0 -24
  147. package/lib/validation/processor/queue.js +0 -214
  148. package/lib/validation/processor.js +0 -84
  149. package/lib/validation/rules/README.md +0 -3
  150. package/lib/validation/rules/ValidationRules.d.ts +0 -22
  151. package/lib/validation/rules/dateObject.js +0 -156
  152. package/lib/validation/rules/email.js +0 -44
  153. package/lib/validation/rules/inArray.js +0 -61
  154. package/lib/validation/rules/index.js +0 -23
  155. package/lib/validation/rules/nino.js +0 -48
  156. package/lib/validation/rules/optional.js +0 -14
  157. package/lib/validation/rules/postalAddressObject.js +0 -142
  158. package/lib/validation/rules/regex.js +0 -39
  159. package/lib/validation/rules/required.js +0 -57
  160. package/lib/validation/rules/strlen.js +0 -57
  161. package/lib/validation/rules/wordCount.js +0 -61
  162. package/lib/view-filters/formatDateObject.js +0 -35
  163. package/lib/view-filters/includes.js +0 -10
  164. package/lib/view-filters/index.js +0 -23
  165. package/lib/view-filters/mergeObjectsDeep.js +0 -21
  166. package/lib/view-filters/renderAsAttributes.js +0 -33
  167. package/middleware/errors/404.js +0 -12
  168. package/middleware/errors/catch-all.js +0 -27
  169. package/middleware/errors/index.js +0 -9
  170. package/middleware/headers/config-defaults.js +0 -57
  171. package/middleware/headers/headers.js +0 -40
  172. package/middleware/headers/index.js +0 -9
  173. package/middleware/i18n/i18n.js +0 -56
  174. package/middleware/i18n/index.js +0 -16
  175. package/middleware/index.js +0 -55
  176. package/middleware/mount/index.js +0 -9
  177. package/middleware/mount/mount.js +0 -10
  178. package/middleware/nunjucks/environment.js +0 -57
  179. package/middleware/nunjucks/index.js +0 -8
  180. package/middleware/page/csrf.js +0 -37
  181. package/middleware/page/edit-mode.js +0 -52
  182. package/middleware/page/gather.js +0 -75
  183. package/middleware/page/index.js +0 -103
  184. package/middleware/page/journey-continue.js +0 -157
  185. package/middleware/page/journey-rails.js +0 -102
  186. package/middleware/page/prepare-request.js +0 -77
  187. package/middleware/page/render.js +0 -75
  188. package/middleware/page/skip.js +0 -72
  189. package/middleware/page/utils.js +0 -206
  190. package/middleware/page/validate.js +0 -67
  191. package/middleware/session/expiry.js +0 -95
  192. package/middleware/session/genid.js +0 -18
  193. package/middleware/session/index.js +0 -18
  194. package/middleware/session/init.js +0 -25
  195. package/middleware/session/seed.js +0 -50
  196. package/middleware/session/timeout.js +0 -5
  197. package/middleware/static/asset-versions.js +0 -23
  198. package/middleware/static/index.js +0 -104
  199. package/middleware/static/prepare-assets.js +0 -51
  200. package/middleware/static/serve-assets.js +0 -58
  201. package/middleware/variables/index.js +0 -12
  202. package/middleware/variables/variables.js +0 -35
  203. package/src/browserconfig.xml +0 -5
  204. package/src/js/casa.js +0 -132
  205. package/src/scss/_casaElements.scss +0 -11
  206. package/src/scss/_casaGovukTemplateJinjaPolyfill.scss +0 -39
  207. package/src/scss/_casaMountUrl.scss +0 -8
  208. package/src/scss/casa-ie8.scss +0 -3
  209. package/src/scss/casa.scss +0 -14
  210. package/test/unit/templates/README.md +0 -5
  211. package/test/utils/BaseTestWaypoint.js +0 -106
  212. package/test/utils/concatWaypoints.js +0 -26
  213. package/test/utils/index.js +0 -6
  214. package/test/utils/testTraversal.js +0 -90
  215. package/views/casa/partials/cookie_message.njk +0 -3
  216. package/views/casa/partials/phase_banner_alpha.njk +0 -8
  217. package/views/casa/partials/phase_banner_beta.njk +0 -8
  218. package/views/casa/review/page-block.njk +0 -8
  219. package/views/casa/review/review.njk +0 -47
@@ -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}
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,272 @@
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
+ const express_1 = require("express");
16
+ class MutableRouter {
17
+ /**
18
+ * @class
19
+ */
20
+ constructor() {
21
+ _MutableRouter_instances.add(this);
22
+ /**
23
+ * @type {array}
24
+ */
25
+ _MutableRouter_stack.set(this, void 0);
26
+ /**
27
+ * @type {Router}
28
+ */
29
+ _MutableRouter_router.set(this, void 0);
30
+ /**
31
+ * @type {boolean}
32
+ */
33
+ _MutableRouter_sealed.set(this, void 0);
34
+ __classPrivateFieldSet(this, _MutableRouter_router, new express_1.Router(), "f");
35
+ __classPrivateFieldSet(this, _MutableRouter_stack, [], "f");
36
+ __classPrivateFieldSet(this, _MutableRouter_sealed, false, "f");
37
+ }
38
+ /**
39
+ * Seals this router to make it immutable. Returns the ExpressJS router.
40
+ *
41
+ * @returns {Router}
42
+ */
43
+ seal() {
44
+ if (__classPrivateFieldGet(this, _MutableRouter_sealed, "f")) {
45
+ return __classPrivateFieldGet(this, _MutableRouter_router, "f");
46
+ }
47
+ __classPrivateFieldGet(this, _MutableRouter_stack, "f").forEach(({ method, args }) => {
48
+ __classPrivateFieldGet(this, _MutableRouter_router, "f")[method].call(__classPrivateFieldGet(this, _MutableRouter_router, "f"), ...args);
49
+ });
50
+ __classPrivateFieldSet(this, _MutableRouter_sealed, true, "f");
51
+ return __classPrivateFieldGet(this, _MutableRouter_router, "f");
52
+ }
53
+ /* ------------------------------------------------------------- prependers */
54
+ /**
55
+ * Prepend middleware function(s) using the `all()` method.
56
+ *
57
+ * @param {string} path route path
58
+ * @param {...function} callbacks Middleware functions
59
+ * @returns {void}
60
+ */
61
+ prependAll(path, ...callbacks) {
62
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'all', path, ...callbacks);
63
+ }
64
+ /**
65
+ * Prepend middleware function(s) using the `get()` method.
66
+ *
67
+ * @param {string} path route path
68
+ * @param {...function} callbacks Middleware functions
69
+ * @returns {void}
70
+ */
71
+ prependGet(path, ...callbacks) {
72
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'get', path, ...callbacks);
73
+ }
74
+ /**
75
+ * Prepend middleware function(s) using the `post()` method.
76
+ *
77
+ * @param {string} path route path
78
+ * @param {...function} callbacks Middleware functions
79
+ * @returns {void}
80
+ */
81
+ prependPost(path, ...callbacks) {
82
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'post', path, ...callbacks);
83
+ }
84
+ /**
85
+ * Prepend middleware function(s) using the `delete()` method.
86
+ *
87
+ * @param {string} path route path
88
+ * @param {...function} callbacks Middleware functions
89
+ * @returns {void}
90
+ */
91
+ prependDelete(path, ...callbacks) {
92
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'delete', path, ...callbacks);
93
+ }
94
+ /**
95
+ * Prepend middleware function(s) using the `put()` method.
96
+ *
97
+ * @param {string} path route path
98
+ * @param {...function} callbacks Middleware functions
99
+ * @returns {void}
100
+ */
101
+ prependPut(path, ...callbacks) {
102
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'put', path, ...callbacks);
103
+ }
104
+ /**
105
+ * Prepend middleware function(s) using the `use()` method.
106
+ *
107
+ * @param {string} path route path
108
+ * @param {...function} callbacks Middleware functions
109
+ * @returns {void}
110
+ */
111
+ prependUse(path, ...callbacks) {
112
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_prepend).call(this, 'use', path, ...callbacks);
113
+ }
114
+ /* -------------------------------------------------------------- replacers */
115
+ // TODO: How do we handle multiple routes on the same path?
116
+ /**
117
+ * Replace middleware function(s) that were mounted using the `all()` method.
118
+ *
119
+ * @param {string} path route path
120
+ * @param {...function} callbacks Middleware functions
121
+ * @returns {void}
122
+ */
123
+ replaceAll(path, ...callbacks) {
124
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'all', path, ...callbacks);
125
+ }
126
+ /**
127
+ * Replace middleware function(s) that were mounted using the `get()` method.
128
+ *
129
+ * @param {string} path route path
130
+ * @param {...function} callbacks Middleware functions
131
+ * @returns {void}
132
+ */
133
+ replaceGet(path, ...callbacks) {
134
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'get', path, ...callbacks);
135
+ }
136
+ /**
137
+ * Replace middleware function(s) that were mounted using the `post()` method.
138
+ *
139
+ * @param {string} path route path
140
+ * @param {...function} callbacks Middleware functions
141
+ * @returns {void}
142
+ */
143
+ replacePost(path, ...callbacks) {
144
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'post', path, ...callbacks);
145
+ }
146
+ /**
147
+ * Replace middleware function(s) that were mounted using the `delete()` method.
148
+ *
149
+ * @param {string} path route path
150
+ * @param {...function} callbacks Middleware functions
151
+ * @returns {void}
152
+ */
153
+ replaceDelete(path, ...callbacks) {
154
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'delete', path, ...callbacks);
155
+ }
156
+ /**
157
+ * Replace middleware function(s) that were mounted using the `put()` method.
158
+ *
159
+ * @param {string} path route path
160
+ * @param {...function} callbacks Middleware functions
161
+ * @returns {void}
162
+ */
163
+ replacePut(path, ...callbacks) {
164
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'put', path, ...callbacks);
165
+ }
166
+ /**
167
+ * Replace middleware function(s) that were mounted using the `use()` method.
168
+ *
169
+ * @param {string} path route path
170
+ * @param {...function} callbacks Middleware functions
171
+ * @returns {void}
172
+ */
173
+ replaceUse(path, ...callbacks) {
174
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_replace).call(this, 'use', path, ...callbacks);
175
+ }
176
+ /* ---------------------------------------------- express.Router() wrappers */
177
+ /**
178
+ * Append middleware function(s) using the `all()` method.
179
+ *
180
+ * @param {string} path route path
181
+ * @param {...function} callbacks Middleware functions
182
+ * @returns {void}
183
+ */
184
+ all(path, ...callbacks) {
185
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'all', path, ...callbacks);
186
+ }
187
+ /**
188
+ * Append middleware function(s) using the `get()` method.
189
+ *
190
+ * @param {string} path route path
191
+ * @param {...function} callbacks Middleware functions
192
+ * @returns {void}
193
+ */
194
+ get(path, ...callbacks) {
195
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'get', path, ...callbacks);
196
+ }
197
+ /**
198
+ * Append middleware function(s) using the `post()` method.
199
+ *
200
+ * @param {string} path route path
201
+ * @param {...function} callbacks Middleware functions
202
+ * @returns {void}
203
+ */
204
+ post(path, ...callbacks) {
205
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'post', path, ...callbacks);
206
+ }
207
+ /**
208
+ * Append middleware function(s) using the `delete()` method.
209
+ *
210
+ * @param {string} path route path
211
+ * @param {...function} callbacks Middleware functions
212
+ * @returns {void}
213
+ */
214
+ delete(path, ...callbacks) {
215
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'delete', path, ...callbacks);
216
+ }
217
+ /**
218
+ * Append middleware function(s) using the `put()` method.
219
+ *
220
+ * @param {string} path route path
221
+ * @param {...function} callbacks Middleware functions
222
+ * @returns {void}
223
+ */
224
+ put(path, ...callbacks) {
225
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'put', path, ...callbacks);
226
+ }
227
+ /**
228
+ * Append middleware function(s) using the `use()` method.
229
+ *
230
+ * @param {string} path route path
231
+ * @param {...function} callbacks Middleware functions
232
+ * @returns {void}
233
+ */
234
+ use(path, ...callbacks) {
235
+ __classPrivateFieldGet(this, _MutableRouter_instances, "m", _MutableRouter_append).call(this, 'use', path, ...callbacks);
236
+ }
237
+ route() {
238
+ throw new Error('The route() method is not currently supported on the MutableRouter class. Please use the verb methods for now.');
239
+ }
240
+ }
241
+ exports.default = MutableRouter;
242
+ _MutableRouter_stack = new WeakMap(), _MutableRouter_router = new WeakMap(), _MutableRouter_sealed = new WeakMap(), _MutableRouter_instances = new WeakSet(), _MutableRouter_append = function _MutableRouter_append(method, path, ...callbacks) {
243
+ if (__classPrivateFieldGet(this, _MutableRouter_sealed, "f")) {
244
+ throw new Error('Cannot alter middleware in a sealed mutable router');
245
+ }
246
+ __classPrivateFieldGet(this, _MutableRouter_stack, "f").push({
247
+ method,
248
+ path,
249
+ args: [path, ...callbacks],
250
+ });
251
+ }, _MutableRouter_prepend = function _MutableRouter_prepend(method, path, ...callbacks) {
252
+ if (__classPrivateFieldGet(this, _MutableRouter_sealed, "f")) {
253
+ throw new Error('Cannot alter middleware in a sealed mutable router');
254
+ }
255
+ __classPrivateFieldGet(this, _MutableRouter_stack, "f").splice(0, 0, {
256
+ method,
257
+ path,
258
+ args: [path, ...callbacks],
259
+ });
260
+ }, _MutableRouter_replace = function _MutableRouter_replace(method, path, ...callbacks) {
261
+ if (__classPrivateFieldGet(this, _MutableRouter_sealed, "f")) {
262
+ throw new Error('Cannot alter middleware in a sealed mutable router');
263
+ }
264
+ const index = __classPrivateFieldGet(this, _MutableRouter_stack, "f").findIndex((command) => `${command.method}|${command.path}` === `${method}|${path}`);
265
+ if (index > -1) {
266
+ __classPrivateFieldGet(this, _MutableRouter_stack, "f").splice(index, 1, {
267
+ method,
268
+ path,
269
+ args: [path, ...callbacks],
270
+ });
271
+ }
272
+ };
@@ -0,0 +1,119 @@
1
+ export default class Plan {
2
+ static isExitNode(name: any): boolean;
3
+ /**
4
+ * @param {object} opts
5
+ */
6
+ constructor(opts?: object);
7
+ getOptions(): any;
8
+ getWaypoints(): any;
9
+ containsWaypoint(waypoint: any): any;
10
+ getRoutes(): any;
11
+ getRouteCondition(src: any, tgt: any, name: any): any;
12
+ /**
13
+ * Return all outward routes (out-edges) from the given waypoint, to the
14
+ * optional target waypoint.
15
+ *
16
+ * @param {string} src Source waypoint.
17
+ * @param {string} tgt Target waypoint (optional).
18
+ * @returns {Array<object>} Route objects found.
19
+ */
20
+ getOutwardRoutes(src: string, tgt?: string): Array<object>;
21
+ /**
22
+ * Return all outward routes (out-edges) from the given waypoint, to the
23
+ * optional target waypoint, matching the "prev" name.
24
+ *
25
+ * @param {string} src Source waypoint.
26
+ * @param {string} tgt Target waypoint (optional).
27
+ * @returns {Array<object>} Route objects found.
28
+ */
29
+ getPrevOutwardRoutes(src: string, tgt?: string): Array<object>;
30
+ addSequence(...waypoints: any[]): void;
31
+ setNextRoute(src: any, tgt: any, follow: any): Plan;
32
+ setPrevRoute(src: any, tgt: any, follow: any): Plan;
33
+ /**
34
+ * Adds both a "next" and "prev" route between the two waypoints.
35
+ *
36
+ * By default, the "prev" route will use the same "follow" test as the "next"
37
+ * route. This makes sense in that in order to get the target, the test must
38
+ * have been true, and so to reverse the direction we also need that same test
39
+ * to be true.
40
+ *
41
+ * However, if the condition function uses the `source`/`target`
42
+ * of the route in some way, then we must reverse these before passing to the
43
+ * condition on the "prev" route because `source` in the condition will almost
44
+ * certainly be referring to the source of the "next" route.
45
+ *
46
+ * If `tgt` is an egress node, do not create a `prev` route for it, because
47
+ * there's no way back from that point to this Plan.
48
+ *
49
+ * @param {string} src Source waypoint.
50
+ * @param {string} tgt Target waypoint.
51
+ * @param {Function} followNext Follow test function.
52
+ * @param {Function} followPrev Follow test function.
53
+ * @returns {Plan} Self.
54
+ */
55
+ setRoute(src: string, tgt: string, followNext?: Function, followPrev?: Function): Plan;
56
+ /**
57
+ * Create a named route between two waypoints, and give that route a function
58
+ * that determine whether it should be followed during traversal operations.
59
+ * Note that the source waypoint must be in a successful validation state
60
+ * to be considered for traversal, regardless of what the custom function
61
+ * determines.
62
+ *
63
+ * You may also define routes that take the user to any generic URL within the
64
+ * same domain by using the `url://` protocol. These are considered
65
+ * "exit nodes".
66
+ *
67
+ * setNamedRoute("my-waypoint", "url:///some/absolute/url");
68
+ *
69
+ * @param {string} src Source waypoint.
70
+ * @param {string} tgt Target waypoint.
71
+ * @param {string} name Name of the route (must be unique for this waypoint pairing).
72
+ * @param {Function} follow Test function to determine if route can be followed.
73
+ * @returns {Plan} Chain
74
+ * @throws {Error} If attempting to create a "next" route from an exit node
75
+ */
76
+ setNamedRoute(src: string, tgt: string, name: string, follow: Function): Plan;
77
+ /**
78
+ * This is a convenience method for traversing all "next" routes, and returning
79
+ * the IDs of all waypoints visited along the way.
80
+ *
81
+ * @param {JourneyContext} context Journey Context.
82
+ * @param {object} options Options.
83
+ * @returns {Array<string>} List of traversed waypoints.
84
+ */
85
+ traverse(context: JourneyContext, options?: object): Array<string>;
86
+ traverseNextRoutes(context: any, options?: {}): object[];
87
+ traversePrevRoutes(context: any, options?: {}): object[];
88
+ /**
89
+ * Traverse through the plan from a particular starting waypoint. This is a
90
+ * non-exhaustive Graph Exploration.
91
+ *
92
+ * The last route in the list will contain the source of the last waypoint that
93
+ * can be reached, i.e. The waypoint that has no further satisfiable out-edges.
94
+ *
95
+ * If a cyclical set of routes are encountered, traversal will stop after
96
+ * reaching the first repeated waypoint.
97
+ *
98
+ * Options:
99
+ * string startWaypoint = Waypoint from which to start traversal
100
+ * string routeName = Follow routes matching this name (next | prev)
101
+ * Map history = Used to detect loops in traversal (internal use)
102
+ * function stopCondition = Condition that, if true, will stop traversal (useful for performance)
103
+ * function|string arbiter = When mutliple target routes are found, this will decide which one to choose (if any)
104
+ *
105
+ * @param {JourneyContext} context Journey context
106
+ * @param {object} options Options
107
+ * @returns {Array<object>} Routes that were traversed
108
+ * @throws {TypeError} When context is not a JourneyContext
109
+ */
110
+ traverseRoutes(context: JourneyContext, options?: object): Array<object>;
111
+ /**
112
+ * Get raw graph data structure. This can be used with other libraries to
113
+ * generate graph visualisations, for example.
114
+ *
115
+ * @returns {graphlib.Graph} Graph data structure.
116
+ */
117
+ getGraphStructure(): any;
118
+ }
119
+ import JourneyContext from "./JourneyContext.js";