ui5-lib-guard-router 1.6.2 → 1.7.1
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 +197 -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 +125 -122
- 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 +900 -1033
- package/dist/resources/ui5/guard/router/Router-dbg.js.map +1 -1
- package/dist/resources/ui5/guard/router/Router.d.ts +362 -212
- 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 +158 -129
- package/src/NavigationOutcome.ts +3 -3
- package/src/PatternTree.ts +145 -0
- package/src/RouteMeta.ts +82 -0
- package/src/Router.ts +1110 -1150
- package/src/manifest.json +5 -2
- package/src/types.ts +79 -22
- package/tsconfig.json +0 -11
|
@@ -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. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GuardPipeline.d.ts","sourceRoot":"../../../../..","sources":["src/GuardPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,gCAAgC,CAAC;IAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"GuardPipeline.d.ts","sourceRoot":"../../../../..","sources":["src/GuardPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,gCAAgC,CAAC;IAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;IAEhG,kDAAkD;IAC3C,MAAM,aAAa,4BAA4B,CAAC;IAEvD,SAAS,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAM/D;IAED;;;;;OAKG;IACH,SAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,CAMxE;IAED,uGAAuG;IACvG,IAAI,cAAc,EAAG,MAAM,CAAC;IAK5B;;;;;;OAMG;IACH,SAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,IAAI,CAOrE;IAED,2EAA2E;IAC3E,MAAM,UAAU,0BAAiC,CAAC;IAElD,sDAAsD;IACtD,SAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAE5D;IAED,8GAA8G;IAC9G,SAAS,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAG3E;IAED;;OAEG;IACH,KAAY,aAAa,GACtB;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GACnB;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GACnB;QAAE,MAAM,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,GACtD;QAAE,MAAM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QAQ3B;;;WAGG;QACH,OAAO,CAAC,WAAW;QAoBnB,+GAA+G;QAC/G,OAAO,CAAC,eAAe;QAsBvB,uDAAuD;QACvD,OAAO,CAAC,eAAe;QAMvB;;;;;;;;;WASG;QACH,OAAO,CAAC,UAAU;QA4BlB;;;;;;;;WAQG;gBACW,oBAAoB;QAoClC,qEAAqE;QACrE,OAAO,CAAC,oBAAoB;QAQ5B,iFAAiF;QACjF,OAAO,CAAC,yBAAyB;KAKjC;CAEA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
sap.ui.define(["sap/base/Log"],function(r){"use strict";const e="ui5.guard.router.Router";function t(r){if(typeof r!=="object"||r===null){return false}
|
|
1
|
+
sap.ui.define(["sap/base/Log"],function(r){"use strict";const e="ui5.guard.router.Router";function t(r){if(typeof r!=="object"||r===null){return false}return"route"in r&&typeof r.route==="string"&&r.route.length>0}function n(r){if(typeof r!=="object"&&typeof r!=="function"||r===null){return false}return"then"in r&&typeof r.then==="function"}let a;void new Promise(r=>{a=Function.prototype.toString.call(r)});function u(r){return typeof r==="function"&&r.name===""&&r.length===1&&Function.prototype.toString.call(r)===a}const i=new WeakMap;function o(r,e){i.set(r,e)}function s(r,e,t){const n=i.get(t);return n===undefined?`${r} [${e}]`:`${r} [${e}] "${n}"`}function l(r){if(r===true)return{action:"allow"};if(r===false)return{action:"block"};return{action:"redirect",target:r}}function d(r){return{action:"error",error:r}}class f{_globalGuards=[];_enterGuards=new Map;_leaveGuards=new Map;addGlobalGuard(r){this._globalGuards.push(r)}removeGlobalGuard(r){const e=this._globalGuards.indexOf(r);if(e!==-1){this._globalGuards.splice(e,1)}}addEnterGuard(r,e,t){this._addToGuardMap(this._enterGuards,r,e,t)}removeEnterGuard(r,e){this._removeFromGuardMap(this._enterGuards,r,e)}addLeaveGuard(r,e,t){this._addToGuardMap(this._leaveGuards,r,e,t)}removeLeaveGuard(r,e){this._removeFromGuardMap(this._leaveGuards,r,e)}clear(){this._globalGuards=[];this._enterGuards.clear();this._leaveGuards.clear()}evaluate(r,e){const t=e?.skipLeaveGuards||r.fromRoute===""?[]:[r.fromRoute,...e?.alsoLeaving??[]];const a=[r.toRoute,...e?.alsoEntering??[]];const u=()=>{const e=this._runEnterGuards(a,r);return n(e)?e.then(l).catch(d):l(e)};try{const e=this._runForEach(t,r,e=>this._runGuards(this._leaveGuards.get(e)??[],r,e,r=>this._validateLeaveGuardResult(r),"Leave guard"));if(n(e)){return e.then(e=>{if(e!==true)return{action:"block"};if(r.signal.aborted)return{action:"block"};return u()}).catch(d)}if(e!==true)return{action:"block"};return u()}catch(r){return d(r)}}_addToGuardMap(r,e,t,n){let a=r.get(e);if(!a){a=[];r.set(e,a)}const u=n===undefined?-1:a.indexOf(n);if(u===-1)a.push(t);else a.splice(u,0,t)}_removeFromGuardMap(r,e,t){const n=r.get(e);if(!n)return;const a=n.indexOf(t);if(a!==-1)n.splice(a,1);if(n.length===0)r.delete(e)}_runForEach(r,e,t,a=0){for(let u=a;u<r.length;u++){const a=t(r[u]);if(n(a)){return a.then(n=>{if(n!==true)return n;if(e.signal.aborted)return false;return this._runForEach(r,e,t,u+1)})}if(a!==true)return a}return true}_runEnterGuards(r,e){const t=()=>this._runForEach(r,e,r=>this._runRouteGuards(r,e));const a=this._runGuards(this._globalGuards,e,e.toRoute,r=>this._validateGuardResult(r),"Enter guard");if(n(a)){return a.then(r=>{if(r!==true)return r;if(e.signal.aborted)return false;return t()})}if(a!==true)return a;return t()}_runRouteGuards(r,e){const t=r?this._enterGuards.get(r):undefined;if(!t)return true;return this._runGuards(t,e,r,r=>this._validateGuardResult(r),"Enter guard")}_runGuards(t,a,u,i,o){t=t.slice();for(let l=0;l<t.length;l++){try{const r=t[l](a);if(n(r)){return this._continueGuardsAsync(r,t,l,a,i,o,u)}if(r!==true)return i(r)}catch(n){if(a.signal.aborted)return false;r.error(`${s(o,l,t[l])} on route "${u}" threw, navigation failed`,n instanceof Error?n:String(n),e);throw n}}return true}async _continueGuardsAsync(t,n,a,u,i,o,l){let d=a;try{const r=await t;if(u.signal.aborted)return false;if(r!==true)return i(r);for(let r=a+1;r<n.length;r++){d=r;const e=await n[r](u);if(u.signal.aborted)return false;if(e!==true)return i(e)}return true}catch(t){if(!u.signal.aborted){r.error(`${s(o,d,n[d])} on route "${l}" threw, navigation failed`,t instanceof Error?t:String(t),e);throw t}return false}}_validateGuardResult(n){if(typeof n==="boolean")return n;if(typeof n==="string"&&n.length>0)return n;if(t(n))return n;r.warning("Guard returned invalid value, treating as block",String(n),e);return false}_validateLeaveGuardResult(t){if(typeof t==="boolean")return t;r.warning("Leave guard returned non-boolean value, treating as block",String(t),e);return false}}f.LOG_COMPONENT=e;f.isPromiseLike=n;f.isPromiseResolver=u;f.nameGuard=o;return f});
|
|
2
2
|
//# sourceMappingURL=GuardPipeline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GuardPipeline.js","names":["LOG_COMPONENT","isGuardRedirect","value","route","length","isPromiseLike","then","GuardPipeline","_globalGuards","_enterGuards","Map","_leaveGuards","addGlobalGuard","guard","this","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":"wDAGA,MAAMA,EAAgB,0BAEtB,SAASC,EAAgBC,GACxB,UAAWA,IAAU,UAAYA,IAAU,KAAM,CAChD,OAAO,KACR,CAEA,MAAMC,MAAEA,GAAUD,EAClB,cAAcC,IAAU,UAAYA,EAAMC,OAAS,CACpD,CAQO,SAASC,EAAiBH,GAChC,UAAYA,IAAU,iBAAmBA,IAAU,YAAeA,IAAU,KAAM,CACjF,OAAO,KACR,CAEA,cAAeA,EAAyBI,OAAS,UAClD,CAqBe,MAAMC,EACZC,cAA2B,GAC3BC,aAAe,IAAIC,IACnBC,aAAe,IAAID,IAG3BE,eAAeC,GACdC,KAAKN,cAAcO,KAAKF,EACzB,CAGAG,kBAAkBH,GACjB,MAAMI,EAAQH,KAAKN,cAAcU,QAAQL,GACzC,GAAII,KAAW,EAAG,CACjBH,KAAKN,cAAcW,OAAOF,EAAO,EAClC,CACD,CAQAG,cAAcjB,EAAeU,GAC5BC,KAAKO,eAAeP,KAAKL,aAAcN,EAAOU,EAC/C,CAQAS,iBAAiBnB,EAAeU,GAC/BC,KAAKS,oBAAoBT,KAAKL,aAAcN,EAAOU,EACpD,CAYAW,cAAcrB,EAAeU,GAC5BC,KAAKO,eAAeP,KAAKH,aAAcR,EAAOU,EAC/C,CAQAY,iBAAiBtB,EAAeU,GAC/BC,KAAKS,oBAAoBT,KAAKH,aAAcR,E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ACR,CAAE,MAAOlC,GACR,IAAKd,EAAQoB,OAAOC,QAAS,CAC5B,MAAM9C,EAAQuE,EAAe9C,EAAQI,UAAYJ,EAAQO,QACzD4B,EAAIrB,MACH,GAAG+B,MAAUE,gBAAyBxE,8BACtCuC,aAAiBsB,MAAQtB,EAAQuB,OAAOvB,GACxC1C,GAED,MAAM0C,CACP,CACA,OAAO,KACR,CACD,CAGQ2B,qBAAqBV,GAC5B,UAAWA,IAAW,UAAW,OAAOA,EACxC,UAAWA,IAAW,UAAYA,EAAOvD,OAAS,EAAG,OAAOuD,EAC5D,GAAI1D,EAAgB0D,GAAS,OAAOA,EACpCI,EAAIc,QAAQ,kDAAmDZ,OAAON,GAAS3D,GAC/E,OAAO,KACR,CAGQ8D,0BAA0BH,GACjC,UAAWA,IAAW,UAAW,OAAOA,EACxCI,EAAIc,QAAQ,4DAA6DZ,OAAON,GAAS3D,GACzF,OAAO,KACR,EACAO,EAAAF,gBAAA,OAAAE,CAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"GuardPipeline.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","this","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"],"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\t// An aborted navigation discards the result: it is neither validated nor followed by the next guard.\n\t\t\tconst result = await pendingResult;\n\t\t\tif (context.signal.aborted) return false;\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\tguardIndex = i;\n\t\t\t\tconst nextResult = await guards[i](context);\n\t\t\t\tif (context.signal.aborted) return false;\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":"wDAIO,MAAMA,EAAgB,0BAE7B,SAASC,EAAgBC,GACxB,UAAWA,IAAU,UAAY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QS,EACzC,CACA,OAAO,IACR,CAAE,MAAO/D,GACR,IAAKqB,EAAQkB,OAAOC,QAAS,CAC5BiB,EAAIzD,MACH,GAAGV,EAAcC,EAAOuE,EAAYnB,EAAOmB,iBAA0B1F,8BACrE4B,aAAiB0D,MAAQ1D,EAAQ2D,OAAO3D,GACxC/B,GAED,MAAM+B,CACP,CACA,OAAO,KACR,CACD,CAGQqD,qBAAqBzD,GAC5B,UAAWA,IAAW,UAAW,OAAOA,EACxC,UAAWA,IAAW,UAAYA,EAAOvB,OAAS,EAAG,OAAOuB,EAC5D,GAAI1B,EAAgB0B,GAAS,OAAOA,EACpC6D,EAAIO,QAAQ,kDAAmDL,OAAO/D,GAAS3B,GAC/E,OAAO,KACR,CAGQoE,0BAA0BzC,GACjC,UAAWA,IAAW,UAAW,OAAOA,EACxC6D,EAAIO,QAAQ,4DAA6DL,OAAO/D,GAAS3B,GACzF,OAAO,KACR,EACAgC,EAAAhC,gBAAAgC,EAAA3B,gBAAA2B,EAAAlB,oBAAAkB,EAAAd,YAAA,OAAAc,CAAA","ignoreList":[]}
|
|
@@ -17,13 +17,13 @@ sap.ui.define([], function () {
|
|
|
17
17
|
Committed: "committed",
|
|
18
18
|
/** Navigation was allowed, but no route matched; UI5 continued with bypassed handling. @since 1.3.0 */
|
|
19
19
|
Bypassed: "bypassed",
|
|
20
|
-
/** A guard blocked navigation; the previous route remains active. @since 1.2.0 */
|
|
20
|
+
/** A guard blocked navigation, or the hash changer refused the hash change; the previous route remains active. @since 1.2.0 */
|
|
21
21
|
Blocked: "blocked",
|
|
22
|
-
/** A guard redirected navigation to a different route. @since 1.2.0 */
|
|
22
|
+
/** A guard redirected navigation to a different route, or to the route that is displayed, which then does not match again. @since 1.2.0 */
|
|
23
23
|
Redirected: "redirected",
|
|
24
24
|
/** Navigation was cancelled before settling (superseded, stopped, or destroyed). @since 1.2.0 */
|
|
25
25
|
Cancelled: "cancelled",
|
|
26
|
-
/** A guard threw or rejected; the previous route remains active. @since 1.4.0 */
|
|
26
|
+
/** A guard threw or rejected, a redirect target had no valid hash, or applying the decision failed; the previous route remains active. @since 1.4.0 */
|
|
27
27
|
Error: "error"
|
|
28
28
|
});
|
|
29
29
|
return NavigationOutcome;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationOutcome-dbg.js","names":["NavigationOutcome","Object","freeze","Committed","Bypassed","Blocked","Redirected","Cancelled","Error"],"sources":["NavigationOutcome.ts"],"sourcesContent":["/**\n * Outcome of a navigation after the guard pipeline settles.\n *\n * Registered as a UI5 enum via `library.ts` so that it is discoverable\n * through `sap.ui.base.DataType.getType()`. Application code can import\n * the value object directly.\n *\n * @enum {string}\n * @namespace ui5.guard.router\n * @since 1.2.0\n */\nconst NavigationOutcome = Object.freeze({\n\t/** Navigation was allowed and the target route activated. @since 1.2.0 */\n\tCommitted: \"committed\",\n\t/** Navigation was allowed, but no route matched; UI5 continued with bypassed handling. @since 1.3.0 */\n\tBypassed: \"bypassed\",\n\t/** A guard blocked navigation; the previous route remains active. @since 1.2.0 */\n\tBlocked: \"blocked\",\n\t/** A guard redirected navigation to a different route. @since 1.2.0 */\n\tRedirected: \"redirected\",\n\t/** Navigation was cancelled before settling (superseded, stopped, or destroyed). @since 1.2.0 */\n\tCancelled: \"cancelled\",\n\t/** A guard threw or rejected; the previous route remains active. @since 1.4.0 */\n\tError: \"error\",\n});\n\ntype NavigationOutcome = (typeof NavigationOutcome)[keyof typeof NavigationOutcome];\n\nexport default NavigationOutcome;\n"],"mappings":";;;EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACA,MAAMA,iBAAiB,GAAGC,MAAM,CAACC,MAAM,CAAC;IACvC;IACAC,SAAS,EAAE,WAAW;IACtB;IACAC,QAAQ,EAAE,UAAU;IACpB;IACAC,OAAO,EAAE,SAAS;IAClB;IACAC,UAAU,EAAE,YAAY;IACxB;IACAC,SAAS,EAAE,WAAW;IACtB;IACAC,KAAK,EAAE;EACR,CAAC,CAAC;EAAC,OAIYR,iBAAiB;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"NavigationOutcome-dbg.js","names":["NavigationOutcome","Object","freeze","Committed","Bypassed","Blocked","Redirected","Cancelled","Error"],"sourceRoot":"./","sources":["NavigationOutcome.ts"],"sourcesContent":["/**\n * Outcome of a navigation after the guard pipeline settles.\n *\n * Registered as a UI5 enum via `library.ts` so that it is discoverable\n * through `sap.ui.base.DataType.getType()`. Application code can import\n * the value object directly.\n *\n * @enum {string}\n * @namespace ui5.guard.router\n * @since 1.2.0\n */\nconst NavigationOutcome = Object.freeze({\n\t/** Navigation was allowed and the target route activated. @since 1.2.0 */\n\tCommitted: \"committed\",\n\t/** Navigation was allowed, but no route matched; UI5 continued with bypassed handling. @since 1.3.0 */\n\tBypassed: \"bypassed\",\n\t/** A guard blocked navigation, or the hash changer refused the hash change; the previous route remains active. @since 1.2.0 */\n\tBlocked: \"blocked\",\n\t/** A guard redirected navigation to a different route, or to the route that is displayed, which then does not match again. @since 1.2.0 */\n\tRedirected: \"redirected\",\n\t/** Navigation was cancelled before settling (superseded, stopped, or destroyed). @since 1.2.0 */\n\tCancelled: \"cancelled\",\n\t/** A guard threw or rejected, a redirect target had no valid hash, or applying the decision failed; the previous route remains active. @since 1.4.0 */\n\tError: \"error\",\n});\n\ntype NavigationOutcome = (typeof NavigationOutcome)[keyof typeof NavigationOutcome];\n\nexport default NavigationOutcome;\n"],"mappings":";;;EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACA,MAAMA,iBAAiB,GAAGC,MAAM,CAACC,MAAM,CAAC;IACvC;IACAC,SAAS,EAAE,WAAW;IACtB;IACAC,QAAQ,EAAE,UAAU;IACpB;IACAC,OAAO,EAAE,SAAS;IAClB;IACAC,UAAU,EAAE,YAAY;IACxB;IACAC,SAAS,EAAE,WAAW;IACtB;IACAC,KAAK,EAAE;EACR,CAAC,CAAC;EAAC,OAIYR,iBAAiB;AAAA","ignoreList":[]}
|
|
@@ -15,13 +15,13 @@ declare module "ui5/guard/router/NavigationOutcome" {
|
|
|
15
15
|
Committed: "committed";
|
|
16
16
|
/** Navigation was allowed, but no route matched; UI5 continued with bypassed handling. @since 1.3.0 */
|
|
17
17
|
Bypassed: "bypassed";
|
|
18
|
-
/** A guard blocked navigation; the previous route remains active. @since 1.2.0 */
|
|
18
|
+
/** A guard blocked navigation, or the hash changer refused the hash change; the previous route remains active. @since 1.2.0 */
|
|
19
19
|
Blocked: "blocked";
|
|
20
|
-
/** A guard redirected navigation to a different route. @since 1.2.0 */
|
|
20
|
+
/** A guard redirected navigation to a different route, or to the route that is displayed, which then does not match again. @since 1.2.0 */
|
|
21
21
|
Redirected: "redirected";
|
|
22
22
|
/** Navigation was cancelled before settling (superseded, stopped, or destroyed). @since 1.2.0 */
|
|
23
23
|
Cancelled: "cancelled";
|
|
24
|
-
/** A guard threw or rejected; the previous route remains active. @since 1.4.0 */
|
|
24
|
+
/** A guard threw or rejected, a redirect target had no valid hash, or applying the decision failed; the previous route remains active. @since 1.4.0 */
|
|
25
25
|
Error: "error";
|
|
26
26
|
}>;
|
|
27
27
|
type NavigationOutcome = (typeof NavigationOutcome)[keyof typeof NavigationOutcome];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationOutcome.d.ts","sourceRoot":"../../../../..","sources":["src/NavigationOutcome.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,oCAAoC,CAAC;IACpD;;;;;;;;;;OAUG;IACH,MAAM,iBAAiB;QACtB,0EAA0E;;QAE1E,uGAAuG;;QAEvG
|
|
1
|
+
{"version":3,"file":"NavigationOutcome.d.ts","sourceRoot":"../../../../..","sources":["src/NavigationOutcome.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,oCAAoC,CAAC;IACpD;;;;;;;;;;OAUG;IACH,MAAM,iBAAiB;QACtB,0EAA0E;;QAE1E,uGAAuG;;QAEvG,+HAA+H;;QAE/H,2IAA2I;;QAE3I,iGAAiG;;QAEjG,uJAAuJ;;MAEtJ,CAAC;IAEH,KAAK,iBAAiB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;IAEpF,eAAe,iBAAiB,CAAC;CAEhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationOutcome.js","names":["NavigationOutcome","Object","freeze","Committed","Bypassed","Blocked","Redirected","Cancelled","Error"],"sources":["NavigationOutcome.ts"],"sourcesContent":["/**\n * Outcome of a navigation after the guard pipeline settles.\n *\n * Registered as a UI5 enum via `library.ts` so that it is discoverable\n * through `sap.ui.base.DataType.getType()`. Application code can import\n * the value object directly.\n *\n * @enum {string}\n * @namespace ui5.guard.router\n * @since 1.2.0\n */\nconst NavigationOutcome = Object.freeze({\n\t/** Navigation was allowed and the target route activated. @since 1.2.0 */\n\tCommitted: \"committed\",\n\t/** Navigation was allowed, but no route matched; UI5 continued with bypassed handling. @since 1.3.0 */\n\tBypassed: \"bypassed\",\n\t/** A guard blocked navigation; the previous route remains active. @since 1.2.0 */\n\tBlocked: \"blocked\",\n\t/** A guard redirected navigation to a different route. @since 1.2.0 */\n\tRedirected: \"redirected\",\n\t/** Navigation was cancelled before settling (superseded, stopped, or destroyed). @since 1.2.0 */\n\tCancelled: \"cancelled\",\n\t/** A guard threw or rejected; the previous route remains active. @since 1.4.0 */\n\tError: \"error\",\n});\n\ntype NavigationOutcome = (typeof NavigationOutcome)[keyof typeof NavigationOutcome];\n\nexport default NavigationOutcome;\n"],"mappings":"yCAWA,MAAMA,EAAoBC,OAAOC,OAAO,CAEvCC,UAAW,YAEXC,SAAU,WAEVC,QAAS,UAETC,WAAY,aAEZC,UAAW,YAEXC,MAAO,UACL,OAIYR,CAAiB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"NavigationOutcome.js","names":["NavigationOutcome","Object","freeze","Committed","Bypassed","Blocked","Redirected","Cancelled","Error"],"sources":["./NavigationOutcome.ts"],"sourcesContent":["/**\n * Outcome of a navigation after the guard pipeline settles.\n *\n * Registered as a UI5 enum via `library.ts` so that it is discoverable\n * through `sap.ui.base.DataType.getType()`. Application code can import\n * the value object directly.\n *\n * @enum {string}\n * @namespace ui5.guard.router\n * @since 1.2.0\n */\nconst NavigationOutcome = Object.freeze({\n\t/** Navigation was allowed and the target route activated. @since 1.2.0 */\n\tCommitted: \"committed\",\n\t/** Navigation was allowed, but no route matched; UI5 continued with bypassed handling. @since 1.3.0 */\n\tBypassed: \"bypassed\",\n\t/** A guard blocked navigation, or the hash changer refused the hash change; the previous route remains active. @since 1.2.0 */\n\tBlocked: \"blocked\",\n\t/** A guard redirected navigation to a different route, or to the route that is displayed, which then does not match again. @since 1.2.0 */\n\tRedirected: \"redirected\",\n\t/** Navigation was cancelled before settling (superseded, stopped, or destroyed). @since 1.2.0 */\n\tCancelled: \"cancelled\",\n\t/** A guard threw or rejected, a redirect target had no valid hash, or applying the decision failed; the previous route remains active. @since 1.4.0 */\n\tError: \"error\",\n});\n\ntype NavigationOutcome = (typeof NavigationOutcome)[keyof typeof NavigationOutcome];\n\nexport default NavigationOutcome;\n"],"mappings":"yCAWA,MAAMA,EAAoBC,OAAOC,OAAO,CAEvCC,UAAW,YAEXC,SAAU,WAEVC,QAAS,UAETC,WAAY,aAEZC,UAAW,YAEXC,MAAO,UACL,OAIYR,CAAiB","ignoreList":[]}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
sap.ui.define([], function () {
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pattern-tree helpers: compare UI5 route patterns by their mandatory path segments.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Matches a standalone optional (`:param:`) or rest (`:param*:`) segment. */
|
|
9
|
+
const OPTIONAL_OR_REST_SEGMENT = /^:[^:]*:$/;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Strips inline query and optional-query suffixes from a segment.
|
|
13
|
+
*
|
|
14
|
+
* UI5 (crossroads.js) allows query parameters to attach directly to a
|
|
15
|
+
* path segment without a `/` separator:
|
|
16
|
+
* - `product{?query}` → mandatory query on `product`
|
|
17
|
+
* - `product:?query:` → optional query on `product`
|
|
18
|
+
* - `{id}{?query}` → mandatory param + mandatory query
|
|
19
|
+
*
|
|
20
|
+
* For pattern-tree ancestry we only care about the path portion,
|
|
21
|
+
* so these suffixes are stripped.
|
|
22
|
+
*/
|
|
23
|
+
function stripInlineQuery(seg) {
|
|
24
|
+
const mqIdx = seg.indexOf("{?");
|
|
25
|
+
if (mqIdx !== -1) return seg.slice(0, mqIdx);
|
|
26
|
+
const oqIdx = seg.indexOf(":?");
|
|
27
|
+
if (oqIdx !== -1) return seg.slice(0, oqIdx);
|
|
28
|
+
return seg;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extract mandatory path segments from a UI5 route pattern.
|
|
33
|
+
*
|
|
34
|
+
* Splits on `/`, strips inline query suffixes, then drops empty segments,
|
|
35
|
+
* standalone optional (`:param:`), and rest (`:param*:`) segments.
|
|
36
|
+
*/
|
|
37
|
+
function patternSegments(pattern) {
|
|
38
|
+
return pattern.split("/").map(stripInlineQuery).filter(seg => seg !== "" && !OPTIONAL_OR_REST_SEGMENT.test(seg));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if `ancestorPattern` is a URL-tree ancestor of `candidatePattern`.
|
|
43
|
+
*
|
|
44
|
+
* Both patterns are reduced to their mandatory path segments and compared
|
|
45
|
+
* positionally. Mandatory parameter segments (`{paramA}`, `{paramB}`) are
|
|
46
|
+
* treated as equivalent regardless of name, so `employees/{empId}` is
|
|
47
|
+
* recognized as an ancestor of `employees/{id}/resume`.
|
|
48
|
+
*/
|
|
49
|
+
function isPatternAncestor(ancestorPattern, candidatePattern) {
|
|
50
|
+
if (ancestorPattern === "") return true;
|
|
51
|
+
const ancestorSegments = patternSegments(ancestorPattern);
|
|
52
|
+
if (ancestorSegments.length === 0) return false;
|
|
53
|
+
const candidateSegments = patternSegments(candidatePattern);
|
|
54
|
+
if (candidateSegments.length <= ancestorSegments.length) return false;
|
|
55
|
+
return ancestorSegments.every((seg, i) => {
|
|
56
|
+
const candidateSeg = candidateSegments[i];
|
|
57
|
+
if (seg === candidateSeg) return true;
|
|
58
|
+
return seg.startsWith("{") && candidateSeg.startsWith("{");
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A route name with its pattern. */
|
|
63
|
+
|
|
64
|
+
/** Number of mandatory segments in the pattern of `route` (0 when unknown). */
|
|
65
|
+
function depthOf(route, patternByName) {
|
|
66
|
+
return patternSegments(patternByName.get(route) ?? "").length;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Entries ordered by the pattern depth of their own route, declaration order within one depth.
|
|
71
|
+
* Expanding them in this order puts an ancestor's entries before a descendant's on every route.
|
|
72
|
+
*/
|
|
73
|
+
function byRouteDepth(entries, patternByName) {
|
|
74
|
+
return entries.toSorted((a, b) => depthOf(a.route, patternByName) - depthOf(b.route, patternByName));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Copy each route-specific entry to every descendant route (`inheritance: "pattern-tree"`).
|
|
79
|
+
* Global (`"*"`) entries and entries for routes without a known pattern are kept as-is.
|
|
80
|
+
* Ordered by the pattern depth of the route an entry was declared for, so on every route
|
|
81
|
+
* ancestor guards run before descendant guards, whatever the declaration order. Where global
|
|
82
|
+
* entries end up does not matter: the pipeline runs global guards separately.
|
|
83
|
+
* A route named `"*"` does not pass its entries on, because a `"*"` entry is a global one.
|
|
84
|
+
*/
|
|
85
|
+
function expandToDescendants(entries, routes) {
|
|
86
|
+
if (routes.length === 0) return entries;
|
|
87
|
+
const patternByName = new Map(routes.map(r => [r.name, r.pattern]));
|
|
88
|
+
const expanded = [];
|
|
89
|
+
for (const entry of byRouteDepth(entries, patternByName)) {
|
|
90
|
+
expanded.push(entry);
|
|
91
|
+
if (entry.route === "*") continue;
|
|
92
|
+
const ancestorPattern = patternByName.get(entry.route);
|
|
93
|
+
if (ancestorPattern === undefined) continue;
|
|
94
|
+
for (const {
|
|
95
|
+
name,
|
|
96
|
+
pattern
|
|
97
|
+
} of routes) {
|
|
98
|
+
if (name !== entry.route && isPatternAncestor(ancestorPattern, pattern)) {
|
|
99
|
+
expanded.push({
|
|
100
|
+
...entry,
|
|
101
|
+
route: name
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return expanded;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Entries a newly added route inherits (`inheritance: "pattern-tree"`): copies of its
|
|
111
|
+
* ancestors' entries for the new route, and copies of its own entries for its existing
|
|
112
|
+
* descendants. `routes` must include the new route. Ordered like {@link expandToDescendants};
|
|
113
|
+
* where the entries go among those a route has already is up to the caller.
|
|
114
|
+
*/
|
|
115
|
+
function expandForNewRoute(entries, newName, routes) {
|
|
116
|
+
const patternByName = new Map(routes.map(r => [r.name, r.pattern]));
|
|
117
|
+
const newPattern = patternByName.get(newName);
|
|
118
|
+
if (newPattern === undefined) return [];
|
|
119
|
+
const result = [];
|
|
120
|
+
for (const entry of byRouteDepth(entries, patternByName)) {
|
|
121
|
+
if (entry.route === "*") continue;
|
|
122
|
+
if (entry.route === newName) {
|
|
123
|
+
for (const {
|
|
124
|
+
name,
|
|
125
|
+
pattern
|
|
126
|
+
} of routes) {
|
|
127
|
+
if (name !== newName && isPatternAncestor(newPattern, pattern)) {
|
|
128
|
+
result.push({
|
|
129
|
+
...entry,
|
|
130
|
+
route: name
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
const ancestorPattern = patternByName.get(entry.route);
|
|
136
|
+
if (ancestorPattern !== undefined && isPatternAncestor(ancestorPattern, newPattern)) {
|
|
137
|
+
result.push({
|
|
138
|
+
...entry,
|
|
139
|
+
route: newName
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
var __exports = {
|
|
147
|
+
__esModule: true
|
|
148
|
+
};
|
|
149
|
+
__exports.patternSegments = patternSegments;
|
|
150
|
+
__exports.isPatternAncestor = isPatternAncestor;
|
|
151
|
+
__exports.byRouteDepth = byRouteDepth;
|
|
152
|
+
__exports.expandToDescendants = expandToDescendants;
|
|
153
|
+
__exports.expandForNewRoute = expandForNewRoute;
|
|
154
|
+
return __exports;
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=PatternTree-dbg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PatternTree-dbg.js","names":["OPTIONAL_OR_REST_SEGMENT","stripInlineQuery","seg","mqIdx","indexOf","slice","oqIdx","patternSegments","pattern","split","map","filter","test","isPatternAncestor","ancestorPattern","candidatePattern","ancestorSegments","length","candidateSegments","every","i","candidateSeg","startsWith","depthOf","route","patternByName","get","byRouteDepth","entries","toSorted","a","b","expandToDescendants","routes","Map","r","name","expanded","entry","push","undefined","expandForNewRoute","newName","newPattern","result","__exports","__esModule"],"sourceRoot":"./","sources":["PatternTree.ts"],"sourcesContent":["/**\n * Pattern-tree helpers: compare UI5 route patterns by their mandatory path segments.\n */\n\n/** Matches a standalone optional (`:param:`) or rest (`:param*:`) segment. */\nconst OPTIONAL_OR_REST_SEGMENT = /^:[^:]*:$/;\n\n/**\n * Strips inline query and optional-query suffixes from a segment.\n *\n * UI5 (crossroads.js) allows query parameters to attach directly to a\n * path segment without a `/` separator:\n * - `product{?query}` → mandatory query on `product`\n * - `product:?query:` → optional query on `product`\n * - `{id}{?query}` → mandatory param + mandatory query\n *\n * For pattern-tree ancestry we only care about the path portion,\n * so these suffixes are stripped.\n */\nfunction stripInlineQuery(seg: string): string {\n\tconst mqIdx = seg.indexOf(\"{?\");\n\tif (mqIdx !== -1) return seg.slice(0, mqIdx);\n\tconst oqIdx = seg.indexOf(\":?\");\n\tif (oqIdx !== -1) return seg.slice(0, oqIdx);\n\treturn seg;\n}\n\n/**\n * Extract mandatory path segments from a UI5 route pattern.\n *\n * Splits on `/`, strips inline query suffixes, then drops empty segments,\n * standalone optional (`:param:`), and rest (`:param*:`) segments.\n */\nexport function patternSegments(pattern: string): string[] {\n\treturn pattern\n\t\t.split(\"/\")\n\t\t.map(stripInlineQuery)\n\t\t.filter((seg) => seg !== \"\" && !OPTIONAL_OR_REST_SEGMENT.test(seg));\n}\n\n/**\n * Check if `ancestorPattern` is a URL-tree ancestor of `candidatePattern`.\n *\n * Both patterns are reduced to their mandatory path segments and compared\n * positionally. Mandatory parameter segments (`{paramA}`, `{paramB}`) are\n * treated as equivalent regardless of name, so `employees/{empId}` is\n * recognized as an ancestor of `employees/{id}/resume`.\n */\nexport function isPatternAncestor(ancestorPattern: string, candidatePattern: string): boolean {\n\tif (ancestorPattern === \"\") return true;\n\tconst ancestorSegments = patternSegments(ancestorPattern);\n\tif (ancestorSegments.length === 0) return false;\n\tconst candidateSegments = patternSegments(candidatePattern);\n\tif (candidateSegments.length <= ancestorSegments.length) return false;\n\treturn ancestorSegments.every((seg, i) => {\n\t\tconst candidateSeg = candidateSegments[i];\n\t\tif (seg === candidateSeg) return true;\n\t\treturn seg.startsWith(\"{\") && candidateSeg.startsWith(\"{\");\n\t});\n}\n\n/** A route name with its pattern. */\nexport interface RoutePattern {\n\treadonly name: string;\n\treadonly pattern: string;\n}\n\n/** Number of mandatory segments in the pattern of `route` (0 when unknown). */\nfunction depthOf(route: string, patternByName: ReadonlyMap<string, string>): number {\n\treturn patternSegments(patternByName.get(route) ?? \"\").length;\n}\n\n/**\n * Entries ordered by the pattern depth of their own route, declaration order within one depth.\n * Expanding them in this order puts an ancestor's entries before a descendant's on every route.\n */\nexport function byRouteDepth<T extends { readonly route: string }>(\n\tentries: T[],\n\tpatternByName: ReadonlyMap<string, string>,\n): T[] {\n\treturn entries.toSorted((a, b) => depthOf(a.route, patternByName) - depthOf(b.route, patternByName));\n}\n\n/**\n * Copy each route-specific entry to every descendant route (`inheritance: \"pattern-tree\"`).\n * Global (`\"*\"`) entries and entries for routes without a known pattern are kept as-is.\n * Ordered by the pattern depth of the route an entry was declared for, so on every route\n * ancestor guards run before descendant guards, whatever the declaration order. Where global\n * entries end up does not matter: the pipeline runs global guards separately.\n * A route named `\"*\"` does not pass its entries on, because a `\"*\"` entry is a global one.\n */\nexport function expandToDescendants<T extends { readonly route: string }>(entries: T[], routes: RoutePattern[]): T[] {\n\tif (routes.length === 0) return entries;\n\tconst patternByName = new Map(routes.map((r) => [r.name, r.pattern]));\n\n\tconst expanded: T[] = [];\n\tfor (const entry of byRouteDepth(entries, patternByName)) {\n\t\texpanded.push(entry);\n\t\tif (entry.route === \"*\") continue;\n\t\tconst ancestorPattern = patternByName.get(entry.route);\n\t\tif (ancestorPattern === undefined) continue;\n\t\tfor (const { name, pattern } of routes) {\n\t\t\tif (name !== entry.route && isPatternAncestor(ancestorPattern, pattern)) {\n\t\t\t\texpanded.push({ ...entry, route: name });\n\t\t\t}\n\t\t}\n\t}\n\n\treturn expanded;\n}\n\n/**\n * Entries a newly added route inherits (`inheritance: \"pattern-tree\"`): copies of its\n * ancestors' entries for the new route, and copies of its own entries for its existing\n * descendants. `routes` must include the new route. Ordered like {@link expandToDescendants};\n * where the entries go among those a route has already is up to the caller.\n */\nexport function expandForNewRoute<T extends { readonly route: string }>(\n\tentries: T[],\n\tnewName: string,\n\troutes: RoutePattern[],\n): T[] {\n\tconst patternByName = new Map(routes.map((r) => [r.name, r.pattern]));\n\tconst newPattern = patternByName.get(newName);\n\tif (newPattern === undefined) return [];\n\n\tconst result: T[] = [];\n\tfor (const entry of byRouteDepth(entries, patternByName)) {\n\t\tif (entry.route === \"*\") continue;\n\t\tif (entry.route === newName) {\n\t\t\tfor (const { name, pattern } of routes) {\n\t\t\t\tif (name !== newName && isPatternAncestor(newPattern, pattern)) {\n\t\t\t\t\tresult.push({ ...entry, route: name });\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst ancestorPattern = patternByName.get(entry.route);\n\t\t\tif (ancestorPattern !== undefined && isPatternAncestor(ancestorPattern, newPattern)) {\n\t\t\t\tresult.push({ ...entry, route: newName });\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;EAAA;AACA;AACA;;EAEA;EACA,MAAMA,wBAAwB,GAAG,WAAW;;EAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACA,SAASC,gBAAgBA,CAACC,GAAW,EAAU;IAC9C,MAAMC,KAAK,GAAGD,GAAG,CAACE,OAAO,CAAC,IAAI,CAAC;IAC/B,IAAID,KAAK,KAAK,CAAC,CAAC,EAAE,OAAOD,GAAG,CAACG,KAAK,CAAC,CAAC,EAAEF,KAAK,CAAC;IAC5C,MAAMG,KAAK,GAAGJ,GAAG,CAACE,OAAO,CAAC,IAAI,CAAC;IAC/B,IAAIE,KAAK,KAAK,CAAC,CAAC,EAAE,OAAOJ,GAAG,CAACG,KAAK,CAAC,CAAC,EAAEC,KAAK,CAAC;IAC5C,OAAOJ,GAAG;EACX;;EAEA;AACA;AACA;AACA;AACA;AACA;EACO,SAASK,eAAeA,CAACC,OAAe,EAAY;IAC1D,OAAOA,OAAO,CACZC,KAAK,CAAC,GAAG,CAAC,CACVC,GAAG,CAACT,gBAAgB,CAAC,CACrBU,MAAM,CAAET,GAAG,IAAKA,GAAG,KAAK,EAAE,IAAI,CAACF,wBAAwB,CAACY,IAAI,CAACV,GAAG,CAAC,CAAC;EACrE;;EAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACO,SAASW,iBAAiBA,CAACC,eAAuB,EAAEC,gBAAwB,EAAW;IAC7F,IAAID,eAAe,KAAK,EAAE,EAAE,OAAO,IAAI;IACvC,MAAME,gBAAgB,GAAGT,eAAe,CAACO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MAAM;UAAEN,IAAI;UAAE5B;QAAQ,CAAC,IAAIyB,MAAM,EAAE;UACvC,IAAIG,IAAI,KAAKM,OAAO,IAAI7B,iBAAiB,CAAC8B,UAAU,EAAEnC,OAAO,CAAC,EAAE;YAC/DoC,MAAM,CAACL,IAAI,CAAC;cAAE,GAAGD,KAAK;cAAEd,KAAK,EAAEY;YAAK,CAAC,CAAC;UACvC;QACD;MACD,CAAC,MAAM;QACN,MAAMtB,eAAe,GAAGW,aAAa,CAACC,GAAG,CAACY,KAAK,CAACd,KAAK,CAAC;QACtD,IAAIV,eAAe,KAAK0B,SAAS,IAAI3B,iBAAiB,CAACC,eAAe,EAAE6B,UAAU,CAAC,EAAE;UACpFC,MAAM,CAACL,IAAI,CAAC;YAAE,GAAGD,KAAK;YAAEd,KAAK,EAAEkB;UAAQ,CAAC,CAAC;QAC1C;MACD;IACD;IAEA,OAAOE,MAAM;EACd;EAAC,IAAAC,SAAA;IAAAC,UAAA;EAAA;EAAAD,SAAA,CAAAtC,eAAA,GAAAA,eAAA;EAAAsC,SAAA,CAAAhC,iBAAA,GAAAA,iBAAA;EAAAgC,SAAA,CAAAlB,YAAA,GAAAA,YAAA;EAAAkB,SAAA,CAAAb,mBAAA,GAAAA,mBAAA;EAAAa,SAAA,CAAAJ,iBAAA,GAAAA,iBAAA;EAAA,OAAAI,SAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
declare module "ui5/guard/router/PatternTree" {
|
|
2
|
+
/**
|
|
3
|
+
* Pattern-tree helpers: compare UI5 route patterns by their mandatory path segments.
|
|
4
|
+
*/
|
|
5
|
+
/** Matches a standalone optional (`:param:`) or rest (`:param*:`) segment. */
|
|
6
|
+
const OPTIONAL_OR_REST_SEGMENT: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* Strips inline query and optional-query suffixes from a segment.
|
|
9
|
+
*
|
|
10
|
+
* UI5 (crossroads.js) allows query parameters to attach directly to a
|
|
11
|
+
* path segment without a `/` separator:
|
|
12
|
+
* - `product{?query}` → mandatory query on `product`
|
|
13
|
+
* - `product:?query:` → optional query on `product`
|
|
14
|
+
* - `{id}{?query}` → mandatory param + mandatory query
|
|
15
|
+
*
|
|
16
|
+
* For pattern-tree ancestry we only care about the path portion,
|
|
17
|
+
* so these suffixes are stripped.
|
|
18
|
+
*/
|
|
19
|
+
function stripInlineQuery(seg: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Extract mandatory path segments from a UI5 route pattern.
|
|
22
|
+
*
|
|
23
|
+
* Splits on `/`, strips inline query suffixes, then drops empty segments,
|
|
24
|
+
* standalone optional (`:param:`), and rest (`:param*:`) segments.
|
|
25
|
+
*/
|
|
26
|
+
export function patternSegments(pattern: string): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Check if `ancestorPattern` is a URL-tree ancestor of `candidatePattern`.
|
|
29
|
+
*
|
|
30
|
+
* Both patterns are reduced to their mandatory path segments and compared
|
|
31
|
+
* positionally. Mandatory parameter segments (`{paramA}`, `{paramB}`) are
|
|
32
|
+
* treated as equivalent regardless of name, so `employees/{empId}` is
|
|
33
|
+
* recognized as an ancestor of `employees/{id}/resume`.
|
|
34
|
+
*/
|
|
35
|
+
export function isPatternAncestor(ancestorPattern: string, candidatePattern: string): boolean;
|
|
36
|
+
/** A route name with its pattern. */
|
|
37
|
+
export interface RoutePattern {
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly pattern: string;
|
|
40
|
+
}
|
|
41
|
+
/** Number of mandatory segments in the pattern of `route` (0 when unknown). */
|
|
42
|
+
function depthOf(route: string, patternByName: ReadonlyMap<string, string>): number;
|
|
43
|
+
/**
|
|
44
|
+
* Entries ordered by the pattern depth of their own route, declaration order within one depth.
|
|
45
|
+
* Expanding them in this order puts an ancestor's entries before a descendant's on every route.
|
|
46
|
+
*/
|
|
47
|
+
export function byRouteDepth<T extends {
|
|
48
|
+
readonly route: string;
|
|
49
|
+
}>(entries: T[], patternByName: ReadonlyMap<string, string>): T[];
|
|
50
|
+
/**
|
|
51
|
+
* Copy each route-specific entry to every descendant route (`inheritance: "pattern-tree"`).
|
|
52
|
+
* Global (`"*"`) entries and entries for routes without a known pattern are kept as-is.
|
|
53
|
+
* Ordered by the pattern depth of the route an entry was declared for, so on every route
|
|
54
|
+
* ancestor guards run before descendant guards, whatever the declaration order. Where global
|
|
55
|
+
* entries end up does not matter: the pipeline runs global guards separately.
|
|
56
|
+
* A route named `"*"` does not pass its entries on, because a `"*"` entry is a global one.
|
|
57
|
+
*/
|
|
58
|
+
export function expandToDescendants<T extends {
|
|
59
|
+
readonly route: string;
|
|
60
|
+
}>(entries: T[], routes: RoutePattern[]): T[];
|
|
61
|
+
/**
|
|
62
|
+
* Entries a newly added route inherits (`inheritance: "pattern-tree"`): copies of its
|
|
63
|
+
* ancestors' entries for the new route, and copies of its own entries for its existing
|
|
64
|
+
* descendants. `routes` must include the new route. Ordered like {@link expandToDescendants};
|
|
65
|
+
* where the entries go among those a route has already is up to the caller.
|
|
66
|
+
*/
|
|
67
|
+
export function expandForNewRoute<T extends {
|
|
68
|
+
readonly route: string;
|
|
69
|
+
}>(entries: T[], newName: string, routes: RoutePattern[]): T[];
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=PatternTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PatternTree.d.ts","sourceRoot":"../../../../..","sources":["src/PatternTree.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,8BAA8B,CAAC;IAC9C;;OAEG;IAEH,8EAA8E;IAC9E,MAAM,wBAAwB,QAAc,CAAC;IAE7C;;;;;;;;;;;OAWG;IACH,SAAS,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM7C;IAED;;;;;OAKG;IACH,SAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAKzD;IAED;;;;;;;OAOG;IACH,SAAgB,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,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