lambder 1.0.51 → 1.0.52

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 CHANGED
@@ -9,26 +9,16 @@ type Session = {
9
9
  csrfToken: string;
10
10
  createdTimeStamp: number;
11
11
  expiresTimeStamp: number;
12
- data: {
13
- [key: string]: any;
14
- };
12
+ data: Record<string, any>;
15
13
  };
16
14
  type RenderContext = {
17
15
  host: string;
18
16
  path: string;
19
- pathParams: {
20
- [key: string]: any;
21
- } | null;
17
+ pathParams: Record<string, any> | null;
22
18
  method: string;
23
- get: {
24
- [key: string]: any;
25
- };
26
- post: {
27
- [key: string]: any;
28
- };
29
- cookie: {
30
- [key: string]: any;
31
- };
19
+ get: Record<string, any>;
20
+ post: Record<string, any>;
21
+ cookie: Record<string, any>;
32
22
  headers: APIGatewayProxyEventHeaders;
33
23
  session: Session | null;
34
24
  lambdaContext: Context;
@@ -63,9 +53,7 @@ export default class Lambder {
63
53
  setRouteFallbackHandler(routeFallbackHandler: RouteFallbackHandlerFunction): void;
64
54
  setApiFallbackHandler(apiFallbackHandler: ApiFallbackHandlerFunction): void;
65
55
  setGlobalErrorHandler(globalErrorHandler: GlobalErrorHandlerFunction): void;
66
- getPatternMatch(pattern: string, path: string): {
67
- [key: string]: any;
68
- };
56
+ getPatternMatch(pattern: string, path: string): Record<string, any>;
69
57
  testPatternMatch(pattern: string, path: string): boolean;
70
58
  private validateSession;
71
59
  private handleNoMatchedAction;
@@ -7,9 +7,7 @@ type FetchTracker = {
7
7
  type EventHandlerFetchParams = {
8
8
  api: string;
9
9
  payload?: any;
10
- headers?: {
11
- [key: string]: any;
12
- };
10
+ headers?: Record<string, any>;
13
11
  };
14
12
  type FetchStartEventHandler = (params: {
15
13
  fetchParams: EventHandlerFetchParams;
@@ -49,9 +47,7 @@ export default class LambderCaller {
49
47
  fetchStartedHandler?: FetchStartEventHandler;
50
48
  fetchEndedHandler?: FetchEndEventHandler;
51
49
  });
52
- api(apiName: string, payload?: any, headers?: {
53
- [key: string]: any;
54
- }, options?: {
50
+ api(apiName: string, payload?: any, headers?: Record<string, any>, options?: {
55
51
  versionExpiredHandler?: VoidFunction;
56
52
  sessionExpiredHandler?: VoidFunction;
57
53
  messageHandler?: MessageHandler;
@@ -1,11 +1,8 @@
1
1
  export type ResolverResponse = {
2
2
  statusCode: number;
3
- multiValueHeaders?: {
4
- [key: string]: string[];
5
- };
3
+ multiValueHeaders?: Record<string, string[]>;
6
4
  body: string | null;
7
5
  isBase64Encoded?: boolean;
8
- [key: string]: any;
9
6
  };
10
7
  export default class ResponseBuilder {
11
8
  private isCorsEnabled;
@@ -19,28 +16,14 @@ export default class ResponseBuilder {
19
16
  private readFileSync;
20
17
  private checkFileExist;
21
18
  raw(param: ResolverResponse): ResolverResponse;
22
- json(data: {
23
- [key: string]: any;
24
- }, headers?: {
25
- [key: string]: string | string[];
26
- }): ResolverResponse;
19
+ json(data: Record<string, any>, headers?: Record<string, string | string[]>): ResolverResponse;
27
20
  xml(data: string): ResolverResponse;
28
- html(data: string, headers?: {
29
- [key: string]: string | string[];
30
- }): ResolverResponse;
31
- status301(url: string, headers?: {
32
- [key: string]: string | string[];
33
- }): ResolverResponse;
34
- status404(data: string, headers?: {
35
- [key: string]: string | string[];
36
- }): ResolverResponse;
21
+ html(data: string, headers?: Record<string, string | string[]>): ResolverResponse;
22
+ status301(url: string, headers?: Record<string, string | string[]>): ResolverResponse;
23
+ status404(data: string, headers?: Record<string, string | string[]>): ResolverResponse;
37
24
  cors(): ResolverResponse;
38
- fileBase64(fileBase64: string, mimeType: string, headers?: {
39
- [key: string]: string | string[];
40
- }): ResolverResponse;
41
- file(filePath: string, headers?: {
42
- [key: string]: string | string[];
43
- }, fallbackFilePath?: string): ResolverResponse;
25
+ fileBase64(fileBase64: string, mimeType: string, headers?: Record<string, string | string[]>): ResolverResponse;
26
+ file(filePath: string, headers?: Record<string, string | string[]>, fallbackFilePath?: string): ResolverResponse;
44
27
  api({ payload, versionExpired, sessionExpired, notAuthorized, message, errorMessage, ...other }: {
45
28
  payload?: any;
46
29
  versionExpired?: boolean;
@@ -48,7 +31,5 @@ export default class ResponseBuilder {
48
31
  notAuthorized?: boolean;
49
32
  message?: any;
50
33
  errorMessage?: any;
51
- }, headers?: {
52
- [key: string]: string | string[];
53
- }): ResolverResponse;
34
+ }, headers?: Record<string, string | string[]>): ResolverResponse;
54
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/Lambder.ts CHANGED
@@ -15,17 +15,17 @@ type Session = {
15
15
  csrfToken: string;
16
16
  createdTimeStamp: number;
17
17
  expiresTimeStamp: number;
18
- data: { [key:string]: any };
18
+ data: Record<string, any>;
19
19
  };
20
20
 
21
21
  type RenderContext = {
22
22
  host: string;
23
23
  path: string;
24
- pathParams: { [key: string]: any } | null;
24
+ pathParams: Record<string, any> | null;
25
25
  method: string;
26
- get: { [key: string]: any };
27
- post: { [key: string]: any };
28
- cookie: { [key: string]: any };
26
+ get: Record<string, any>;
27
+ post: Record<string, any>;
28
+ cookie: Record<string, any>;
29
29
  headers: APIGatewayProxyEventHeaders;
30
30
  session: Session|null;
31
31
  lambdaContext: Context;
@@ -58,11 +58,11 @@ export const createContext = (
58
58
  const host = event.headers.Host || event.headers.host || "";
59
59
  const path = event.path;
60
60
  const pathParams = null;
61
- const get: { [key:string]: any } = event.queryStringParameters || {};
61
+ const get: Record<string, any> = event.queryStringParameters || {};
62
62
  const method = event.httpMethod;
63
63
  const cookie = cookieParser.parse(event.headers.Cookie || event.headers.cookie || "");
64
64
  const headers = event.headers;
65
- let post:{ [key:string]: any } = {};
65
+ let post: Record<string, any> = {};
66
66
  const session = null;
67
67
  try {
68
68
  const decodedBody = event.isBase64Encoded ? ( event.body ? Buffer.from(event.body,"base64").toString() : "{}" ) : ( event.body || "{}" );
@@ -118,7 +118,7 @@ export default class Lambder {
118
118
  setGlobalErrorHandler(globalErrorHandler: GlobalErrorHandlerFunction){
119
119
  this.globalErrorHandler = globalErrorHandler;
120
120
  }
121
- getPatternMatch(pattern: string, path: string): { [key:string]: any }{
121
+ getPatternMatch(pattern: string, path: string): Record<string, any> {
122
122
  const result = (match(pattern, { decode: decodeURIComponent }))(path);
123
123
  if(!result) return {};
124
124
  return result?.params || {};
@@ -5,7 +5,7 @@ type FetchTracker = { apiName: string, done: boolean, fetchEndCalled: boolean };
5
5
  type EventHandlerFetchParams = {
6
6
  api: string,
7
7
  payload?: any,
8
- headers?: { [key:string]: any }
8
+ headers?: Record<string, any>
9
9
  };
10
10
 
11
11
  type FetchStartEventHandler = (params: {
@@ -80,7 +80,7 @@ export default class LambderCaller {
80
80
 
81
81
  };
82
82
 
83
- async api(apiName: string, payload?: any, headers?: { [key:string]: any }, options?: {
83
+ async api(apiName: string, payload?: any, headers?: Record<string, any>, options?: {
84
84
  versionExpiredHandler?: VoidFunction,
85
85
  sessionExpiredHandler?: VoidFunction,
86
86
  messageHandler?: MessageHandler,
@@ -3,8 +3,8 @@ import * as path from "path";
3
3
  import mimeTypeResolver from "mime-types";
4
4
 
5
5
  const convertToMultiHeader = (
6
- headers: { [key:string]: string|string[] } | undefined
7
- ):{ [key:string]: string[] } =>
6
+ headers: Record<string, string|string[]> | undefined
7
+ ):Record<string, string[]> =>
8
8
  Object.fromEntries(Object.entries(headers||{}).map(([k,v])=>[ k, Array.isArray(v) ? v : [v] ]));
9
9
 
10
10
  const CORS_HEADERS = convertToMultiHeader({
@@ -16,10 +16,9 @@ const CORS_HEADERS = convertToMultiHeader({
16
16
 
17
17
  export type ResolverResponse = {
18
18
  statusCode: number,
19
- multiValueHeaders?: { [key:string]: string[] },
19
+ multiValueHeaders?: Record<string, string[]>,
20
20
  body: string | null,
21
21
  isBase64Encoded?: boolean,
22
- [key:string]: any,
23
22
  };
24
23
 
25
24
 
@@ -62,8 +61,8 @@ export default class ResponseBuilder {
62
61
  };
63
62
 
64
63
  json(
65
- data: { [key:string]: any },
66
- headers?: { [key:string]: string|string[] }
64
+ data: Record<string, any>,
65
+ headers?: Record<string, string|string[]>
67
66
  ):ResolverResponse{
68
67
  return this.raw({
69
68
  statusCode: 200,
@@ -87,7 +86,7 @@ export default class ResponseBuilder {
87
86
 
88
87
  html(
89
88
  data: string,
90
- headers?: { [key:string]: string|string[] },
89
+ headers?: Record<string, string|string[]>,
91
90
  ):ResolverResponse{
92
91
  return this.raw({
93
92
  statusCode: 200,
@@ -99,7 +98,7 @@ export default class ResponseBuilder {
99
98
 
100
99
  status301(
101
100
  url: string,
102
- headers?: { [key:string]: string|string[] },
101
+ headers?: Record<string, string|string[]>,
103
102
  ):ResolverResponse{
104
103
  return this.raw({
105
104
  statusCode: 301,
@@ -110,7 +109,7 @@ export default class ResponseBuilder {
110
109
 
111
110
  status404(
112
111
  data: string,
113
- headers?: { [key:string]: string|string[] },
112
+ headers?: Record<string, string|string[]>,
114
113
  ):ResolverResponse{
115
114
  return this.raw({
116
115
  statusCode: 404,
@@ -131,7 +130,7 @@ export default class ResponseBuilder {
131
130
  fileBase64 (
132
131
  fileBase64: string,
133
132
  mimeType: string,
134
- headers?: { [key:string]: string|string[] },
133
+ headers?: Record<string, string|string[]>,
135
134
  ):ResolverResponse{
136
135
  return this.raw({
137
136
  statusCode: 200,
@@ -143,7 +142,7 @@ export default class ResponseBuilder {
143
142
 
144
143
  file(
145
144
  filePath: string,
146
- headers?: { [key:string]: string|string[] },
145
+ headers?: Record<string, string|string[]>,
147
146
  fallbackFilePath?: string,
148
147
  ):ResolverResponse{
149
148
  if(!this.checkFileExist(filePath)){
@@ -173,7 +172,7 @@ export default class ResponseBuilder {
173
172
  message?: any;
174
173
  errorMessage?: any;
175
174
  },
176
- headers?: { [key:string]: string|string[] },
175
+ headers?: Record<string, string|string[]>,
177
176
  ): ResolverResponse {
178
177
  if(Object.keys(other).length) console.log("ERROR: Unexpected key in result: " + Object.keys(other).join(", "));
179
178
  return this.json({