@typed/router 0.27.7 → 0.28.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/MatchInput/package.json +6 -0
- package/RouteGuard/package.json +6 -0
- package/RouteMatch/package.json +6 -0
- package/dist/cjs/CurrentRoute.js +48 -31
- package/dist/cjs/CurrentRoute.js.map +1 -1
- package/dist/cjs/MatchInput.js +96 -0
- package/dist/cjs/MatchInput.js.map +1 -0
- package/dist/cjs/Matcher.js +97 -73
- package/dist/cjs/Matcher.js.map +1 -1
- package/dist/cjs/RouteGuard.js +78 -0
- package/dist/cjs/RouteGuard.js.map +1 -0
- package/dist/cjs/RouteMatch.js +49 -0
- package/dist/cjs/RouteMatch.js.map +1 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/dts/CurrentRoute.d.ts +19 -14
- package/dist/dts/CurrentRoute.d.ts.map +1 -1
- package/dist/dts/MatchInput.d.ts +135 -0
- package/dist/dts/MatchInput.d.ts.map +1 -0
- package/dist/dts/Matcher.d.ts +94 -33
- package/dist/dts/Matcher.d.ts.map +1 -1
- package/dist/dts/RouteGuard.d.ts +94 -0
- package/dist/dts/RouteGuard.d.ts.map +1 -0
- package/dist/dts/RouteMatch.d.ts +50 -0
- package/dist/dts/RouteMatch.d.ts.map +1 -0
- package/dist/dts/index.d.ts +12 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/CurrentRoute.js +46 -29
- package/dist/esm/CurrentRoute.js.map +1 -1
- package/dist/esm/MatchInput.js +79 -0
- package/dist/esm/MatchInput.js.map +1 -0
- package/dist/esm/Matcher.js +95 -67
- package/dist/esm/Matcher.js.map +1 -1
- package/dist/esm/RouteGuard.js +57 -0
- package/dist/esm/RouteGuard.js.map +1 -0
- package/dist/esm/RouteMatch.js +29 -0
- package/dist/esm/RouteMatch.js.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +35 -10
- package/src/CurrentRoute.ts +113 -63
- package/src/MatchInput.ts +282 -0
- package/src/Matcher.ts +325 -143
- package/src/RouteGuard.ts +217 -0
- package/src/RouteMatch.ts +104 -0
- package/src/index.ts +15 -0
package/dist/cjs/CurrentRoute.js
CHANGED
|
@@ -4,21 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.browser = exports.CurrentState = exports.CurrentSearchParams = exports.CurrentRoute = exports.CurrentParams = void 0;
|
|
7
|
+
exports.decode = decode;
|
|
7
8
|
exports.isActive = isActive;
|
|
8
9
|
exports.layer = layer;
|
|
9
|
-
exports.
|
|
10
|
+
exports.makeCurrentRoute = makeCurrentRoute;
|
|
10
11
|
exports.makeHref = makeHref;
|
|
11
12
|
exports.withCurrentRoute = exports.server = void 0;
|
|
12
13
|
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/context"));
|
|
13
14
|
var Document = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/dom/Document"));
|
|
14
15
|
var RefSubject = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/fx/RefSubject"));
|
|
15
16
|
var _navigation = /*#__PURE__*/require("@typed/navigation");
|
|
16
|
-
var
|
|
17
|
+
var Route = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/route"));
|
|
17
18
|
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
18
19
|
var _Function = /*#__PURE__*/require("effect/Function");
|
|
19
|
-
var
|
|
20
|
+
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option"));
|
|
20
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
22
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
23
|
/**
|
|
23
24
|
* @since 1.0.0
|
|
24
25
|
*/
|
|
@@ -30,9 +31,9 @@ const CurrentRoute = exports.CurrentRoute = /*#__PURE__*/Context.Tagged("@typed/
|
|
|
30
31
|
/**
|
|
31
32
|
* @since 1.0.0
|
|
32
33
|
*/
|
|
33
|
-
function
|
|
34
|
+
function makeCurrentRoute(route, parent = Option.none()) {
|
|
34
35
|
return {
|
|
35
|
-
route
|
|
36
|
+
route,
|
|
36
37
|
parent
|
|
37
38
|
};
|
|
38
39
|
}
|
|
@@ -40,26 +41,23 @@ function make(route, parent = Option.none()) {
|
|
|
40
41
|
* @since 1.0.0
|
|
41
42
|
*/
|
|
42
43
|
function layer(route, parent = Option.none()) {
|
|
43
|
-
return CurrentRoute.layer(
|
|
44
|
-
}
|
|
45
|
-
function getRoute(route) {
|
|
46
|
-
return typeof route === "string" ? Route.fromPath(route) : route;
|
|
44
|
+
return CurrentRoute.layer(makeCurrentRoute(route, parent));
|
|
47
45
|
}
|
|
48
46
|
/**
|
|
49
47
|
* @since 1.0.0
|
|
50
48
|
*/
|
|
51
|
-
const CurrentParams = exports.CurrentParams = /*#__PURE__*/RefSubject.
|
|
49
|
+
const CurrentParams = exports.CurrentParams = /*#__PURE__*/RefSubject.filteredFromTag(_navigation.Navigation, nav => RefSubject.filterMapEffect(nav.currentEntry, e => CurrentRoute.with(({
|
|
52
50
|
route
|
|
53
|
-
}) => route.match(
|
|
51
|
+
}) => route.match((0, _navigation.getCurrentPathFromUrl)(e.url)))));
|
|
54
52
|
/**
|
|
55
53
|
* @since 1.0.0
|
|
56
54
|
*/
|
|
57
55
|
const withCurrentRoute = exports.withCurrentRoute = /*#__PURE__*/(0, _Function.dual)(2, (effect, route) => Effect.contextWithEffect(ctx => {
|
|
58
56
|
const parent = Context.getOption(ctx, CurrentRoute);
|
|
59
|
-
if (Option.isNone(parent)) return (0, _Function.pipe)(effect, CurrentRoute.provide(
|
|
60
|
-
return (0, _Function.pipe)(effect, CurrentRoute.provide(
|
|
57
|
+
if (Option.isNone(parent)) return (0, _Function.pipe)(effect, CurrentRoute.provide(makeCurrentRoute(route)));
|
|
58
|
+
return (0, _Function.pipe)(effect, CurrentRoute.provide(makeCurrentRoute(parent.value.route.concat(route), parent)));
|
|
61
59
|
}));
|
|
62
|
-
const makeHref_ = (currentPath, currentRoute, route,
|
|
60
|
+
const makeHref_ = (currentPath, currentRoute, route, params = {}) => {
|
|
63
61
|
const currentMatch = currentRoute.match(currentPath);
|
|
64
62
|
if (Option.isNone(currentMatch)) return Option.none();
|
|
65
63
|
const fullRoute = currentRoute.concat(route);
|
|
@@ -67,16 +65,15 @@ const makeHref_ = (currentPath, currentRoute, route, ...[params]) => {
|
|
|
67
65
|
...currentMatch.value,
|
|
68
66
|
...params
|
|
69
67
|
};
|
|
70
|
-
return Option.some(fullRoute.
|
|
68
|
+
return Option.some(fullRoute.interpolate(fullParams));
|
|
71
69
|
};
|
|
72
70
|
/**
|
|
73
71
|
* @since 1.0.0
|
|
74
72
|
*/
|
|
75
|
-
function makeHref(
|
|
76
|
-
|
|
77
|
-
return RefSubject.filterMapEffect(_navigation.CurrentPath, currentPath => Effect.map(CurrentRoute, currentRoute => makeHref_(currentPath, currentRoute.route, route, ...params)));
|
|
73
|
+
function makeHref(route, ...[params]) {
|
|
74
|
+
return RefSubject.filterMapEffect(_navigation.CurrentPath, currentPath => Effect.map(CurrentRoute, currentRoute => makeHref_(currentPath, currentRoute.route, route, params)));
|
|
78
75
|
}
|
|
79
|
-
const isActive_ = (currentPath, currentRoute, route,
|
|
76
|
+
const isActive_ = (currentPath, currentRoute, route, params = {}) => {
|
|
80
77
|
const currentMatch = currentRoute.match(currentPath);
|
|
81
78
|
if (Option.isNone(currentMatch)) return false;
|
|
82
79
|
const fullRoute = currentRoute.concat(route);
|
|
@@ -84,33 +81,53 @@ const isActive_ = (currentPath, currentRoute, route, ...params) => {
|
|
|
84
81
|
...currentMatch.value,
|
|
85
82
|
...params
|
|
86
83
|
};
|
|
87
|
-
const fullPath = fullRoute.
|
|
88
|
-
|
|
84
|
+
const fullPath = fullRoute.interpolate(fullParams);
|
|
85
|
+
const currentPathWithoutSearch = currentPath.split("?")[0] || "/";
|
|
86
|
+
const fullPathWithoutSearch = fullPath.split("?")[0] || "/";
|
|
87
|
+
if (fullPathWithoutSearch === currentPathWithoutSearch) {
|
|
88
|
+
return true;
|
|
89
|
+
} else if (route.routeOptions.end) {
|
|
90
|
+
return false;
|
|
91
|
+
} else {
|
|
92
|
+
return currentPathWithoutSearch.startsWith(fullPathWithoutSearch);
|
|
93
|
+
}
|
|
89
94
|
};
|
|
95
|
+
function isActive(route, ...[params]) {
|
|
96
|
+
return RefSubject.mapEffect(_navigation.CurrentPath, currentPath => CurrentRoute.with(currentRoute => isActive_(currentPath, currentRoute.route, route, params)));
|
|
97
|
+
}
|
|
90
98
|
/**
|
|
91
99
|
* @since 1.0.0
|
|
92
100
|
*/
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
function decode(route) {
|
|
102
|
+
return RefSubject.filteredFromTag(_navigation.Navigation, nav => RefSubject.filterMapEffect(nav.currentEntry, e => Effect.flatMap(CurrentRoute, ({
|
|
103
|
+
route: parent
|
|
104
|
+
}) => Effect.optionFromOptional(Route.decode(parent.concat(route), (0, _navigation.getCurrentPathFromUrl)(e.url))))));
|
|
96
105
|
}
|
|
97
106
|
/**
|
|
98
107
|
* @since 1.0.0
|
|
99
108
|
*/
|
|
100
|
-
const browser = exports.browser = /*#__PURE__*/CurrentRoute.layer( /*#__PURE__*/Effect.gen(function* (
|
|
101
|
-
const document = yield*
|
|
109
|
+
const browser = exports.browser = /*#__PURE__*/CurrentRoute.layer( /*#__PURE__*/Effect.gen(function* () {
|
|
110
|
+
const document = yield* Document.Document;
|
|
102
111
|
const base = document.querySelector("base");
|
|
103
|
-
const baseHref = base ? base.href : "/";
|
|
112
|
+
const baseHref = base ? getBasePathname(base.href) : "/";
|
|
104
113
|
return {
|
|
105
|
-
route: Route.
|
|
114
|
+
route: Route.parse(baseHref),
|
|
106
115
|
parent: Option.none()
|
|
107
116
|
};
|
|
108
117
|
}));
|
|
118
|
+
function getBasePathname(base) {
|
|
119
|
+
try {
|
|
120
|
+
const url = new URL(base);
|
|
121
|
+
return url.pathname;
|
|
122
|
+
} catch {
|
|
123
|
+
return base;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
109
126
|
/**
|
|
110
127
|
* @since 1.0.0
|
|
111
128
|
*/
|
|
112
129
|
const server = (base = "/") => CurrentRoute.layer({
|
|
113
|
-
route: Route.
|
|
130
|
+
route: Route.parse(base),
|
|
114
131
|
parent: Option.none()
|
|
115
132
|
});
|
|
116
133
|
exports.server = server;
|
|
@@ -122,5 +139,5 @@ const CurrentSearchParams = exports.CurrentSearchParams = /*#__PURE__*/RefSubjec
|
|
|
122
139
|
/**
|
|
123
140
|
* @since 1.0.0
|
|
124
141
|
*/
|
|
125
|
-
const CurrentState = exports.CurrentState = /*#__PURE__*/RefSubject.
|
|
142
|
+
const CurrentState = exports.CurrentState = /*#__PURE__*/RefSubject.computedFromTag(_navigation.Navigation, n => RefSubject.map(n.currentEntry, e => e.state));
|
|
126
143
|
//# sourceMappingURL=CurrentRoute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrentRoute.js","names":["Context","_interopRequireWildcard","require","Document","RefSubject","_navigation","
|
|
1
|
+
{"version":3,"file":"CurrentRoute.js","names":["Context","_interopRequireWildcard","require","Document","RefSubject","_navigation","Route","Effect","_Function","Option","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","CurrentRoute","exports","Tagged","makeCurrentRoute","route","parent","none","layer","CurrentParams","filteredFromTag","Navigation","nav","filterMapEffect","currentEntry","with","match","getCurrentPathFromUrl","url","withCurrentRoute","dual","effect","contextWithEffect","ctx","getOption","isNone","pipe","provide","value","concat","makeHref_","currentPath","currentRoute","params","currentMatch","fullRoute","fullParams","some","interpolate","makeHref","CurrentPath","map","isActive_","fullPath","currentPathWithoutSearch","split","fullPathWithoutSearch","routeOptions","end","startsWith","isActive","mapEffect","decode","flatMap","optionFromOptional","browser","gen","document","base","querySelector","baseHref","getBasePathname","href","parse","URL","pathname","server","getSearchParams","destination","fromEntries","searchParams","CurrentSearchParams","CurrentEntry","CurrentState","computedFromTag","state"],"sources":["../../src/CurrentRoute.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;AAIA,IAAAA,OAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,QAAA,gBAAAF,uBAAA,eAAAC,OAAA;AAEA,IAAAE,UAAA,gBAAAH,uBAAA,eAAAC,OAAA;AAEA,IAAAG,WAAA,gBAAAH,OAAA;AACA,IAAAI,KAAA,gBAAAL,uBAAA,eAAAC,OAAA;AACA,IAAAK,MAAA,gBAAAN,uBAAA,eAAAC,OAAA;AACA,IAAAM,SAAA,gBAAAN,OAAA;AAEA,IAAAO,MAAA,gBAAAR,uBAAA,eAAAC,OAAA;AAAuC,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAA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IAAKA,CAAC,CAAC6F,KAAK,CAAC,CACtD","ignoreList":[]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.asRouteGuard = asRouteGuard;
|
|
7
|
+
exports.concat = concat;
|
|
8
|
+
exports.flatMap = exports.filterMap = exports.filter = void 0;
|
|
9
|
+
exports.getPath = getPath;
|
|
10
|
+
exports.getPathSchema = getPathSchema;
|
|
11
|
+
exports.getQuerySchema = getQuerySchema;
|
|
12
|
+
exports.getRoute = getRoute;
|
|
13
|
+
exports.getSchema = getSchema;
|
|
14
|
+
exports.mapEffect = exports.map = void 0;
|
|
15
|
+
var Route = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/route"));
|
|
16
|
+
var _Function = /*#__PURE__*/require("effect/Function");
|
|
17
|
+
var RouteGuard = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./RouteGuard.js"));
|
|
18
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
function asRouteGuard(input) {
|
|
28
|
+
return Route.isRoute(input) ? RouteGuard.fromRoute(input) : input;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*/
|
|
33
|
+
const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, function map(input, f) {
|
|
34
|
+
return RouteGuard.map(asRouteGuard(input), f);
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
*/
|
|
39
|
+
const mapEffect = exports.mapEffect = /*#__PURE__*/(0, _Function.dual)(2, function mapEffect(input, f) {
|
|
40
|
+
return RouteGuard.mapEffect(asRouteGuard(input), f);
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* @since 1.0.0
|
|
44
|
+
*/
|
|
45
|
+
const filter = exports.filter = /*#__PURE__*/(0, _Function.dual)(2, function filter(input, f) {
|
|
46
|
+
return RouteGuard.filter(asRouteGuard(input), f);
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* @since 1.0.0
|
|
50
|
+
*/
|
|
51
|
+
const filterMap = exports.filterMap = /*#__PURE__*/(0, _Function.dual)(2, function filterMap(input, f) {
|
|
52
|
+
return RouteGuard.filterMap(asRouteGuard(input), f);
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
*/
|
|
57
|
+
const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, function flatMap(input, guard) {
|
|
58
|
+
return RouteGuard.flatMap(asRouteGuard(input), guard);
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* @since 1.0.0
|
|
62
|
+
*/
|
|
63
|
+
function concat(left, right) {
|
|
64
|
+
return RouteGuard.concat(asRouteGuard(left), asRouteGuard(right));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
*/
|
|
69
|
+
function getRoute(input) {
|
|
70
|
+
return asRouteGuard(input).route;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @since 1.0.0
|
|
74
|
+
*/
|
|
75
|
+
function getSchema(input) {
|
|
76
|
+
return asRouteGuard(input).route.schema;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @since 1.0.0
|
|
80
|
+
*/
|
|
81
|
+
function getPathSchema(input) {
|
|
82
|
+
return asRouteGuard(input).route.pathSchema;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @since 1.0.0
|
|
86
|
+
*/
|
|
87
|
+
function getQuerySchema(input) {
|
|
88
|
+
return asRouteGuard(input).route.querySchema;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @since 1.0.0
|
|
92
|
+
*/
|
|
93
|
+
function getPath(input) {
|
|
94
|
+
return asRouteGuard(input).route.path;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=MatchInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatchInput.js","names":["Route","_interopRequireWildcard","require","_Function","RouteGuard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","asRouteGuard","input","isRoute","fromRoute","map","exports","dual","f","mapEffect","filter","filterMap","flatMap","guard","concat","left","right","getRoute","route","getSchema","schema","getPathSchema","pathSchema","getQuerySchema","querySchema","getPath","path"],"sources":["../../src/MatchInput.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;AAOA,IAAAA,KAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAEA,IAAAC,SAAA,gBAAAD,OAAA;AAEA,IAAAE,UAAA,gBAAAH,uBAAA,eAAAC,OAAA;AAA6C,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,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AK,CAAC,CAAC;AAClD;AAEA;;;AAGM,SAAUC,QAAQA,CAA2Bf,KAAQ;EACzD,OAAOD,YAAY,CAAIC,KAAK,CAAC,CAACgB,KAAK;AACrC;AAEA;;;AAGM,SAAUC,SAASA,CAA2BjB,KAAQ;EAC1D,OAAOD,YAAY,CAAIC,KAAK,CAAC,CAACgB,KAAK,CAACE,MAAM;AAC5C;AAEA;;;AAGM,SAAUC,aAAaA,CAA2BnB,KAAQ;EAC9D,OAAOD,YAAY,CAAIC,KAAK,CAAC,CAACgB,KAAK,CAACI,UAAsC;AAC5E;AAEA;;;AAGM,SAAUC,cAAcA,CAA2BrB,KAAQ;EAC/D,OAAOD,YAAY,CAAIC,KAAK,CAAC,CAACgB,KAAK,CAACM,WAAwC;AAC9E;AAEA;;;AAGM,SAAUC,OAAOA,CAA2BvB,KAAQ;EACxD,OAAOD,YAAY,CAAIC,KAAK,CAAC,CAACgB,KAAK,CAACQ,IAAI;AAC1C","ignoreList":[]}
|
package/dist/cjs/Matcher.js
CHANGED
|
@@ -3,108 +3,132 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.empty =
|
|
7
|
-
exports.
|
|
8
|
-
|
|
6
|
+
exports.empty = exports.effect = exports.catchRedirectError = exports.RouteMatcherTypeId = exports.RedirectRouteMatchError = void 0;
|
|
7
|
+
exports.isRouteMatcher = isRouteMatcher;
|
|
8
|
+
exports.make = make;
|
|
9
|
+
exports.to = exports.switch = exports.redirectWith = exports.redirectTo = exports.notFoundWith = exports.notFound = exports.match = void 0;
|
|
9
10
|
var Fx = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/fx/Fx"));
|
|
10
11
|
var Match = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/fx/Match"));
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var Navigation = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/navigation"));
|
|
14
|
-
var Route = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/route"));
|
|
12
|
+
var _navigation = /*#__PURE__*/require("@typed/navigation");
|
|
13
|
+
var Data = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Data"));
|
|
15
14
|
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
15
|
+
var _Function = /*#__PURE__*/require("effect/Function");
|
|
16
16
|
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option"));
|
|
17
|
+
var _Predicate = /*#__PURE__*/require("effect/Predicate");
|
|
18
|
+
var Unify = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Unify"));
|
|
17
19
|
var _CurrentRoute = /*#__PURE__*/require("./CurrentRoute.js");
|
|
20
|
+
var RouteMatch = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./RouteMatch.js"));
|
|
18
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
22
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
23
|
/**
|
|
21
24
|
* @since 1.0.0
|
|
22
25
|
*/
|
|
23
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
const RouteMatcherTypeId = exports.RouteMatcherTypeId = /*#__PURE__*/Symbol.for("@typed/router/RouteMatcher");
|
|
24
31
|
class RouteMatcherImpl {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
matches;
|
|
33
|
+
[RouteMatcherTypeId] = RouteMatcherTypeId;
|
|
34
|
+
constructor(matches) {
|
|
35
|
+
this.matches = matches;
|
|
36
|
+
this.add = this.add.bind(this);
|
|
28
37
|
this.match = this.match.bind(this);
|
|
38
|
+
this.switch = this.switch.bind(this);
|
|
39
|
+
this.effect = this.effect.bind(this);
|
|
29
40
|
this.to = this.to.bind(this);
|
|
30
|
-
this.notFound = this.notFound.bind(this);
|
|
31
|
-
this.redirect = this.redirect.bind(this);
|
|
32
41
|
}
|
|
33
|
-
match
|
|
34
|
-
|
|
35
|
-
if (args.length === 2) {
|
|
36
|
-
return new RouteMatcherImpl([...this.guards, {
|
|
37
|
-
route,
|
|
38
|
-
guard: getGuard(route),
|
|
39
|
-
match: ref => Fx.scoped(args[1](ref))
|
|
40
|
-
}]);
|
|
41
|
-
} else {
|
|
42
|
-
return new RouteMatcherImpl([...this.guards, {
|
|
43
|
-
route,
|
|
44
|
-
guard: getGuard(route, args[1]),
|
|
45
|
-
match: ref => Fx.scoped(args[2](ref))
|
|
46
|
-
}]);
|
|
47
|
-
}
|
|
42
|
+
add(match) {
|
|
43
|
+
return new RouteMatcherImpl([...this.matches, match]);
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (args.length === 2) {
|
|
52
|
-
return this.match(route, ref => RefSubject.map(ref, args[1]));
|
|
53
|
-
} else {
|
|
54
|
-
return this.match(route, args[1], ref => RefSubject.map(ref, args[2]));
|
|
55
|
-
}
|
|
45
|
+
match(input, match) {
|
|
46
|
+
return this.add(RouteMatch.fromInput(input, match));
|
|
56
47
|
}
|
|
57
|
-
|
|
58
|
-
return
|
|
59
|
-
const onNotFound = Fx.scoped(f(Navigation.CurrentEntry));
|
|
60
|
-
let matcher = Match.value(
|
|
61
|
-
// Only if we're rendering in a DOM-based environment should we allow for routing to last indefinitely
|
|
62
|
-
env === "dom" || env === "test:dom" ? Navigation.CurrentPath : Fx.take(Navigation.CurrentPath, 1));
|
|
63
|
-
for (const {
|
|
64
|
-
guard,
|
|
65
|
-
match,
|
|
66
|
-
route
|
|
67
|
-
} of this.guards) {
|
|
68
|
-
matcher = matcher.when(guard, ref => Fx.middleware(match(ref), (0, _CurrentRoute.withCurrentRoute)(route)));
|
|
69
|
-
}
|
|
70
|
-
return Fx.filterMapErrorEffect(matcher.getOrElse(() => onNotFound), e => Navigation.isRedirectError(e)
|
|
71
|
-
// Fork the redirect to ensure it does not occur within the same runUpdates as the initial navigation
|
|
72
|
-
? Effect.as(Effect.forkScoped(Navigation.handleRedirect(e)), Option.none()) : Effect.succeedSome(e));
|
|
73
|
-
}));
|
|
48
|
+
switch(input, match) {
|
|
49
|
+
return this.match(input, Fx.switchMap(match));
|
|
74
50
|
}
|
|
75
|
-
|
|
76
|
-
return this.
|
|
51
|
+
effect(input, match) {
|
|
52
|
+
return this.match(input, Fx.switchMapEffect(match));
|
|
77
53
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (guard) {
|
|
81
|
-
return Guard.compose(path, guard);
|
|
82
|
-
} else {
|
|
83
|
-
return path.asGuard();
|
|
54
|
+
to(input, f) {
|
|
55
|
+
return this.match(input, Fx.map(f));
|
|
84
56
|
}
|
|
85
57
|
}
|
|
86
|
-
function getRoute(route) {
|
|
87
|
-
return typeof route === "string" ? Route.fromPath(route) : route;
|
|
88
|
-
}
|
|
89
58
|
/**
|
|
90
59
|
* @since 1.0.0
|
|
91
60
|
*/
|
|
92
|
-
function
|
|
93
|
-
return new RouteMatcherImpl(
|
|
61
|
+
function make(matches) {
|
|
62
|
+
return new RouteMatcherImpl(matches);
|
|
94
63
|
}
|
|
95
64
|
/**
|
|
96
|
-
* @since 1.
|
|
65
|
+
* @since 1.0.0
|
|
97
66
|
*/
|
|
67
|
+
const empty = exports.empty = /*#__PURE__*/make([]);
|
|
98
68
|
const {
|
|
99
|
-
|
|
100
|
-
* @since 1.0.0
|
|
101
|
-
*/
|
|
69
|
+
effect,
|
|
102
70
|
match,
|
|
103
|
-
|
|
104
|
-
* @since 1.0.0
|
|
105
|
-
*/
|
|
71
|
+
switch: switch_,
|
|
106
72
|
to
|
|
107
|
-
} =
|
|
73
|
+
} = empty;
|
|
108
74
|
exports.to = to;
|
|
75
|
+
exports.switch = switch_;
|
|
109
76
|
exports.match = match;
|
|
77
|
+
exports.effect = effect;
|
|
78
|
+
/**
|
|
79
|
+
* @since 1.0.0
|
|
80
|
+
*/
|
|
81
|
+
const catchRedirectError = fx => Fx.filterMapErrorEffect(fx, Unify.unify(_ => (0, _navigation.isRedirectError)(_) ? Effect.as(Effect.forkScoped(Effect.ignoreLogged((0, _navigation.navigate)(_.path, _.options))), Option.none()) : Effect.succeedSome(_)));
|
|
82
|
+
/**
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
*/
|
|
85
|
+
exports.catchRedirectError = catchRedirectError;
|
|
86
|
+
const notFound = exports.notFound = /*#__PURE__*/(0, _Function.dual)(2, function notFound(router, onNotFound) {
|
|
87
|
+
let matcher = Match.value(_navigation.CurrentPath);
|
|
88
|
+
for (const match of router.matches) {
|
|
89
|
+
matcher = matcher.when(match.guard, match.match);
|
|
90
|
+
}
|
|
91
|
+
return catchRedirectError(matcher.getOrElse(() => onNotFound));
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* @since 1.0.0
|
|
95
|
+
*/
|
|
96
|
+
const notFoundWith = exports.notFoundWith = /*#__PURE__*/(0, _Function.dual)(2, function notFoundWith(router, onNotFound) {
|
|
97
|
+
return notFound(router, Fx.fromEffect(onNotFound));
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* @since 1.0.0
|
|
101
|
+
*/
|
|
102
|
+
function isRouteMatcher(value) {
|
|
103
|
+
return (0, _Predicate.hasProperty)(value, RouteMatcherTypeId);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @since 1.0.0
|
|
107
|
+
*/
|
|
108
|
+
const redirectWith = exports.redirectWith = /*#__PURE__*/(0, _Function.dual)(2, function redirectWith(router, effect) {
|
|
109
|
+
return notFoundWith(router, Effect.flatMap(effect, path => new _navigation.RedirectError({
|
|
110
|
+
path
|
|
111
|
+
})));
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* @since 1.0.0
|
|
115
|
+
*/
|
|
116
|
+
const redirectTo = exports.redirectTo = /*#__PURE__*/(0, _Function.dual)(args => isRouteMatcher(args[0]), function redirect(router, route, ...params) {
|
|
117
|
+
return redirectWith(router, (0, _Function.pipe)(Effect.catchTag((0, _CurrentRoute.makeHref)(route, ...params), "NoSuchElementException", () => Effect.fail(new RedirectRouteMatchError(route, params[0] || {}))), Effect.flatMap(path => new _navigation.RedirectError({
|
|
118
|
+
path
|
|
119
|
+
}))));
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* @since 1.0.0
|
|
123
|
+
*/
|
|
124
|
+
class RedirectRouteMatchError extends Data.TaggedError("RedirectRouteMatchError") {
|
|
125
|
+
route;
|
|
126
|
+
params;
|
|
127
|
+
constructor(route, params) {
|
|
128
|
+
super();
|
|
129
|
+
this.route = route;
|
|
130
|
+
this.params = params;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.RedirectRouteMatchError = RedirectRouteMatchError;
|
|
110
134
|
//# sourceMappingURL=Matcher.js.map
|
package/dist/cjs/Matcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matcher.js","names":["
|
|
1
|
+
{"version":3,"file":"Matcher.js","names":["Fx","_interopRequireWildcard","require","Match","_navigation","Data","Effect","_Function","Option","_Predicate","Unify","_CurrentRoute","RouteMatch","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RouteMatcherTypeId","exports","Symbol","for","RouteMatcherImpl","matches","constructor","add","bind","match","switch","effect","to","input","fromInput","switchMap","switchMapEffect","f","map","make","empty","switch_","catchRedirectError","fx","filterMapErrorEffect","unify","_","isRedirectError","as","forkScoped","ignoreLogged","navigate","path","options","none","succeedSome","notFound","dual","router","onNotFound","matcher","value","CurrentPath","when","guard","getOrElse","notFoundWith","fromEffect","isRouteMatcher","hasProperty","redirectWith","flatMap","RedirectError","redirectTo","args","redirect","route","params","pipe","catchTag","makeHref","fail","RedirectRouteMatchError","TaggedError"],"sources":["../../src/Matcher.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;AAIA,IAAAA,EAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,KAAA,gBAAAF,uBAAA,eAAAC,OAAA;AAGA,IAAAE,WAAA,gBAAAF,OAAA;AAEA,IAAAG,IAAA,gBAAAJ,uBAAA,eAAAC,OAAA;AACA,IAAAI,MAAA,gBAAAL,uBAAA,eAAAC,OAAA;AACA,IAAAK,SAAA,gBAAAL,OAAA;AACA,IAAAM,MAAA,gBAAAP,uBAAA,eAAAC,OAAA;AACA,IAAAO,UAAA,gBAAAP,OAAA;AAEA,IAAAQ,KAAA,gBAAAT,uBAAA,eAAAC,OAAA;AAEA,IAAAS,aAAA,gBAAAT,OAAA;AAEA,IAAAU,UAAA,gBAAAX,uBAAA,eAAAC,OAAA;AAA6C,SAAAW,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,K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