ui5-lib-guard-router 1.6.2 → 1.7.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/{dist/.ui5 → .ui5}/build-manifest.json +56 -8
- package/CHANGELOG.md +190 -0
- package/README.md +695 -327
- package/dist/index.d.ts +9 -5
- package/dist/resources/ui5/guard/router/.library +1 -1
- package/dist/resources/ui5/guard/router/GuardConfig-dbg.js +222 -0
- package/dist/resources/ui5/guard/router/GuardConfig-dbg.js.map +1 -0
- package/dist/resources/ui5/guard/router/GuardConfig.d.ts +89 -0
- package/dist/resources/ui5/guard/router/GuardConfig.d.ts.map +1 -0
- package/dist/resources/ui5/guard/router/GuardConfig.js +2 -0
- package/dist/resources/ui5/guard/router/GuardConfig.js.map +1 -0
- package/dist/resources/ui5/guard/router/GuardModules-dbg.js +253 -0
- package/dist/resources/ui5/guard/router/GuardModules-dbg.js.map +1 -0
- package/dist/resources/ui5/guard/router/GuardModules.d.ts +72 -0
- package/dist/resources/ui5/guard/router/GuardModules.d.ts.map +1 -0
- package/dist/resources/ui5/guard/router/GuardModules.js +2 -0
- package/dist/resources/ui5/guard/router/GuardModules.js.map +1 -0
- package/dist/resources/ui5/guard/router/GuardPipeline-dbg.js +122 -121
- package/dist/resources/ui5/guard/router/GuardPipeline-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/GuardPipeline.d.ts +45 -26
- package/dist/resources/ui5/guard/router/GuardPipeline.d.ts.map +1 -1
- package/dist/resources/ui5/guard/router/GuardPipeline.js +1 -1
- package/dist/resources/ui5/guard/router/GuardPipeline.js.map +1 -1
- package/dist/resources/ui5/guard/router/NavigationOutcome-dbg.js +3 -3
- package/dist/resources/ui5/guard/router/NavigationOutcome-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/NavigationOutcome.d.ts +3 -3
- package/dist/resources/ui5/guard/router/NavigationOutcome.d.ts.map +1 -1
- package/dist/resources/ui5/guard/router/NavigationOutcome.js.map +1 -1
- package/dist/resources/ui5/guard/router/PatternTree-dbg.js +156 -0
- package/dist/resources/ui5/guard/router/PatternTree-dbg.js.map +1 -0
- package/dist/resources/ui5/guard/router/PatternTree.d.ts +71 -0
- package/dist/resources/ui5/guard/router/PatternTree.d.ts.map +1 -0
- package/dist/resources/ui5/guard/router/PatternTree.js +2 -0
- package/dist/resources/ui5/guard/router/PatternTree.js.map +1 -0
- package/dist/resources/ui5/guard/router/RouteMeta-dbg.js +84 -0
- package/dist/resources/ui5/guard/router/RouteMeta-dbg.js.map +1 -0
- package/dist/resources/ui5/guard/router/RouteMeta.d.ts +33 -0
- package/dist/resources/ui5/guard/router/RouteMeta.d.ts.map +1 -0
- package/dist/resources/ui5/guard/router/RouteMeta.js +2 -0
- package/dist/resources/ui5/guard/router/RouteMeta.js.map +1 -0
- package/dist/resources/ui5/guard/router/Router-dbg.js +882 -1020
- package/dist/resources/ui5/guard/router/Router-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/Router.d.ts +360 -211
- package/dist/resources/ui5/guard/router/Router.d.ts.map +1 -1
- package/dist/resources/ui5/guard/router/Router.js +1 -1
- package/dist/resources/ui5/guard/router/Router.js.map +1 -1
- package/dist/resources/ui5/guard/router/library-dbg.js +1 -1
- package/dist/resources/ui5/guard/router/library-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/library-preload.js +8 -4
- package/dist/resources/ui5/guard/router/library-preload.js.map +1 -1
- package/dist/resources/ui5/guard/router/library.js +1 -1
- package/dist/resources/ui5/guard/router/library.js.map +1 -1
- package/dist/resources/ui5/guard/router/manifest.json +5 -2
- package/dist/resources/ui5/guard/router/types-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/types.d.ts +94 -39
- package/dist/resources/ui5/guard/router/types.d.ts.map +1 -1
- package/package.json +10 -6
- package/src/GuardConfig.ts +272 -0
- package/src/GuardModules.ts +249 -0
- package/src/GuardPipeline.ts +155 -128
- package/src/NavigationOutcome.ts +3 -3
- package/src/PatternTree.ts +145 -0
- package/src/RouteMeta.ts +82 -0
- package/src/Router.ts +1089 -1130
- package/src/manifest.json +5 -2
- package/src/types.ts +79 -22
- package/tsconfig.json +0 -11
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
sap.ui.define(["sap/base/Log"], function (Log) {
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
/** The component under which the library logs. */
|
|
4
5
|
const LOG_COMPONENT = "ui5.guard.router.Router";
|
|
5
6
|
function isGuardRedirect(value) {
|
|
6
7
|
if (typeof value !== "object" || value === null) {
|
|
7
8
|
return false;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
route
|
|
11
|
-
} = value;
|
|
12
|
-
return typeof route === "string" && route.length > 0;
|
|
10
|
+
return "route" in value && typeof value.route === "string" && value.route.length > 0;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
/**
|
|
@@ -22,22 +20,70 @@ sap.ui.define(["sap/base/Log"], function (Log) {
|
|
|
22
20
|
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
23
21
|
return false;
|
|
24
22
|
}
|
|
25
|
-
return typeof value.then === "function";
|
|
23
|
+
return "then" in value && typeof value.then === "function";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** How this engine prints the resolve function of a Promise: `function () { [native code] }` in V8. */
|
|
27
|
+
let resolverSource;
|
|
28
|
+
void new Promise(resolve => {
|
|
29
|
+
resolverSource = Function.prototype.toString.call(resolve);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Whether `value` looks exactly like the resolve function of a native Promise: a function with
|
|
34
|
+
* the name `""`, the length `1` and the source text that this engine prints for such a function.
|
|
35
|
+
* `Router#attachRouteMatched` needs this to recognize a UI5 component target that waits for the
|
|
36
|
+
* router. A function written in JavaScript never matches; other anonymous built-ins with one
|
|
37
|
+
* parameter do, above all the reject function of a Promise.
|
|
38
|
+
*/
|
|
39
|
+
function isPromiseResolver(value) {
|
|
40
|
+
return typeof value === "function" && value.name === "" && value.length === 1 && Function.prototype.toString.call(value) === resolverSource;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Names of manifest guards, derived from their module, for log output. */
|
|
44
|
+
const guardNames = new WeakMap();
|
|
45
|
+
|
|
46
|
+
/** Give a guard a name that its log messages show. */
|
|
47
|
+
function nameGuard(guard, name) {
|
|
48
|
+
guardNames.set(guard, name);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Describe a guard for log output: `Enter guard [0]`, or `Enter guard [0] "checks#0"` when it has a name. */
|
|
52
|
+
function describeGuard(label, index, guard) {
|
|
53
|
+
const name = guardNames.get(guard);
|
|
54
|
+
return name === undefined ? `${label} [${index}]` : `${label} [${index}] "${name}"`;
|
|
26
55
|
}
|
|
27
56
|
|
|
28
57
|
/**
|
|
29
58
|
* Normalized result of the guard decision pipeline.
|
|
30
59
|
*/
|
|
31
60
|
|
|
61
|
+
function toDecision(result) {
|
|
62
|
+
if (result === true) return {
|
|
63
|
+
action: "allow"
|
|
64
|
+
};
|
|
65
|
+
if (result === false) return {
|
|
66
|
+
action: "block"
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
action: "redirect",
|
|
70
|
+
target: result
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function toErrorDecision(error) {
|
|
74
|
+
return {
|
|
75
|
+
action: "error",
|
|
76
|
+
error
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
32
80
|
/**
|
|
33
81
|
* Standalone guard evaluation pipeline.
|
|
34
82
|
*
|
|
35
83
|
* Owns guard storage (global, enter, leave) and runs the full
|
|
36
|
-
* leave -> global-enter -> route-enter pipeline.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @namespace ui5.guard.router
|
|
84
|
+
* leave -> global-enter -> route-enter pipeline. It reads no Router
|
|
85
|
+
* state: evaluate() receives the context and the greedy routes left
|
|
86
|
+
* and entered with it.
|
|
41
87
|
*/
|
|
42
88
|
class GuardPipeline {
|
|
43
89
|
_globalGuards = [];
|
|
@@ -62,16 +108,14 @@ sap.ui.define(["sap/base/Log"], function (Log) {
|
|
|
62
108
|
*
|
|
63
109
|
* @param route - Route name as defined in `manifest.json`.
|
|
64
110
|
* @param guard - Guard function to register.
|
|
111
|
+
* @param before - A guard of the route to register `guard` in front of; at the end without it.
|
|
65
112
|
*/
|
|
66
|
-
addEnterGuard(route, guard) {
|
|
67
|
-
this._addToGuardMap(this._enterGuards, route, guard);
|
|
113
|
+
addEnterGuard(route, guard, before) {
|
|
114
|
+
this._addToGuardMap(this._enterGuards, route, guard, before);
|
|
68
115
|
}
|
|
69
116
|
|
|
70
117
|
/**
|
|
71
118
|
* Remove a previously registered enter guard by reference.
|
|
72
|
-
*
|
|
73
|
-
* @param route - Route name.
|
|
74
|
-
* @param guard - Guard function to remove.
|
|
75
119
|
*/
|
|
76
120
|
removeEnterGuard(route, guard) {
|
|
77
121
|
this._removeFromGuardMap(this._enterGuards, route, guard);
|
|
@@ -86,16 +130,14 @@ sap.ui.define(["sap/base/Log"], function (Log) {
|
|
|
86
130
|
*
|
|
87
131
|
* @param route - Route name as defined in `manifest.json`.
|
|
88
132
|
* @param guard - Guard function to register as a leave guard.
|
|
133
|
+
* @param before - A leave guard of the route to register `guard` in front of; at the end without it.
|
|
89
134
|
*/
|
|
90
|
-
addLeaveGuard(route, guard) {
|
|
91
|
-
this._addToGuardMap(this._leaveGuards, route, guard);
|
|
135
|
+
addLeaveGuard(route, guard, before) {
|
|
136
|
+
this._addToGuardMap(this._leaveGuards, route, guard, before);
|
|
92
137
|
}
|
|
93
138
|
|
|
94
139
|
/**
|
|
95
140
|
* Remove a previously registered leave guard by reference.
|
|
96
|
-
*
|
|
97
|
-
* @param route - Route name.
|
|
98
|
-
* @param guard - Guard function to remove.
|
|
99
141
|
*/
|
|
100
142
|
removeLeaveGuard(route, guard) {
|
|
101
143
|
this._removeFromGuardMap(this._leaveGuards, route, guard);
|
|
@@ -121,90 +163,50 @@ sap.ui.define(["sap/base/Log"], function (Log) {
|
|
|
121
163
|
* @param options.skipLeaveGuards - When true, leave guards are skipped even if
|
|
122
164
|
* `context.fromRoute` is set. Used by redirect chain hops to avoid re-running
|
|
123
165
|
* leave guards while still preserving `fromRoute` in the context.
|
|
166
|
+
* @param options.alsoLeaving - Greedy routes that are left as well: their leave guards run
|
|
167
|
+
* after those of `context.fromRoute`, with the same context.
|
|
168
|
+
* @param options.alsoEntering - Greedy routes that match as well: their enter guards run
|
|
169
|
+
* after those of `context.toRoute`, with the same context.
|
|
124
170
|
* @returns A synchronous {@link GuardDecision} when all guards return plain values,
|
|
125
171
|
* or a `Promise<GuardDecision>` when at least one guard returns a thenable.
|
|
126
172
|
*/
|
|
127
173
|
evaluate(context, options) {
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
if (r === false) return {
|
|
174
|
+
// No route is left on the first navigation, or after a hash that matched none.
|
|
175
|
+
const leaving = options?.skipLeaveGuards || context.fromRoute === "" ? [] : [context.fromRoute, ...(options?.alsoLeaving ?? [])];
|
|
176
|
+
const entering = [context.toRoute, ...(options?.alsoEntering ?? [])];
|
|
177
|
+
const runEnterPhase = () => {
|
|
178
|
+
const enterResult = this._runEnterGuards(entering, context);
|
|
179
|
+
return isPromiseLike(enterResult) ? enterResult.then(toDecision).catch(toErrorDecision) : toDecision(enterResult);
|
|
180
|
+
};
|
|
181
|
+
try {
|
|
182
|
+
const leaveResult = this._runForEach(leaving, context, route => this._runGuards(this._leaveGuards.get(route) ?? [], context, route, result => this._validateLeaveGuardResult(result), "Leave guard"));
|
|
183
|
+
if (isPromiseLike(leaveResult)) {
|
|
184
|
+
return leaveResult.then(allowed => {
|
|
185
|
+
if (allowed !== true) return {
|
|
142
186
|
action: "block"
|
|
143
187
|
};
|
|
144
|
-
return {
|
|
145
|
-
action: "
|
|
146
|
-
target: r
|
|
147
|
-
};
|
|
148
|
-
}).catch(error => {
|
|
149
|
-
return {
|
|
150
|
-
action: "error",
|
|
151
|
-
error
|
|
188
|
+
if (context.signal.aborted) return {
|
|
189
|
+
action: "block"
|
|
152
190
|
};
|
|
153
|
-
|
|
191
|
+
return runEnterPhase();
|
|
192
|
+
}).catch(toErrorDecision);
|
|
154
193
|
}
|
|
155
|
-
if (
|
|
156
|
-
action: "allow"
|
|
157
|
-
};
|
|
158
|
-
if (enterResult === false) return {
|
|
194
|
+
if (leaveResult !== true) return {
|
|
159
195
|
action: "block"
|
|
160
196
|
};
|
|
161
|
-
return {
|
|
162
|
-
action: "redirect",
|
|
163
|
-
target: enterResult
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
const runEnterPhase = () => {
|
|
167
|
-
const enterResult = this._runEnterGuards(context.toRoute, context);
|
|
168
|
-
return processEnterResult(enterResult);
|
|
169
|
-
};
|
|
170
|
-
try {
|
|
171
|
-
if (hasLeaveGuards) {
|
|
172
|
-
const leaveResult = this._runLeaveGuards(context);
|
|
173
|
-
if (isPromiseLike(leaveResult)) {
|
|
174
|
-
return leaveResult.then(allowed => {
|
|
175
|
-
if (allowed !== true) return {
|
|
176
|
-
action: "block"
|
|
177
|
-
};
|
|
178
|
-
if (context.signal.aborted) return {
|
|
179
|
-
action: "block"
|
|
180
|
-
};
|
|
181
|
-
return runEnterPhase();
|
|
182
|
-
}).catch(error => {
|
|
183
|
-
return {
|
|
184
|
-
action: "error",
|
|
185
|
-
error
|
|
186
|
-
};
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (leaveResult !== true) return {
|
|
190
|
-
action: "block"
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
197
|
return runEnterPhase();
|
|
194
198
|
} catch (error) {
|
|
195
|
-
return
|
|
196
|
-
action: "error",
|
|
197
|
-
error
|
|
198
|
-
};
|
|
199
|
+
return toErrorDecision(error);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
|
-
_addToGuardMap(map, key, guard) {
|
|
202
|
+
_addToGuardMap(map, key, guard, before) {
|
|
202
203
|
let guards = map.get(key);
|
|
203
204
|
if (!guards) {
|
|
204
205
|
guards = [];
|
|
205
206
|
map.set(key, guards);
|
|
206
207
|
}
|
|
207
|
-
guards.
|
|
208
|
+
const index = before === undefined ? -1 : guards.indexOf(before);
|
|
209
|
+
if (index === -1) guards.push(guard);else guards.splice(index, 0, guard);
|
|
208
210
|
}
|
|
209
211
|
_removeFromGuardMap(map, key, guard) {
|
|
210
212
|
const guards = map.get(key);
|
|
@@ -215,71 +217,68 @@ sap.ui.define(["sap/base/Log"], function (Log) {
|
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
/**
|
|
218
|
-
* Run
|
|
219
|
-
*
|
|
220
|
-
* The guard array is snapshot-copied before iteration so that guards
|
|
221
|
-
* may safely add/remove themselves (e.g. one-shot guards) without
|
|
222
|
-
* affecting the current pipeline run.
|
|
220
|
+
* Run `run` for each route in order until one does not return `true`. Stays sync as long
|
|
221
|
+
* as the runs do; after an async run the next one starts unless the navigation was aborted.
|
|
223
222
|
*/
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
if (result !== true) return this._validateLeaveGuardResult(result);
|
|
235
|
-
} catch (error) {
|
|
236
|
-
Log.error(`Leave guard [${i}] on route "${context.fromRoute}" threw, navigation failed`, error instanceof Error ? error : String(error), LOG_COMPONENT);
|
|
237
|
-
if (context.signal.aborted) return false;
|
|
238
|
-
throw error;
|
|
223
|
+
_runForEach(routes, context, run, start = 0) {
|
|
224
|
+
for (let i = start; i < routes.length; i++) {
|
|
225
|
+
const result = run(routes[i]);
|
|
226
|
+
if (isPromiseLike(result)) {
|
|
227
|
+
return result.then(settled => {
|
|
228
|
+
if (settled !== true) return settled;
|
|
229
|
+
if (context.signal.aborted) return false;
|
|
230
|
+
return this._runForEach(routes, context, run, i + 1);
|
|
231
|
+
});
|
|
239
232
|
}
|
|
233
|
+
if (result !== true) return result;
|
|
240
234
|
}
|
|
241
235
|
return true;
|
|
242
236
|
}
|
|
243
237
|
|
|
244
|
-
/** Run global guards, then route-specific guards
|
|
245
|
-
_runEnterGuards(
|
|
246
|
-
const
|
|
238
|
+
/** Run global guards, then the route-specific guards of each route in `entering`. Stays sync when possible. */
|
|
239
|
+
_runEnterGuards(entering, context) {
|
|
240
|
+
const runRouteGuards = () => this._runForEach(entering, context, route => this._runRouteGuards(route, context));
|
|
241
|
+
const globalResult = this._runGuards(this._globalGuards, context, context.toRoute, result => this._validateGuardResult(result), "Enter guard");
|
|
247
242
|
if (isPromiseLike(globalResult)) {
|
|
248
243
|
return globalResult.then(result => {
|
|
249
244
|
if (result !== true) return result;
|
|
250
245
|
if (context.signal.aborted) return false;
|
|
251
|
-
return
|
|
246
|
+
return runRouteGuards();
|
|
252
247
|
});
|
|
253
248
|
}
|
|
254
249
|
if (globalResult !== true) return globalResult;
|
|
255
|
-
return
|
|
250
|
+
return runRouteGuards();
|
|
256
251
|
}
|
|
257
252
|
|
|
258
253
|
/** Run route-specific guards if any are registered. */
|
|
259
254
|
_runRouteGuards(toRoute, context) {
|
|
260
|
-
|
|
261
|
-
|
|
255
|
+
const guards = toRoute ? this._enterGuards.get(toRoute) : undefined;
|
|
256
|
+
if (!guards) return true;
|
|
257
|
+
return this._runGuards(guards, context, toRoute, result => this._validateGuardResult(result), "Enter guard");
|
|
262
258
|
}
|
|
263
259
|
|
|
264
260
|
/**
|
|
265
|
-
* Run guards sync; switch to async path if a Promise is returned.
|
|
261
|
+
* Run guards sync; switch to async path if a Promise is returned. A result that is not
|
|
262
|
+
* `true` ends the run with what `onBlock` makes of it.
|
|
266
263
|
*
|
|
267
264
|
* The guard array is snapshot-copied before iteration so that guards
|
|
268
265
|
* may safely add/remove themselves (e.g. one-shot guards) without
|
|
269
266
|
* affecting the current pipeline run.
|
|
267
|
+
*
|
|
268
|
+
* @param route - The route the guards are registered for, named in error logs.
|
|
270
269
|
*/
|
|
271
|
-
_runGuards(guards, context) {
|
|
270
|
+
_runGuards(guards, context, route, onBlock, label) {
|
|
272
271
|
guards = guards.slice();
|
|
273
272
|
for (let i = 0; i < guards.length; i++) {
|
|
274
273
|
try {
|
|
275
274
|
const result = guards[i](context);
|
|
276
275
|
if (isPromiseLike(result)) {
|
|
277
|
-
return this._continueGuardsAsync(result, guards, i, context,
|
|
276
|
+
return this._continueGuardsAsync(result, guards, i, context, onBlock, label, route);
|
|
278
277
|
}
|
|
279
|
-
if (result !== true) return
|
|
278
|
+
if (result !== true) return onBlock(result);
|
|
280
279
|
} catch (error) {
|
|
281
|
-
Log.error(`Enter guard [${i}] on route "${context.toRoute}" threw, navigation failed`, error instanceof Error ? error : String(error), LOG_COMPONENT);
|
|
282
280
|
if (context.signal.aborted) return false;
|
|
281
|
+
Log.error(`${describeGuard(label, i, guards[i])} on route "${route}" threw, navigation failed`, error instanceof Error ? error : String(error), LOG_COMPONENT);
|
|
283
282
|
throw error;
|
|
284
283
|
}
|
|
285
284
|
}
|
|
@@ -293,9 +292,9 @@ sap.ui.define(["sap/base/Log"], function (Log) {
|
|
|
293
292
|
* determines what to return for non-true results: leave guards always
|
|
294
293
|
* return `false`, enter guards validate and may return redirects.
|
|
295
294
|
*
|
|
296
|
-
* @param
|
|
295
|
+
* @param route - The route the guards are registered for, named in error logs.
|
|
297
296
|
*/
|
|
298
|
-
async _continueGuardsAsync(pendingResult, guards, currentIndex, context, onBlock, label,
|
|
297
|
+
async _continueGuardsAsync(pendingResult, guards, currentIndex, context, onBlock, label, route) {
|
|
299
298
|
let guardIndex = currentIndex;
|
|
300
299
|
try {
|
|
301
300
|
const result = await pendingResult;
|
|
@@ -309,8 +308,7 @@ sap.ui.define(["sap/base/Log"], function (Log) {
|
|
|
309
308
|
return true;
|
|
310
309
|
} catch (error) {
|
|
311
310
|
if (!context.signal.aborted) {
|
|
312
|
-
|
|
313
|
-
Log.error(`${label} [${guardIndex}] on route "${route}" threw, navigation failed`, error instanceof Error ? error : String(error), LOG_COMPONENT);
|
|
311
|
+
Log.error(`${describeGuard(label, guardIndex, guards[guardIndex])} on route "${route}" threw, navigation failed`, error instanceof Error ? error : String(error), LOG_COMPONENT);
|
|
314
312
|
throw error;
|
|
315
313
|
}
|
|
316
314
|
return false;
|
|
@@ -333,7 +331,10 @@ sap.ui.define(["sap/base/Log"], function (Log) {
|
|
|
333
331
|
return false;
|
|
334
332
|
}
|
|
335
333
|
}
|
|
334
|
+
GuardPipeline.LOG_COMPONENT = LOG_COMPONENT;
|
|
336
335
|
GuardPipeline.isPromiseLike = isPromiseLike;
|
|
336
|
+
GuardPipeline.isPromiseResolver = isPromiseResolver;
|
|
337
|
+
GuardPipeline.nameGuard = nameGuard;
|
|
337
338
|
return GuardPipeline;
|
|
338
339
|
});
|
|
339
340
|
//# sourceMappingURL=GuardPipeline-dbg.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GuardPipeline-dbg.js","names":["LOG_COMPONENT","isGuardRedirect","value","route","length","isPromiseLike","then","GuardPipeline","_globalGuards","_enterGuards","Map","_leaveGuards","addGlobalGuard","guard","push","removeGlobalGuard","index","indexOf","splice","addEnterGuard","_addToGuardMap","removeEnterGuard","_removeFromGuardMap","addLeaveGuard","removeLeaveGuard","clear","evaluate","context","options","hasLeaveGuards","skipLeaveGuards","fromRoute","has","hasEnterGuards","toRoute","action","processEnterResult","enterResult","r","target","catch","error","runEnterPhase","_runEnterGuards","leaveResult","_runLeaveGuards","allowed","signal","aborted","map","key","guards","get","set","delete","registered","slice","i","result","_continueGuardsAsync","candidate","_validateLeaveGuardResult","Log","Error","String","globalResult","_runGuards","_runRouteGuards","_validateGuardResult","pendingResult","currentIndex","onBlock","label","isLeaveGuard","guardIndex","nextResult","warning"],"sources":["GuardPipeline.ts"],"sourcesContent":["import Log from \"sap/base/Log\";\nimport type { GuardFn, GuardContext, GuardResult, GuardRedirect } from \"./types\";\n\nconst LOG_COMPONENT = \"ui5.guard.router.Router\";\n\nfunction isGuardRedirect(value: unknown): value is GuardRedirect {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn false;\n\t}\n\n\tconst { route } = value as GuardRedirect;\n\treturn typeof route === \"string\" && route.length > 0;\n}\n\n/**\n * Promises/A+ thenable detection via duck typing.\n *\n * We intentionally do not use `instanceof Promise` because that misses\n * cross-realm Promises and PromiseLike/thenable objects.\n */\nexport function isPromiseLike<T>(value: unknown): value is PromiseLike<T> {\n\tif ((typeof value !== \"object\" && typeof value !== \"function\") || value === null) {\n\t\treturn false;\n\t}\n\n\treturn typeof (value as PromiseLike<T>).then === \"function\";\n}\n\n/**\n * Normalized result of the guard decision pipeline.\n */\nexport type GuardDecision =\n\t| { action: \"allow\" }\n\t| { action: \"block\" }\n\t| { action: \"redirect\"; target: string | GuardRedirect }\n\t| { action: \"error\"; error: unknown };\n\n/**\n * Standalone guard evaluation pipeline.\n *\n * Owns guard storage (global, enter, leave) and runs the full\n * leave -> global-enter -> route-enter pipeline. Pure logic with\n * no dependency on Router state beyond the current route name\n * passed into evaluate().\n *\n * @namespace ui5.guard.router\n */\nexport default class GuardPipeline {\n\tprivate _globalGuards: GuardFn[] = [];\n\tprivate _enterGuards = new Map<string, GuardFn[]>();\n\tprivate _leaveGuards = new Map<string, GuardFn[]>();\n\n\t/** Register a guard that runs for every navigation. */\n\taddGlobalGuard(guard: GuardFn): void {\n\t\tthis._globalGuards.push(guard);\n\t}\n\n\t/** Remove a previously registered global guard by reference. */\n\tremoveGlobalGuard(guard: GuardFn): void {\n\t\tconst index = this._globalGuards.indexOf(guard);\n\t\tif (index !== -1) {\n\t\t\tthis._globalGuards.splice(index, 1);\n\t\t}\n\t}\n\n\t/**\n\t * Register an enter guard for a specific route.\n\t *\n\t * @param route - Route name as defined in `manifest.json`.\n\t * @param guard - Guard function to register.\n\t */\n\taddEnterGuard(route: string, guard: GuardFn): void {\n\t\tthis._addToGuardMap(this._enterGuards, route, guard);\n\t}\n\n\t/**\n\t * Remove a previously registered enter guard by reference.\n\t *\n\t * @param route - Route name.\n\t * @param guard - Guard function to remove.\n\t */\n\tremoveEnterGuard(route: string, guard: GuardFn): void {\n\t\tthis._removeFromGuardMap(this._enterGuards, route, guard);\n\t}\n\n\t/**\n\t * Register a leave guard for a specific route.\n\t *\n\t * Accepts `GuardFn` to support manifest-declared guards loaded from\n\t * untyped modules. Non-boolean return values are caught at runtime\n\t * by {@link _validateLeaveGuardResult}.\n\t *\n\t * @param route - Route name as defined in `manifest.json`.\n\t * @param guard - Guard function to register as a leave guard.\n\t */\n\taddLeaveGuard(route: string, guard: GuardFn): void {\n\t\tthis._addToGuardMap(this._leaveGuards, route, guard);\n\t}\n\n\t/**\n\t * Remove a previously registered leave guard by reference.\n\t *\n\t * @param route - Route name.\n\t * @param guard - Guard function to remove.\n\t */\n\tremoveLeaveGuard(route: string, guard: GuardFn): void {\n\t\tthis._removeFromGuardMap(this._leaveGuards, route, guard);\n\t}\n\n\t/**\n\t * Remove all registered guards.\n\t */\n\tclear(): void {\n\t\tthis._globalGuards = [];\n\t\tthis._enterGuards.clear();\n\t\tthis._leaveGuards.clear();\n\t}\n\n\t/**\n\t * Run the full guard pipeline (leave -> global enter -> route enter) and\n\t * return a normalized decision. Stays synchronous when all guards return\n\t * plain values; returns a Promise only when an async guard is encountered.\n\t *\n\t * @param context - Complete guard context including AbortSignal.\n\t * `context.fromRoute` controls leave-guard lookup: empty string skips leave guards.\n\t * @param options - Optional evaluation options.\n\t * @param options.skipLeaveGuards - When true, leave guards are skipped even if\n\t * `context.fromRoute` is set. Used by redirect chain hops to avoid re-running\n\t * leave guards while still preserving `fromRoute` in the context.\n\t * @returns A synchronous {@link GuardDecision} when all guards return plain values,\n\t * or a `Promise<GuardDecision>` when at least one guard returns a thenable.\n\t */\n\tevaluate(context: GuardContext, options?: { skipLeaveGuards?: boolean }): GuardDecision | Promise<GuardDecision> {\n\t\tconst hasLeaveGuards =\n\t\t\t!options?.skipLeaveGuards && context.fromRoute !== \"\" && this._leaveGuards.has(context.fromRoute);\n\t\tconst hasEnterGuards =\n\t\t\tthis._globalGuards.length > 0 || (context.toRoute !== \"\" && this._enterGuards.has(context.toRoute));\n\n\t\tif (!hasLeaveGuards && !hasEnterGuards) {\n\t\t\treturn { action: \"allow\" };\n\t\t}\n\n\t\tconst processEnterResult = (\n\t\t\tenterResult: GuardResult | Promise<GuardResult>,\n\t\t): GuardDecision | Promise<GuardDecision> => {\n\t\t\tif (isPromiseLike(enterResult)) {\n\t\t\t\treturn enterResult\n\t\t\t\t\t.then((r: GuardResult): GuardDecision => {\n\t\t\t\t\t\tif (r === true) return { action: \"allow\" };\n\t\t\t\t\t\tif (r === false) return { action: \"block\" };\n\t\t\t\t\t\treturn { action: \"redirect\", target: r };\n\t\t\t\t\t})\n\t\t\t\t\t.catch((error: unknown): GuardDecision => {\n\t\t\t\t\t\treturn { action: \"error\", error };\n\t\t\t\t\t});\n\t\t\t}\n\t\t\tif (enterResult === true) return { action: \"allow\" };\n\t\t\tif (enterResult === false) return { action: \"block\" };\n\t\t\treturn { action: \"redirect\", target: enterResult };\n\t\t};\n\n\t\tconst runEnterPhase = (): GuardDecision | Promise<GuardDecision> => {\n\t\t\tconst enterResult = this._runEnterGuards(context.toRoute, context);\n\t\t\treturn processEnterResult(enterResult);\n\t\t};\n\n\t\ttry {\n\t\t\tif (hasLeaveGuards) {\n\t\t\t\tconst leaveResult = this._runLeaveGuards(context);\n\n\t\t\t\tif (isPromiseLike(leaveResult)) {\n\t\t\t\t\treturn leaveResult\n\t\t\t\t\t\t.then((allowed: boolean): GuardDecision | Promise<GuardDecision> => {\n\t\t\t\t\t\t\tif (allowed !== true) return { action: \"block\" };\n\t\t\t\t\t\t\tif (context.signal.aborted) return { action: \"block\" };\n\t\t\t\t\t\t\treturn runEnterPhase();\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch((error: unknown): GuardDecision => {\n\t\t\t\t\t\t\treturn { action: \"error\", error };\n\t\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (leaveResult !== true) return { action: \"block\" };\n\t\t\t}\n\n\t\t\treturn runEnterPhase();\n\t\t} catch (error) {\n\t\t\treturn { action: \"error\", error };\n\t\t}\n\t}\n\n\tprivate _addToGuardMap<T>(map: Map<string, T[]>, key: string, guard: T): void {\n\t\tlet guards = map.get(key);\n\t\tif (!guards) {\n\t\t\tguards = [];\n\t\t\tmap.set(key, guards);\n\t\t}\n\t\tguards.push(guard);\n\t}\n\n\tprivate _removeFromGuardMap<T>(map: Map<string, T[]>, key: string, guard: T): void {\n\t\tconst guards = map.get(key);\n\t\tif (!guards) return;\n\t\tconst index = guards.indexOf(guard);\n\t\tif (index !== -1) guards.splice(index, 1);\n\t\tif (guards.length === 0) map.delete(key);\n\t}\n\n\t/**\n\t * Run leave guards for the current route. Returns boolean (no redirects).\n\t *\n\t * The guard array is snapshot-copied before iteration so that guards\n\t * may safely add/remove themselves (e.g. one-shot guards) without\n\t * affecting the current pipeline run.\n\t */\n\tprivate _runLeaveGuards(context: GuardContext): boolean | Promise<boolean> {\n\t\tconst registered = this._leaveGuards.get(context.fromRoute);\n\t\tif (!registered || registered.length === 0) return true;\n\n\t\tconst guards = registered.slice();\n\t\tfor (let i = 0; i < guards.length; i++) {\n\t\t\ttry {\n\t\t\t\tconst result = guards[i](context);\n\t\t\t\tif (isPromiseLike(result)) {\n\t\t\t\t\treturn this._continueGuardsAsync(\n\t\t\t\t\t\tresult,\n\t\t\t\t\t\tguards,\n\t\t\t\t\t\ti,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t(candidate) => this._validateLeaveGuardResult(candidate),\n\t\t\t\t\t\t\"Leave guard\",\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t) as Promise<boolean>;\n\t\t\t\t}\n\t\t\t\tif (result !== true) return this._validateLeaveGuardResult(result);\n\t\t\t} catch (error) {\n\t\t\t\tLog.error(\n\t\t\t\t\t`Leave guard [${i}] on route \"${context.fromRoute}\" threw, navigation failed`,\n\t\t\t\t\terror instanceof Error ? error : String(error),\n\t\t\t\t\tLOG_COMPONENT,\n\t\t\t\t);\n\t\t\t\tif (context.signal.aborted) return false;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** Run global guards, then route-specific guards. Stays sync when possible. */\n\tprivate _runEnterGuards(toRoute: string, context: GuardContext): GuardResult | Promise<GuardResult> {\n\t\tconst globalResult = this._runGuards(this._globalGuards, context);\n\n\t\tif (isPromiseLike(globalResult)) {\n\t\t\treturn globalResult.then((result: GuardResult) => {\n\t\t\t\tif (result !== true) return result;\n\t\t\t\tif (context.signal.aborted) return false;\n\t\t\t\treturn this._runRouteGuards(toRoute, context);\n\t\t\t});\n\t\t}\n\t\tif (globalResult !== true) return globalResult;\n\t\treturn this._runRouteGuards(toRoute, context);\n\t}\n\n\t/** Run route-specific guards if any are registered. */\n\tprivate _runRouteGuards(toRoute: string, context: GuardContext): GuardResult | Promise<GuardResult> {\n\t\tif (!toRoute || !this._enterGuards.has(toRoute)) return true;\n\t\treturn this._runGuards(this._enterGuards.get(toRoute)!, context);\n\t}\n\n\t/**\n\t * Run guards sync; switch to async path if a Promise is returned.\n\t *\n\t * The guard array is snapshot-copied before iteration so that guards\n\t * may safely add/remove themselves (e.g. one-shot guards) without\n\t * affecting the current pipeline run.\n\t */\n\tprivate _runGuards(guards: GuardFn[], context: GuardContext): GuardResult | Promise<GuardResult> {\n\t\tguards = guards.slice();\n\t\tfor (let i = 0; i < guards.length; i++) {\n\t\t\ttry {\n\t\t\t\tconst result = guards[i](context);\n\t\t\t\tif (isPromiseLike(result)) {\n\t\t\t\t\treturn this._continueGuardsAsync(\n\t\t\t\t\t\tresult,\n\t\t\t\t\t\tguards,\n\t\t\t\t\t\ti,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t(candidate) => this._validateGuardResult(candidate),\n\t\t\t\t\t\t\"Enter guard\",\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (result !== true) return this._validateGuardResult(result);\n\t\t\t} catch (error) {\n\t\t\t\tLog.error(\n\t\t\t\t\t`Enter guard [${i}] on route \"${context.toRoute}\" threw, navigation failed`,\n\t\t\t\t\terror instanceof Error ? error : String(error),\n\t\t\t\t\tLOG_COMPONENT,\n\t\t\t\t);\n\t\t\t\tif (context.signal.aborted) return false;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Continue guard array async from the first Promise onward.\n\t *\n\t * Shared by both enter and leave guard pipelines. The `onBlock` callback\n\t * determines what to return for non-true results: leave guards always\n\t * return `false`, enter guards validate and may return redirects.\n\t *\n\t * @param isLeaveGuard - When true, error logs reference `fromRoute`; otherwise `toRoute`.\n\t */\n\tprivate async _continueGuardsAsync(\n\t\tpendingResult: PromiseLike<GuardResult>,\n\t\tguards: GuardFn[],\n\t\tcurrentIndex: number,\n\t\tcontext: GuardContext,\n\t\tonBlock: (result: unknown) => GuardResult,\n\t\tlabel: string,\n\t\tisLeaveGuard: boolean,\n\t): Promise<GuardResult> {\n\t\tlet guardIndex = currentIndex;\n\t\ttry {\n\t\t\tconst result = await pendingResult;\n\t\t\tif (result !== true) return onBlock(result);\n\n\t\t\tfor (let i = currentIndex + 1; i < guards.length; i++) {\n\t\t\t\tif (context.signal.aborted) return false;\n\t\t\t\tguardIndex = i;\n\t\t\t\tconst nextResult = await guards[i](context);\n\t\t\t\tif (nextResult !== true) return onBlock(nextResult);\n\t\t\t}\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tif (!context.signal.aborted) {\n\t\t\t\tconst route = isLeaveGuard ? context.fromRoute : context.toRoute;\n\t\t\t\tLog.error(\n\t\t\t\t\t`${label} [${guardIndex}] on route \"${route}\" threw, navigation failed`,\n\t\t\t\t\terror instanceof Error ? error : String(error),\n\t\t\t\t\tLOG_COMPONENT,\n\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/** Validate a non-true guard result; invalid values become false. */\n\tprivate _validateGuardResult(result: unknown): GuardResult {\n\t\tif (typeof result === \"boolean\") return result;\n\t\tif (typeof result === \"string\" && result.length > 0) return result;\n\t\tif (isGuardRedirect(result)) return result;\n\t\tLog.warning(\"Guard returned invalid value, treating as block\", String(result), LOG_COMPONENT);\n\t\treturn false;\n\t}\n\n\t/** Validate a leave guard result; non-boolean values log a warning and block. */\n\tprivate _validateLeaveGuardResult(result: unknown): boolean {\n\t\tif (typeof result === \"boolean\") return result;\n\t\tLog.warning(\"Leave guard returned non-boolean value, treating as block\", String(result), LOG_COMPONENT);\n\t\treturn false;\n\t}\n}\n"],"mappings":";;;EAGA,MAAMA,aAAa,GAAG,yBAAyB;EAE/C,SAASC,eAAeA,CAACC,KAAc,EAA0B;IAChE,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,EAAE;MAChD,OAAO,KAAK;IACb;IAEA,MAAM;MAAEC;IAAM,CAAC,GAAGD,KAAsB;IACxC,OAAO,OAAOC,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACC,MAAM,GAAG,CAAC;EACrD;;EAEA;AACA;AACA;AACA;AACA;AACA;EACO,SAASC,aAAaA,CAAIH,KAAc,EAA2B;IACzE,IAAK,OAAOA,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,UAAU,IAAKA,KAAK,KAAK,IAAI,EAAE;MACjF,OAAO,KAAK;IACb;IAEA,OAAO,OAAQA,KAAK,CAAoBI,IAAI,KAAK,UAAU;EAC5D;;EAEA;AACA;AACA;;EAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACe,MAAMC,aAAa,CAAC;IAC1BC,aAAa,GAAc,EAAE;IAC7BC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,aAAa,CAAC;MAC7F,OAAO,KAAK;IACb;;IAEA;IACQ6D,yBAAyBA,CAACH,MAAe,EAAW;MAC3D,IAAI,OAAOA,MAAM,KAAK,SAAS,EAAE,OAAOA,MAAM;MAC9CI,GAAG,CAACc,OAAO,CAAC,2DAA2D,EAAEZ,MAAM,CAACN,MAAM,CAAC,EAAE1D,aAAa,CAAC;MACvG,OAAO,KAAK;IACb;EACD;EAACO,aAAA,CAAAF,aAAA,GAAAA,aAAA;EAAA,OAAAE,aAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"GuardPipeline-dbg.js","names":["LOG_COMPONENT","isGuardRedirect","value","route","length","isPromiseLike","then","resolverSource","Promise","resolve","Function","prototype","toString","call","isPromiseResolver","name","guardNames","WeakMap","nameGuard","guard","set","describeGuard","label","index","get","undefined","toDecision","result","action","target","toErrorDecision","error","GuardPipeline","_globalGuards","_enterGuards","Map","_leaveGuards","addGlobalGuard","push","removeGlobalGuard","indexOf","splice","addEnterGuard","before","_addToGuardMap","removeEnterGuard","_removeFromGuardMap","addLeaveGuard","removeLeaveGuard","clear","evaluate","context","options","leaving","skipLeaveGuards","fromRoute","alsoLeaving","entering","toRoute","alsoEntering","runEnterPhase","enterResult","_runEnterGuards","catch","leaveResult","_runForEach","_runGuards","_validateLeaveGuardResult","allowed","signal","aborted","map","key","guards","delete","routes","run","start","i","settled","runRouteGuards","_runRouteGuards","globalResult","_validateGuardResult","onBlock","slice","_continueGuardsAsync","Log","Error","String","pendingResult","currentIndex","guardIndex","nextResult","warning"],"sourceRoot":"./","sources":["GuardPipeline.ts"],"sourcesContent":["import Log from \"sap/base/Log\";\nimport type { GuardFn, GuardContext, GuardResult, GuardRedirect } from \"./types\";\n\n/** The component under which the library logs. */\nexport const LOG_COMPONENT = \"ui5.guard.router.Router\";\n\nfunction isGuardRedirect(value: unknown): value is GuardRedirect {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn false;\n\t}\n\n\treturn \"route\" in value && typeof value.route === \"string\" && value.route.length > 0;\n}\n\n/**\n * Promises/A+ thenable detection via duck typing.\n *\n * We intentionally do not use `instanceof Promise` because that misses\n * cross-realm Promises and PromiseLike/thenable objects.\n */\nexport function isPromiseLike<T>(value: unknown): value is PromiseLike<T> {\n\tif ((typeof value !== \"object\" && typeof value !== \"function\") || value === null) {\n\t\treturn false;\n\t}\n\n\treturn \"then\" in value && typeof value.then === \"function\";\n}\n\n/** How this engine prints the resolve function of a Promise: `function () { [native code] }` in V8. */\nlet resolverSource!: string;\nvoid new Promise((resolve) => {\n\tresolverSource = Function.prototype.toString.call(resolve);\n});\n\n/**\n * Whether `value` looks exactly like the resolve function of a native Promise: a function with\n * the name `\"\"`, the length `1` and the source text that this engine prints for such a function.\n * `Router#attachRouteMatched` needs this to recognize a UI5 component target that waits for the\n * router. A function written in JavaScript never matches; other anonymous built-ins with one\n * parameter do, above all the reject function of a Promise.\n */\nexport function isPromiseResolver(value: unknown): value is () => void {\n\treturn (\n\t\ttypeof value === \"function\" &&\n\t\tvalue.name === \"\" &&\n\t\tvalue.length === 1 &&\n\t\tFunction.prototype.toString.call(value) === resolverSource\n\t);\n}\n\n/** Names of manifest guards, derived from their module, for log output. */\nconst guardNames = new WeakMap<GuardFn, string>();\n\n/** Give a guard a name that its log messages show. */\nexport function nameGuard(guard: GuardFn, name: string): void {\n\tguardNames.set(guard, name);\n}\n\n/** Describe a guard for log output: `Enter guard [0]`, or `Enter guard [0] \"checks#0\"` when it has a name. */\nfunction describeGuard(label: string, index: number, guard: GuardFn): string {\n\tconst name = guardNames.get(guard);\n\treturn name === undefined ? `${label} [${index}]` : `${label} [${index}] \"${name}\"`;\n}\n\n/**\n * Normalized result of the guard decision pipeline.\n */\nexport type GuardDecision =\n\t| { action: \"allow\" }\n\t| { action: \"block\" }\n\t| { action: \"redirect\"; target: string | GuardRedirect }\n\t| { action: \"error\"; error: unknown };\n\nfunction toDecision(result: GuardResult): GuardDecision {\n\tif (result === true) return { action: \"allow\" };\n\tif (result === false) return { action: \"block\" };\n\treturn { action: \"redirect\", target: result };\n}\n\nfunction toErrorDecision(error: unknown): GuardDecision {\n\treturn { action: \"error\", error };\n}\n\n/**\n * Standalone guard evaluation pipeline.\n *\n * Owns guard storage (global, enter, leave) and runs the full\n * leave -> global-enter -> route-enter pipeline. It reads no Router\n * state: evaluate() receives the context and the greedy routes left\n * and entered with it.\n */\nexport default class GuardPipeline {\n\tprivate _globalGuards: GuardFn[] = [];\n\tprivate _enterGuards = new Map<string, GuardFn[]>();\n\tprivate _leaveGuards = new Map<string, GuardFn[]>();\n\n\t/** Register a guard that runs for every navigation. */\n\taddGlobalGuard(guard: GuardFn): void {\n\t\tthis._globalGuards.push(guard);\n\t}\n\n\t/** Remove a previously registered global guard by reference. */\n\tremoveGlobalGuard(guard: GuardFn): void {\n\t\tconst index = this._globalGuards.indexOf(guard);\n\t\tif (index !== -1) {\n\t\t\tthis._globalGuards.splice(index, 1);\n\t\t}\n\t}\n\n\t/**\n\t * Register an enter guard for a specific route.\n\t *\n\t * @param route - Route name as defined in `manifest.json`.\n\t * @param guard - Guard function to register.\n\t * @param before - A guard of the route to register `guard` in front of; at the end without it.\n\t */\n\taddEnterGuard(route: string, guard: GuardFn, before?: GuardFn): void {\n\t\tthis._addToGuardMap(this._enterGuards, route, guard, before);\n\t}\n\n\t/**\n\t * Remove a previously registered enter guard by reference.\n\t */\n\tremoveEnterGuard(route: string, guard: GuardFn): void {\n\t\tthis._removeFromGuardMap(this._enterGuards, route, guard);\n\t}\n\n\t/**\n\t * Register a leave guard for a specific route.\n\t *\n\t * Accepts `GuardFn` to support manifest-declared guards loaded from\n\t * untyped modules. Non-boolean return values are caught at runtime\n\t * by {@link _validateLeaveGuardResult}.\n\t *\n\t * @param route - Route name as defined in `manifest.json`.\n\t * @param guard - Guard function to register as a leave guard.\n\t * @param before - A leave guard of the route to register `guard` in front of; at the end without it.\n\t */\n\taddLeaveGuard(route: string, guard: GuardFn, before?: GuardFn): void {\n\t\tthis._addToGuardMap(this._leaveGuards, route, guard, before);\n\t}\n\n\t/**\n\t * Remove a previously registered leave guard by reference.\n\t */\n\tremoveLeaveGuard(route: string, guard: GuardFn): void {\n\t\tthis._removeFromGuardMap(this._leaveGuards, route, guard);\n\t}\n\n\t/**\n\t * Remove all registered guards.\n\t */\n\tclear(): void {\n\t\tthis._globalGuards = [];\n\t\tthis._enterGuards.clear();\n\t\tthis._leaveGuards.clear();\n\t}\n\n\t/**\n\t * Run the full guard pipeline (leave -> global enter -> route enter) and\n\t * return a normalized decision. Stays synchronous when all guards return\n\t * plain values; returns a Promise only when an async guard is encountered.\n\t *\n\t * @param context - Complete guard context including AbortSignal.\n\t * `context.fromRoute` controls leave-guard lookup: empty string skips leave guards.\n\t * @param options - Optional evaluation options.\n\t * @param options.skipLeaveGuards - When true, leave guards are skipped even if\n\t * `context.fromRoute` is set. Used by redirect chain hops to avoid re-running\n\t * leave guards while still preserving `fromRoute` in the context.\n\t * @param options.alsoLeaving - Greedy routes that are left as well: their leave guards run\n\t * after those of `context.fromRoute`, with the same context.\n\t * @param options.alsoEntering - Greedy routes that match as well: their enter guards run\n\t * after those of `context.toRoute`, with the same context.\n\t * @returns A synchronous {@link GuardDecision} when all guards return plain values,\n\t * or a `Promise<GuardDecision>` when at least one guard returns a thenable.\n\t */\n\tevaluate(\n\t\tcontext: GuardContext,\n\t\toptions?: { skipLeaveGuards?: boolean; alsoLeaving?: string[]; alsoEntering?: string[] },\n\t): GuardDecision | Promise<GuardDecision> {\n\t\t// No route is left on the first navigation, or after a hash that matched none.\n\t\tconst leaving =\n\t\t\toptions?.skipLeaveGuards || context.fromRoute === \"\"\n\t\t\t\t? []\n\t\t\t\t: [context.fromRoute, ...(options?.alsoLeaving ?? [])];\n\t\tconst entering = [context.toRoute, ...(options?.alsoEntering ?? [])];\n\n\t\tconst runEnterPhase = (): GuardDecision | Promise<GuardDecision> => {\n\t\t\tconst enterResult = this._runEnterGuards(entering, context);\n\t\t\treturn isPromiseLike(enterResult)\n\t\t\t\t? enterResult.then(toDecision).catch(toErrorDecision)\n\t\t\t\t: toDecision(enterResult);\n\t\t};\n\n\t\ttry {\n\t\t\tconst leaveResult = this._runForEach(leaving, context, (route) =>\n\t\t\t\tthis._runGuards(\n\t\t\t\t\tthis._leaveGuards.get(route) ?? [],\n\t\t\t\t\tcontext,\n\t\t\t\t\troute,\n\t\t\t\t\t(result) => this._validateLeaveGuardResult(result),\n\t\t\t\t\t\"Leave guard\",\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tif (isPromiseLike(leaveResult)) {\n\t\t\t\treturn leaveResult\n\t\t\t\t\t.then((allowed: GuardResult): GuardDecision | Promise<GuardDecision> => {\n\t\t\t\t\t\tif (allowed !== true) return { action: \"block\" };\n\t\t\t\t\t\tif (context.signal.aborted) return { action: \"block\" };\n\t\t\t\t\t\treturn runEnterPhase();\n\t\t\t\t\t})\n\t\t\t\t\t.catch(toErrorDecision);\n\t\t\t}\n\t\t\tif (leaveResult !== true) return { action: \"block\" };\n\n\t\t\treturn runEnterPhase();\n\t\t} catch (error) {\n\t\t\treturn toErrorDecision(error);\n\t\t}\n\t}\n\n\tprivate _addToGuardMap<T>(map: Map<string, T[]>, key: string, guard: T, before?: T): void {\n\t\tlet guards = map.get(key);\n\t\tif (!guards) {\n\t\t\tguards = [];\n\t\t\tmap.set(key, guards);\n\t\t}\n\t\tconst index = before === undefined ? -1 : guards.indexOf(before);\n\t\tif (index === -1) guards.push(guard);\n\t\telse guards.splice(index, 0, guard);\n\t}\n\n\tprivate _removeFromGuardMap<T>(map: Map<string, T[]>, key: string, guard: T): void {\n\t\tconst guards = map.get(key);\n\t\tif (!guards) return;\n\t\tconst index = guards.indexOf(guard);\n\t\tif (index !== -1) guards.splice(index, 1);\n\t\tif (guards.length === 0) map.delete(key);\n\t}\n\n\t/**\n\t * Run `run` for each route in order until one does not return `true`. Stays sync as long\n\t * as the runs do; after an async run the next one starts unless the navigation was aborted.\n\t */\n\tprivate _runForEach(\n\t\troutes: string[],\n\t\tcontext: GuardContext,\n\t\trun: (route: string) => GuardResult | Promise<GuardResult>,\n\t\tstart = 0,\n\t): GuardResult | Promise<GuardResult> {\n\t\tfor (let i = start; i < routes.length; i++) {\n\t\t\tconst result = run(routes[i]);\n\t\t\tif (isPromiseLike(result)) {\n\t\t\t\treturn result.then((settled: GuardResult) => {\n\t\t\t\t\tif (settled !== true) return settled;\n\t\t\t\t\tif (context.signal.aborted) return false;\n\t\t\t\t\treturn this._runForEach(routes, context, run, i + 1);\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (result !== true) return result;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** Run global guards, then the route-specific guards of each route in `entering`. Stays sync when possible. */\n\tprivate _runEnterGuards(entering: string[], context: GuardContext): GuardResult | Promise<GuardResult> {\n\t\tconst runRouteGuards = (): GuardResult | Promise<GuardResult> =>\n\t\t\tthis._runForEach(entering, context, (route) => this._runRouteGuards(route, context));\n\t\tconst globalResult = this._runGuards(\n\t\t\tthis._globalGuards,\n\t\t\tcontext,\n\t\t\tcontext.toRoute,\n\t\t\t(result) => this._validateGuardResult(result),\n\t\t\t\"Enter guard\",\n\t\t);\n\n\t\tif (isPromiseLike(globalResult)) {\n\t\t\treturn globalResult.then((result: GuardResult) => {\n\t\t\t\tif (result !== true) return result;\n\t\t\t\tif (context.signal.aborted) return false;\n\t\t\t\treturn runRouteGuards();\n\t\t\t});\n\t\t}\n\t\tif (globalResult !== true) return globalResult;\n\t\treturn runRouteGuards();\n\t}\n\n\t/** Run route-specific guards if any are registered. */\n\tprivate _runRouteGuards(toRoute: string, context: GuardContext): GuardResult | Promise<GuardResult> {\n\t\tconst guards = toRoute ? this._enterGuards.get(toRoute) : undefined;\n\t\tif (!guards) return true;\n\t\treturn this._runGuards(guards, context, toRoute, (result) => this._validateGuardResult(result), \"Enter guard\");\n\t}\n\n\t/**\n\t * Run guards sync; switch to async path if a Promise is returned. A result that is not\n\t * `true` ends the run with what `onBlock` makes of it.\n\t *\n\t * The guard array is snapshot-copied before iteration so that guards\n\t * may safely add/remove themselves (e.g. one-shot guards) without\n\t * affecting the current pipeline run.\n\t *\n\t * @param route - The route the guards are registered for, named in error logs.\n\t */\n\tprivate _runGuards<R extends GuardResult>(\n\t\tguards: GuardFn[],\n\t\tcontext: GuardContext,\n\t\troute: string,\n\t\tonBlock: (result: unknown) => R,\n\t\tlabel: string,\n\t): R | boolean | Promise<R | boolean> {\n\t\tguards = guards.slice();\n\t\tfor (let i = 0; i < guards.length; i++) {\n\t\t\ttry {\n\t\t\t\tconst result = guards[i](context);\n\t\t\t\tif (isPromiseLike(result)) {\n\t\t\t\t\treturn this._continueGuardsAsync(result, guards, i, context, onBlock, label, route);\n\t\t\t\t}\n\t\t\t\tif (result !== true) return onBlock(result);\n\t\t\t} catch (error) {\n\t\t\t\tif (context.signal.aborted) return false;\n\t\t\t\tLog.error(\n\t\t\t\t\t`${describeGuard(label, i, guards[i])} on route \"${route}\" threw, navigation failed`,\n\t\t\t\t\terror instanceof Error ? error : String(error),\n\t\t\t\t\tLOG_COMPONENT,\n\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Continue guard array async from the first Promise onward.\n\t *\n\t * Shared by both enter and leave guard pipelines. The `onBlock` callback\n\t * determines what to return for non-true results: leave guards always\n\t * return `false`, enter guards validate and may return redirects.\n\t *\n\t * @param route - The route the guards are registered for, named in error logs.\n\t */\n\tprivate async _continueGuardsAsync<R extends GuardResult>(\n\t\tpendingResult: PromiseLike<GuardResult>,\n\t\tguards: GuardFn[],\n\t\tcurrentIndex: number,\n\t\tcontext: GuardContext,\n\t\tonBlock: (result: unknown) => R,\n\t\tlabel: string,\n\t\troute: string,\n\t): Promise<R | boolean> {\n\t\tlet guardIndex = currentIndex;\n\t\ttry {\n\t\t\tconst result = await pendingResult;\n\t\t\tif (result !== true) return onBlock(result);\n\n\t\t\tfor (let i = currentIndex + 1; i < guards.length; i++) {\n\t\t\t\tif (context.signal.aborted) return false;\n\t\t\t\tguardIndex = i;\n\t\t\t\tconst nextResult = await guards[i](context);\n\t\t\t\tif (nextResult !== true) return onBlock(nextResult);\n\t\t\t}\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tif (!context.signal.aborted) {\n\t\t\t\tLog.error(\n\t\t\t\t\t`${describeGuard(label, guardIndex, guards[guardIndex])} on route \"${route}\" threw, navigation failed`,\n\t\t\t\t\terror instanceof Error ? error : String(error),\n\t\t\t\t\tLOG_COMPONENT,\n\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/** Validate a non-true guard result; invalid values become false. */\n\tprivate _validateGuardResult(result: unknown): GuardResult {\n\t\tif (typeof result === \"boolean\") return result;\n\t\tif (typeof result === \"string\" && result.length > 0) return result;\n\t\tif (isGuardRedirect(result)) return result;\n\t\tLog.warning(\"Guard returned invalid value, treating as block\", String(result), LOG_COMPONENT);\n\t\treturn false;\n\t}\n\n\t/** Validate a leave guard result; non-boolean values log a warning and block. */\n\tprivate _validateLeaveGuardResult(result: unknown): boolean {\n\t\tif (typeof result === \"boolean\") return result;\n\t\tLog.warning(\"Leave guard returned non-boolean value, treating as block\", String(result), LOG_COMPONENT);\n\t\treturn false;\n\t}\n}\n"],"mappings":";;;EAGA;EACO,MAAMA,aAAa,GAAG,yBAAyB;EAEtD,SAASC,eAAeA,CAACC,KAAc,EAA0B;IAChE,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,EAAE;MAChD,OAAO,KAAK;IACb;IAEA,OAAO,OAAO,IAAIA,KAAK,IAAI,OAAOA,KAAK,CAACC,KAAK,KAAK,QAAQ,IAAID,KAAK,CAACC,KAAK,CAACC,MAAM,GAAG,CAAC;EACrF;;EAEA;AACA;AACA;AACA;AACA;AACA;EACO,SAASC,aAAaA,CAAIH,KAAc,EAA2B;IACzE,IAAK,OAAOA,KAAK,KAAK,QAAQ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,MAAe,EAAW;MAC3D,IAAI,OAAOA,MAAM,KAAK,SAAS,EAAE,OAAOA,MAAM;MAC9C4D,GAAG,CAACO,OAAO,CAAC,2DAA2D,EAAEL,MAAM,CAAC9D,MAAM,CAAC,EAAE3B,aAAa,CAAC;MACvG,OAAO,KAAK;IACb;EACD;EAACgC,aAAA,CAAAhC,aAAA,GAAAA,aAAA;EAAAgC,aAAA,CAAA3B,aAAA,GAAAA,aAAA;EAAA2B,aAAA,CAAAlB,iBAAA,GAAAA,iBAAA;EAAAkB,aAAA,CAAAd,SAAA,GAAAA,SAAA;EAAA,OAAAc,aAAA;AAAA","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare module "ui5/guard/router/GuardPipeline" {
|
|
2
|
-
import type { GuardFn, GuardContext, GuardRedirect } from "ui5/guard/router/types";
|
|
3
|
-
|
|
2
|
+
import type { GuardFn, GuardContext, GuardResult, GuardRedirect } from "ui5/guard/router/types";
|
|
3
|
+
/** The component under which the library logs. */
|
|
4
|
+
export const LOG_COMPONENT = "ui5.guard.router.Router";
|
|
4
5
|
function isGuardRedirect(value: unknown): value is GuardRedirect;
|
|
5
6
|
/**
|
|
6
7
|
* Promises/A+ thenable detection via duck typing.
|
|
@@ -8,11 +9,27 @@ declare module "ui5/guard/router/GuardPipeline" {
|
|
|
8
9
|
* We intentionally do not use `instanceof Promise` because that misses
|
|
9
10
|
* cross-realm Promises and PromiseLike/thenable objects.
|
|
10
11
|
*/
|
|
11
|
-
function isPromiseLike<T>(value: unknown): value is PromiseLike<T>;
|
|
12
|
+
export function isPromiseLike<T>(value: unknown): value is PromiseLike<T>;
|
|
13
|
+
/** How this engine prints the resolve function of a Promise: `function () { [native code] }` in V8. */
|
|
14
|
+
let resolverSource: string;
|
|
15
|
+
/**
|
|
16
|
+
* Whether `value` looks exactly like the resolve function of a native Promise: a function with
|
|
17
|
+
* the name `""`, the length `1` and the source text that this engine prints for such a function.
|
|
18
|
+
* `Router#attachRouteMatched` needs this to recognize a UI5 component target that waits for the
|
|
19
|
+
* router. A function written in JavaScript never matches; other anonymous built-ins with one
|
|
20
|
+
* parameter do, above all the reject function of a Promise.
|
|
21
|
+
*/
|
|
22
|
+
export function isPromiseResolver(value: unknown): value is () => void;
|
|
23
|
+
/** Names of manifest guards, derived from their module, for log output. */
|
|
24
|
+
const guardNames: WeakMap<GuardFn, string>;
|
|
25
|
+
/** Give a guard a name that its log messages show. */
|
|
26
|
+
export function nameGuard(guard: GuardFn, name: string): void;
|
|
27
|
+
/** Describe a guard for log output: `Enter guard [0]`, or `Enter guard [0] "checks#0"` when it has a name. */
|
|
28
|
+
function describeGuard(label: string, index: number, guard: GuardFn): string;
|
|
12
29
|
/**
|
|
13
30
|
* Normalized result of the guard decision pipeline.
|
|
14
31
|
*/
|
|
15
|
-
type GuardDecision = {
|
|
32
|
+
export type GuardDecision = {
|
|
16
33
|
action: "allow";
|
|
17
34
|
} | {
|
|
18
35
|
action: "block";
|
|
@@ -23,15 +40,15 @@ declare module "ui5/guard/router/GuardPipeline" {
|
|
|
23
40
|
action: "error";
|
|
24
41
|
error: unknown;
|
|
25
42
|
};
|
|
43
|
+
function toDecision(result: GuardResult): GuardDecision;
|
|
44
|
+
function toErrorDecision(error: unknown): GuardDecision;
|
|
26
45
|
/**
|
|
27
46
|
* Standalone guard evaluation pipeline.
|
|
28
47
|
*
|
|
29
48
|
* Owns guard storage (global, enter, leave) and runs the full
|
|
30
|
-
* leave -> global-enter -> route-enter pipeline.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @namespace ui5.guard.router
|
|
49
|
+
* leave -> global-enter -> route-enter pipeline. It reads no Router
|
|
50
|
+
* state: evaluate() receives the context and the greedy routes left
|
|
51
|
+
* and entered with it.
|
|
35
52
|
*/
|
|
36
53
|
export default class GuardPipeline {
|
|
37
54
|
private _globalGuards;
|
|
@@ -46,13 +63,11 @@ declare module "ui5/guard/router/GuardPipeline" {
|
|
|
46
63
|
*
|
|
47
64
|
* @param route - Route name as defined in `manifest.json`.
|
|
48
65
|
* @param guard - Guard function to register.
|
|
66
|
+
* @param before - A guard of the route to register `guard` in front of; at the end without it.
|
|
49
67
|
*/
|
|
50
|
-
addEnterGuard(route: string, guard: GuardFn): void;
|
|
68
|
+
addEnterGuard(route: string, guard: GuardFn, before?: GuardFn): void;
|
|
51
69
|
/**
|
|
52
70
|
* Remove a previously registered enter guard by reference.
|
|
53
|
-
*
|
|
54
|
-
* @param route - Route name.
|
|
55
|
-
* @param guard - Guard function to remove.
|
|
56
71
|
*/
|
|
57
72
|
removeEnterGuard(route: string, guard: GuardFn): void;
|
|
58
73
|
/**
|
|
@@ -64,13 +79,11 @@ declare module "ui5/guard/router/GuardPipeline" {
|
|
|
64
79
|
*
|
|
65
80
|
* @param route - Route name as defined in `manifest.json`.
|
|
66
81
|
* @param guard - Guard function to register as a leave guard.
|
|
82
|
+
* @param before - A leave guard of the route to register `guard` in front of; at the end without it.
|
|
67
83
|
*/
|
|
68
|
-
addLeaveGuard(route: string, guard: GuardFn): void;
|
|
84
|
+
addLeaveGuard(route: string, guard: GuardFn, before?: GuardFn): void;
|
|
69
85
|
/**
|
|
70
86
|
* Remove a previously registered leave guard by reference.
|
|
71
|
-
*
|
|
72
|
-
* @param route - Route name.
|
|
73
|
-
* @param guard - Guard function to remove.
|
|
74
87
|
*/
|
|
75
88
|
removeLeaveGuard(route: string, guard: GuardFn): void;
|
|
76
89
|
/**
|
|
@@ -88,32 +101,38 @@ declare module "ui5/guard/router/GuardPipeline" {
|
|
|
88
101
|
* @param options.skipLeaveGuards - When true, leave guards are skipped even if
|
|
89
102
|
* `context.fromRoute` is set. Used by redirect chain hops to avoid re-running
|
|
90
103
|
* leave guards while still preserving `fromRoute` in the context.
|
|
104
|
+
* @param options.alsoLeaving - Greedy routes that are left as well: their leave guards run
|
|
105
|
+
* after those of `context.fromRoute`, with the same context.
|
|
106
|
+
* @param options.alsoEntering - Greedy routes that match as well: their enter guards run
|
|
107
|
+
* after those of `context.toRoute`, with the same context.
|
|
91
108
|
* @returns A synchronous {@link GuardDecision} when all guards return plain values,
|
|
92
109
|
* or a `Promise<GuardDecision>` when at least one guard returns a thenable.
|
|
93
110
|
*/
|
|
94
111
|
evaluate(context: GuardContext, options?: {
|
|
95
112
|
skipLeaveGuards?: boolean;
|
|
113
|
+
alsoLeaving?: string[];
|
|
114
|
+
alsoEntering?: string[];
|
|
96
115
|
}): GuardDecision | Promise<GuardDecision>;
|
|
97
116
|
private _addToGuardMap;
|
|
98
117
|
private _removeFromGuardMap;
|
|
99
118
|
/**
|
|
100
|
-
* Run
|
|
101
|
-
*
|
|
102
|
-
* The guard array is snapshot-copied before iteration so that guards
|
|
103
|
-
* may safely add/remove themselves (e.g. one-shot guards) without
|
|
104
|
-
* affecting the current pipeline run.
|
|
119
|
+
* Run `run` for each route in order until one does not return `true`. Stays sync as long
|
|
120
|
+
* as the runs do; after an async run the next one starts unless the navigation was aborted.
|
|
105
121
|
*/
|
|
106
|
-
private
|
|
107
|
-
/** Run global guards, then route-specific guards
|
|
122
|
+
private _runForEach;
|
|
123
|
+
/** Run global guards, then the route-specific guards of each route in `entering`. Stays sync when possible. */
|
|
108
124
|
private _runEnterGuards;
|
|
109
125
|
/** Run route-specific guards if any are registered. */
|
|
110
126
|
private _runRouteGuards;
|
|
111
127
|
/**
|
|
112
|
-
* Run guards sync; switch to async path if a Promise is returned.
|
|
128
|
+
* Run guards sync; switch to async path if a Promise is returned. A result that is not
|
|
129
|
+
* `true` ends the run with what `onBlock` makes of it.
|
|
113
130
|
*
|
|
114
131
|
* The guard array is snapshot-copied before iteration so that guards
|
|
115
132
|
* may safely add/remove themselves (e.g. one-shot guards) without
|
|
116
133
|
* affecting the current pipeline run.
|
|
134
|
+
*
|
|
135
|
+
* @param route - The route the guards are registered for, named in error logs.
|
|
117
136
|
*/
|
|
118
137
|
private _runGuards;
|
|
119
138
|
/**
|
|
@@ -123,7 +142,7 @@ declare module "ui5/guard/router/GuardPipeline" {
|
|
|
123
142
|
* determines what to return for non-true results: leave guards always
|
|
124
143
|
* return `false`, enter guards validate and may return redirects.
|
|
125
144
|
*
|
|
126
|
-
* @param
|
|
145
|
+
* @param route - The route the guards are registered for, named in error logs.
|
|
127
146
|
*/
|
|
128
147
|
private _continueGuardsAsync;
|
|
129
148
|
/** Validate a non-true guard result; invalid values become false. */
|