lambder 1.0.16 → 1.0.17

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/index.d.ts CHANGED
@@ -55,8 +55,9 @@ export default class Lambder {
55
55
  setGlobalErrorHandler(globalErrorHandler: (err: Error) => ResolverResponse): void;
56
56
  addModule(moduleFn: Function): Promise<void>;
57
57
  private validateSession;
58
- addPath(condition: string | ConditionFunction | RegExp, actionFn: ActionFunction): void;
59
- addPublicApi(condition: string | ConditionFunction | RegExp, actionFn: ActionFunction): void;
58
+ addRoute(condition: string | ConditionFunction | RegExp, actionFn: ActionFunction): void;
59
+ addSessionRoute(condition: string | ConditionFunction | RegExp, actionFn: ActionFunction): void;
60
+ addApi(condition: string | ConditionFunction | RegExp, actionFn: ActionFunction): void;
60
61
  addSessionApi(condition: string | ConditionFunction | RegExp, actionFn: ActionFunction): void;
61
62
  addHook(hookEvent: 'created', hookFn: HookCreatedFunction, priority?: number): Promise<void>;
62
63
  addHook(hookEvent: 'beforeRender', hookFn: HookBeforeRenderFunction, priority?: number): Promise<void>;
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ export default class Lambder {
68
68
  // Check DDB;
69
69
  return false;
70
70
  }
71
- addPath(condition, actionFn) {
71
+ addRoute(condition, actionFn) {
72
72
  this._actionList.push({
73
73
  conditionFn: async (renderContext) => (renderContext.method === "GET" &&
74
74
  ((typeof condition === "string" && renderContext.url === condition) ||
@@ -77,7 +77,16 @@ export default class Lambder {
77
77
  actionFn: async (renderContext, resolver) => await actionFn(renderContext, resolver)
78
78
  });
79
79
  }
80
- addPublicApi(condition, actionFn) {
80
+ addSessionRoute(condition, actionFn) {
81
+ this._actionList.push({
82
+ conditionFn: async (renderContext) => (renderContext.method === "GET" &&
83
+ ((typeof condition === "string" && renderContext.url === condition) ||
84
+ (typeof condition === "function" && (await condition(renderContext))) ||
85
+ (condition?.constructor == RegExp && condition.test(renderContext.url)))),
86
+ actionFn: async (renderContext, resolver) => await actionFn(renderContext, resolver)
87
+ });
88
+ }
89
+ addApi(condition, actionFn) {
81
90
  this._actionList.push({
82
91
  conditionFn: async (renderContext) => (renderContext.method === "POST" && renderContext.url === this.apiPath &&
83
92
  ((typeof condition === "string" && renderContext.post?.api === condition) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -120,7 +120,21 @@ export default class Lambder {
120
120
  return false;
121
121
  }
122
122
 
123
- addPath(condition: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
123
+ addRoute(condition: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
124
+ this._actionList.push({
125
+ conditionFn: async (renderContext:RenderContext) => (
126
+ renderContext.method === "GET" &&
127
+ (
128
+ (typeof condition === "string" && renderContext.url === condition) ||
129
+ (typeof condition === "function" && (await condition(renderContext))) ||
130
+ (condition?.constructor == RegExp && condition.test(renderContext.url))
131
+ )
132
+ ),
133
+ actionFn: async (renderContext:RenderContext, resolver: Resolver) => await actionFn(renderContext, resolver)
134
+ });
135
+ }
136
+
137
+ addSessionRoute(condition: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
124
138
  this._actionList.push({
125
139
  conditionFn: async (renderContext:RenderContext) => (
126
140
  renderContext.method === "GET" &&
@@ -134,7 +148,7 @@ export default class Lambder {
134
148
  });
135
149
  }
136
150
 
137
- addPublicApi(condition: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
151
+ addApi(condition: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
138
152
  this._actionList.push({
139
153
  conditionFn: async (renderContext:RenderContext) => (
140
154
  renderContext.method === "POST" && renderContext.url === this.apiPath &&