@noony-serverless/core 0.2.0 → 0.2.2

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/README.md CHANGED
@@ -9,7 +9,7 @@ A powerful and flexible serverless middleware framework for Google Cloud Functio
9
9
  The `Handler` class manages the middleware execution pipeline with `before`, `after`, and `onError` lifecycle hooks:
10
10
 
11
11
  ```typescript
12
- const handler = new Handler<RequestType, UserType>()
12
+ const handler = new Handler<RequestType>()
13
13
  .use(errorHandler())
14
14
  .use(bodyParser())
15
15
  .use(bodyValidator(schema))
@@ -23,7 +23,7 @@ const handler = new Handler<RequestType, UserType>()
23
23
  The context system provides full TypeScript support with generic typing:
24
24
 
25
25
  ```typescript
26
- interface Context<T = unknown, U = unknown> {
26
+ interface Context<T = unknown> {
27
27
  req: CustomRequest<T>; // Request with parsedBody and validatedBody
28
28
  res: CustomResponse; // Response object
29
29
  container?: Container; // TypeDI dependency injection
@@ -72,7 +72,7 @@ const userSchema = z.object({
72
72
  type UserRequest = z.infer<typeof userSchema>;
73
73
 
74
74
  // Create handler with full type safety
75
- const createUserHandler = new Handler<UserRequest, unknown>()
75
+ const createUserHandler = new Handler<UserRequest>()
76
76
  .use(new ErrorHandlerMiddleware())
77
77
  .use(new BodyValidationMiddleware(userSchema))
78
78
  .use(new ResponseWrapperMiddleware())
@@ -117,7 +117,7 @@ const messageSchema = z.object({
117
117
  type PubSubMessage = z.infer<typeof messageSchema>;
118
118
 
119
119
  // Create Pub/Sub handler
120
- const pubsubHandler = new Handler<PubSubMessage, unknown>()
120
+ const pubsubHandler = new Handler<PubSubMessage>()
121
121
  .use(new ErrorHandlerMiddleware())
122
122
  .use(new BodyParserMiddleware()) // Decodes base64 Pub/Sub messages
123
123
  .use(new BodyValidationMiddleware(messageSchema))
@@ -296,7 +296,7 @@ app.post('/users', async (req, res) => {
296
296
  ### 1. Middleware Order
297
297
 
298
298
  ```typescript
299
- const handler = new Handler<RequestType, UserType>()
299
+ const handler = new Handler<RequestType>()
300
300
  .use(new ErrorHandlerMiddleware()) // Always first
301
301
  .use(new HeaderVariablesMiddleware(...)) // Required headers
302
302
  .use(new AuthenticationMiddleware(...)) // Authentication
@@ -324,7 +324,7 @@ interface UserContext {
324
324
  }
325
325
 
326
326
  // Use throughout the handler
327
- const handler = new Handler<UserRequest, UserContext>();
327
+ const handler = new Handler<UserRequest>();
328
328
  ```
329
329
 
330
330
  ### 3. Error Handling
@@ -361,7 +361,7 @@ import {
361
361
  } from '@noony/serverless';
362
362
 
363
363
  // No type casting needed with proper generics
364
- const handler = new Handler<UserRequest, UserContext>()
364
+ const handler = new Handler<UserRequest>()
365
365
  .handle(async (context) => {
366
366
  // TypeScript knows validatedBody is UserRequest
367
367
  const { name, email } = context.req.validatedBody!;
@@ -1,4 +1,4 @@
1
- import Container from 'typedi';
1
+ import { ContainerInstance } from 'typedi';
2
2
  /**
3
3
  * Framework-agnostic HTTP method enum
4
4
  */
@@ -71,7 +71,7 @@ export interface HandlerOptions {
71
71
  export interface Context<T = unknown> {
72
72
  readonly req: NoonyRequest<T>;
73
73
  readonly res: NoonyResponse;
74
- container?: Container;
74
+ container: ContainerInstance;
75
75
  error?: Error | null;
76
76
  readonly businessData: Map<string, unknown>;
77
77
  user?: unknown;
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.HttpMethod = void 0;
7
4
  exports.generateRequestId = generateRequestId;
8
5
  exports.createContext = createContext;
9
- const typedi_1 = __importDefault(require("typedi"));
6
+ const typedi_1 = require("typedi");
10
7
  /**
11
8
  * Framework-agnostic HTTP method enum
12
9
  */
@@ -25,7 +22,7 @@ var HttpMethod;
25
22
  * Utility function to generate unique request IDs
26
23
  */
27
24
  function generateRequestId() {
28
- return `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
25
+ return `req_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
29
26
  }
30
27
  // Complex adapter functions removed - using smart universal adapter in Handler instead
31
28
  /**
@@ -35,7 +32,7 @@ function createContext(req, res, options = {}) {
35
32
  return {
36
33
  req,
37
34
  res,
38
- container: options.container || typedi_1.default.of(),
35
+ container: options.container || typedi_1.Container.of(),
39
36
  error: options.error || null,
40
37
  businessData: options.businessData || new Map(),
41
38
  user: options.user,
@@ -312,7 +312,9 @@ class ProcessingMiddleware {
312
312
  }
313
313
  extractContentLength(req) {
314
314
  const contentLength = req.headers?.['content-length'] || req.headers?.['Content-Length'];
315
- const lengthValue = Array.isArray(contentLength) ? contentLength[0] : contentLength;
315
+ const lengthValue = Array.isArray(contentLength)
316
+ ? contentLength[0]
317
+ : contentLength;
316
318
  return lengthValue ? parseInt(lengthValue, 10) : undefined;
317
319
  }
318
320
  extractAcceptLanguage(req) {
@@ -158,7 +158,7 @@ class DependencyInjectionMiddleware {
158
158
  this.services.forEach((service) => {
159
159
  typedi_1.Container.set(service.id, service.value);
160
160
  });
161
- context.container = typedi_1.Container;
161
+ context.container = typedi_1.Container.of();
162
162
  }
163
163
  }
164
164
  exports.DependencyInjectionMiddleware = DependencyInjectionMiddleware;
@@ -421,7 +421,9 @@ let PermissionGuardFactory = class PermissionGuardFactory {
421
421
  return this.createExpressionGuard(permissions, config);
422
422
  default:
423
423
  // Fallback to plain guard
424
- return this.createPlainGuard(Array.isArray(permissions) ? permissions : [permissions], config);
424
+ return this.createPlainGuard(Array.isArray(permissions)
425
+ ? permissions
426
+ : [permissions], config);
425
427
  }
426
428
  }
427
429
  /**
@@ -534,7 +536,8 @@ let PermissionGuardFactory = class PermissionGuardFactory {
534
536
  checkCount: acc.checkCount + (stats.checkCount || 0),
535
537
  successCount: acc.successCount + (stats.successCount || 0),
536
538
  failureCount: acc.failureCount + (stats.failureCount || 0),
537
- totalProcessingTimeUs: acc.totalProcessingTimeUs + (stats.totalProcessingTimeUs || 0),
539
+ totalProcessingTimeUs: acc.totalProcessingTimeUs +
540
+ (stats.totalProcessingTimeUs || 0),
538
541
  }), {
539
542
  checkCount: 0,
540
543
  successCount: 0,
@@ -546,10 +549,12 @@ let PermissionGuardFactory = class PermissionGuardFactory {
546
549
  totalSuccesses: totals.successCount,
547
550
  totalFailures: totals.failureCount,
548
551
  overallSuccessRate: totals.checkCount > 0
549
- ? (totals.successCount / totals.checkCount) * 100
552
+ ? (totals.successCount / totals.checkCount) *
553
+ 100
550
554
  : 100,
551
555
  averageProcessingTimeUs: totals.checkCount > 0
552
- ? totals.totalProcessingTimeUs / totals.checkCount
556
+ ? totals.totalProcessingTimeUs /
557
+ totals.checkCount
553
558
  : 0,
554
559
  };
555
560
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noony-serverless/core",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A Middy base framework compatible with Firebase and GCP Cloud Functions with TypeScript",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",