minimonolith 0.1.0 → 0.1.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/index.js CHANGED
@@ -1,3 +1,4 @@
1
- import { serviceHandler } from './src/serviceHanlder/serviceHandler.js';
1
+ import { createAPI } from 'lambda-api';
2
+ import { serviceHandler } from './src/serviceHandler/serviceHandler.js';
2
3
 
3
- export { serviceHandler };
4
+ export { createAPI, serviceHandler };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minimonolith",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -0,0 +1,10 @@
1
+ const handler = async (e, MODELS) => {
2
+ const { id } = e.body;
3
+
4
+ const todo = await MODELS.todo.findOne({ where: { id: e.body.id } });
5
+ await todo.destroy();
6
+
7
+ return { statusCode: 200 };
8
+ }
9
+
10
+ export { handler };
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+
3
+ const VALIDATOR = (MODELS, ROUTE_CODE) =>
4
+ z.object({
5
+ id: z.number(),
6
+ }).strict();
7
+
8
+ export { VALIDATOR };
@@ -0,0 +1,7 @@
1
+ const handler = async (e, MODELS) => {
2
+ const todos = await MODELS.todo.findAll();
3
+
4
+ return { statusCode: 200, body: todos };
5
+ }
6
+
7
+ export { handler };
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+
3
+ const VALIDATOR = (MODELS, ROUTE_CODE) =>
4
+ z.undefined();
5
+
6
+ export { VALIDATOR };
@@ -0,0 +1,5 @@
1
+ import { modelSchema } from './model.js';
2
+
3
+ const methods = ['get', 'post', 'delete'];
4
+
5
+ export { modelSchema, methods };
@@ -0,0 +1,8 @@
1
+ export const modelSchema = serviceName => (sequelize, type) => {
2
+ return sequelize.define(serviceName, {
3
+ name: {
4
+ type: type.STRING,
5
+ allowNull: false
6
+ },
7
+ });
8
+ };
@@ -0,0 +1,9 @@
1
+ const handler = async (e, MODELS) => {
2
+ const { name } = e.body;
3
+
4
+ const todo = await MODELS.todo.create({ name });
5
+
6
+ return { statusCode: 201, body: todo.toJSON() };
7
+ }
8
+
9
+ export { handler };
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+
3
+ const VALIDATOR = (MODELS, ROUTE_CODE) =>
4
+ z.object({
5
+ name: z.string(),
6
+ }).strict();
7
+
8
+ export { VALIDATOR };
package/src/index.js DELETED
@@ -1,25 +0,0 @@
1
- 'use strict';
2
-
3
- import createAPI from 'lambda-api';
4
- import healthCheck from './healthCheck/index.js';
5
- import { serviceHandler } from './serviceHandler/index.js';
6
-
7
- const API = createAPI();
8
-
9
- // Health Check
10
- API.get('/', async (req, res) => {
11
- console.log('HEALTH_CHECK ENTERING');
12
- const response = healthCheck();
13
- console.log('HEALTH_CHECK SUCCESS');
14
- return { response };
15
- });
16
-
17
- serviceHandler(API, 'todo', 'src');
18
-
19
- export const handler = async (e, context) => {
20
- console.log({
21
- EVENT_PATH: e.path,
22
- EVENT_METHOD: e.httpMethod,
23
- });
24
- return await API.run(e, context);
25
- };