minimonolith 0.12.1 → 0.13.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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # minimonolith
2
2
 
3
+ [![codecov](https://codecov.io/gh/DeepHackDev/minimonolith-lib/branch/master/graph/badge.svg?token=ORFNKKJRSE)](https://codecov.io/gh/DeepHackDev/minimonolith-lib)
4
+
3
5
  `minimonolith` is a lightweight library designed to help you build serverless APIs using AWS Lambda, with a focus on simplicity and ease of use. The library provides a straightforward structure to organize your API's services, methods, validation, and models while handling common tasks like database connection and request validation.
4
6
 
5
7
  In addition to its simplicity, `minimonolith` enables seamless inter-service communication within your API. This allows services to call one another's functionality without directly importing them, fostering a modular design. For example, you can call the get method of the todo service from the todoList service using SERVICES.todo.get({ id }). By registering services within the API, you can easily call their methods from other services, which not only promotes a clean architecture but also paves the way for future support of automated end-to-end testing.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minimonolith",
3
3
  "type": "module",
4
- "version": "0.12.1",
4
+ "version": "0.13.0",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -1,8 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  const DB_VALIDATION = {
4
- exists: (model, field, options=undefined) => async (rawValue, ctx) => {
5
- const value = options?.parseInt ? parseInt(rawValue) : rawValue;
4
+ exists: (model, field) => async (value, ctx) => {
6
5
  const valueCount = await model.count({ where: { [field]: value } });
7
6
  if (valueCount == 0) {
8
7
  ctx.addIssue({
@@ -12,8 +11,7 @@ const DB_VALIDATION = {
12
11
  }
13
12
  },
14
13
 
15
- notExists: (model, field, options=undefined) => async (rawValue, ctx) => {
16
- const value = options?.parseInt ? parseInt(rawValue) : rawValue;
14
+ notExists: (model, field) => async (value, ctx) => {
17
15
  const valueCount = await model.count({ where: { [field]: value } });
18
16
  if (valueCount > 0) {
19
17
  ctx.addIssue({
@@ -22,6 +20,16 @@ const DB_VALIDATION = {
22
20
  });
23
21
  }
24
22
  },
23
+
24
+ isSafeInt: field => (rawValue, ctx) => {
25
+ const parsedValue = parseInt(rawValue, 10);
26
+ if (isNaN(parsedValue) || parsedValue.toString() !== rawValue) {
27
+ ctx.addIssue({
28
+ code: z.ZodIssueCode.custom,
29
+ message: field.toUpperCase()+'_NOT_A_SAFE_INT',
30
+ });
31
+ }
32
+ },
25
33
  };
26
34
 
27
35
  export { DB_VALIDATION };