lambder 1.0.45 → 1.0.47
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/Lambder.d.ts +2 -0
- package/dist/Lambder.js +10 -4
- package/package.json +2 -1
- package/src/Lambder.ts +10 -4
package/dist/Lambder.d.ts
CHANGED
|
@@ -62,6 +62,8 @@ export default class Lambder {
|
|
|
62
62
|
setRouteFallbackHandler(routeFallbackHandler: RouteFallbackHandlerFunction): void;
|
|
63
63
|
setApiFallbackHandler(apiFallbackHandler: ApiFallbackHandlerFunction): void;
|
|
64
64
|
setGlobalErrorHandler(globalErrorHandler: GlobalErrorHandlerFunction): void;
|
|
65
|
+
getPatternMatch(pattern: string, path: string): {};
|
|
66
|
+
testPatternMatch(pattern: string, path: string): boolean;
|
|
65
67
|
private validateSession;
|
|
66
68
|
private handleNoMatchedAction;
|
|
67
69
|
addModule(moduleFn: Function): Promise<void>;
|
package/dist/Lambder.js
CHANGED
|
@@ -60,6 +60,12 @@ export default class Lambder {
|
|
|
60
60
|
setGlobalErrorHandler(globalErrorHandler) {
|
|
61
61
|
this.globalErrorHandler = globalErrorHandler;
|
|
62
62
|
}
|
|
63
|
+
getPatternMatch(pattern, path) {
|
|
64
|
+
return (match(pattern, { decode: decodeURIComponent }))(path) || {};
|
|
65
|
+
}
|
|
66
|
+
testPatternMatch(pattern, path) {
|
|
67
|
+
return (match(pattern, { decode: decodeURIComponent }))(path) !== false;
|
|
68
|
+
}
|
|
63
69
|
async validateSession(session) {
|
|
64
70
|
if (!session)
|
|
65
71
|
return false;
|
|
@@ -97,12 +103,12 @@ export default class Lambder {
|
|
|
97
103
|
addRoute(condition, actionFn) {
|
|
98
104
|
this.actionList.push({
|
|
99
105
|
conditionFn: (ctx) => (ctx.method === "GET" &&
|
|
100
|
-
((typeof condition === "string" && ctx.path
|
|
106
|
+
((typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
|
|
101
107
|
(typeof condition === "function" && condition(ctx)) ||
|
|
102
108
|
(condition?.constructor == RegExp && condition.test(ctx.path)))),
|
|
103
109
|
actionFn: async (ctx, resolver) => {
|
|
104
110
|
if (typeof condition === "string") {
|
|
105
|
-
ctx.pathParams = (
|
|
111
|
+
ctx.pathParams = this.getPatternMatch(condition, ctx.path);
|
|
106
112
|
}
|
|
107
113
|
else if (condition?.constructor == RegExp) {
|
|
108
114
|
ctx.pathParams = ctx.path.match(condition);
|
|
@@ -115,7 +121,7 @@ export default class Lambder {
|
|
|
115
121
|
addSessionRoute(condition, actionFn) {
|
|
116
122
|
this.actionList.push({
|
|
117
123
|
conditionFn: (ctx) => (ctx.method === "GET" &&
|
|
118
|
-
((typeof condition === "string" && ctx.path
|
|
124
|
+
((typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
|
|
119
125
|
(typeof condition === "function" && condition(ctx)) ||
|
|
120
126
|
(condition?.constructor == RegExp && condition.test(ctx.path)))),
|
|
121
127
|
actionFn: async (ctx, resolver) => {
|
|
@@ -123,7 +129,7 @@ export default class Lambder {
|
|
|
123
129
|
if (!isSessionValid)
|
|
124
130
|
throw new Error("Session not found");
|
|
125
131
|
if (typeof condition === "string") {
|
|
126
|
-
ctx.pathParams = (
|
|
132
|
+
ctx.pathParams = this.getPatternMatch(condition, ctx.path);
|
|
127
133
|
}
|
|
128
134
|
else if (condition?.constructor == RegExp) {
|
|
129
135
|
ctx.pathParams = ctx.path.match(condition);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lambder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"cookie": "^0.6.0",
|
|
17
17
|
"js-cookie": "^3.0.5",
|
|
18
18
|
"mime-types": "^2.1.35",
|
|
19
|
+
"path-to-regexp": "^6.2.1",
|
|
19
20
|
"querystring": "^0.2.1"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
package/src/Lambder.ts
CHANGED
|
@@ -116,6 +116,12 @@ export default class Lambder {
|
|
|
116
116
|
setGlobalErrorHandler(globalErrorHandler: GlobalErrorHandlerFunction){
|
|
117
117
|
this.globalErrorHandler = globalErrorHandler;
|
|
118
118
|
}
|
|
119
|
+
getPatternMatch(pattern: string, path: string){
|
|
120
|
+
return (match(pattern, { decode: decodeURIComponent }))(path) || {};
|
|
121
|
+
}
|
|
122
|
+
testPatternMatch(pattern: string, path: string): boolean{
|
|
123
|
+
return (match(pattern, { decode: decodeURIComponent }))(path) !== false;
|
|
124
|
+
}
|
|
119
125
|
|
|
120
126
|
private async validateSession (session: Session|null): Promise<boolean>{
|
|
121
127
|
if(!session) return false;
|
|
@@ -149,14 +155,14 @@ export default class Lambder {
|
|
|
149
155
|
conditionFn: (ctx:RenderContext) => (
|
|
150
156
|
ctx.method === "GET" &&
|
|
151
157
|
(
|
|
152
|
-
(typeof condition === "string" && ctx.path
|
|
158
|
+
(typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
|
|
153
159
|
(typeof condition === "function" && condition(ctx)) ||
|
|
154
160
|
(condition?.constructor == RegExp && condition.test(ctx.path))
|
|
155
161
|
)
|
|
156
162
|
),
|
|
157
163
|
actionFn: async (ctx:RenderContext, resolver: Resolver) => {
|
|
158
164
|
if(typeof condition === "string"){
|
|
159
|
-
ctx.pathParams = (
|
|
165
|
+
ctx.pathParams = this.getPatternMatch(condition, ctx.path);
|
|
160
166
|
}else if(condition?.constructor == RegExp){
|
|
161
167
|
ctx.pathParams = ctx.path.match(condition);
|
|
162
168
|
}
|
|
@@ -170,7 +176,7 @@ export default class Lambder {
|
|
|
170
176
|
conditionFn: (ctx:RenderContext) => (
|
|
171
177
|
ctx.method === "GET" &&
|
|
172
178
|
(
|
|
173
|
-
(typeof condition === "string" && ctx.path
|
|
179
|
+
(typeof condition === "string" && this.testPatternMatch(condition, ctx.path)) ||
|
|
174
180
|
(typeof condition === "function" && condition(ctx)) ||
|
|
175
181
|
(condition?.constructor == RegExp && condition.test(ctx.path))
|
|
176
182
|
)
|
|
@@ -179,7 +185,7 @@ export default class Lambder {
|
|
|
179
185
|
const isSessionValid = this.validateSession(ctx.session);
|
|
180
186
|
if(!isSessionValid) throw new Error("Session not found");
|
|
181
187
|
if(typeof condition === "string"){
|
|
182
|
-
ctx.pathParams = (
|
|
188
|
+
ctx.pathParams = this.getPatternMatch(condition, ctx.path);
|
|
183
189
|
}else if(condition?.constructor == RegExp){
|
|
184
190
|
ctx.pathParams = ctx.path.match(condition);
|
|
185
191
|
}
|