@galeh/chuka 1.0.5 → 1.0.7

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.
Files changed (2) hide show
  1. package/README.md +77 -0
  2. package/package.json +5 -2
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Purpose
2
+ This package aims at making the API programming much easier, using the expressjs as underlying library, it creates fast API's. It adds leverages expressjs by adding strong types, dependency injection and profound validation.
3
+
4
+ # Example
5
+
6
+ ```typescript
7
+ // main.ts
8
+ const app = createApp({
9
+ dependencies: [
10
+ {
11
+ provide: 'catservice',
12
+ useClass: CatsService
13
+ }
14
+ ],
15
+ routes: [
16
+ {
17
+ path: '/cats',
18
+ controller: CatsController
19
+ }
20
+ ],
21
+ middlewares: [
22
+ json()
23
+ ]
24
+ });
25
+
26
+ app.use((error: any, req: any, res: any, next: any) => {
27
+ res.status(400).json(error);
28
+ })
29
+
30
+ app.listen(8080, () => {
31
+ console.log('running application!');
32
+ });
33
+
34
+ ```
35
+
36
+ ```typescript
37
+ // example for a controller
38
+
39
+ @injectable()
40
+ export class CatsController extends Controller {
41
+ constructor(@inject('catservice') service: CatsServiceInterface) {
42
+ super();
43
+
44
+ const intercepted = this.middleware(
45
+ createLogger()
46
+ );
47
+
48
+ intercepted.middleware(
49
+ bodyValidator<CatModel>({
50
+ name: and(isDefined(), isString()),
51
+ country: isNumber(),
52
+ age: custom(model => Promise.resolve(!!(model.age && model.age > 2))),
53
+ parents: {
54
+ name: isString(),
55
+ parents: {
56
+ country: isString(),
57
+ }
58
+ }
59
+ })
60
+ ).post('/', async (req, res) => {{
61
+ const allcats = await service.add(req.body.name);
62
+ res.send(allcats);
63
+ }});
64
+
65
+ intercepted.get('/', async (req, res) => {{
66
+ const allcats = await service.findAll();
67
+ res.send(allcats);
68
+ }});
69
+
70
+ intercepted.get('/:id', async (req, res) => {
71
+ const onecat = await service.findOne(+req.params.id);
72
+ res.send(onecat);
73
+ });
74
+ }
75
+ }
76
+
77
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galeh/chuka",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "simple yet robust wrapper for expressjs",
5
5
  "keywords": [
6
6
  "chuka",
@@ -20,7 +20,10 @@
20
20
  "express-ws": "^5.0.2",
21
21
  "inversify": "^6.0.2",
22
22
  "reflect-metadata": "^0.2.1",
23
- "tslib": "^2.6.2"
23
+ "tslib": "^2.6.2",
24
+ "@types/express": "^4.17.21",
25
+ "@types/express-ws": "^3.0.4",
26
+ "@types/ws": "^8.5.10"
24
27
  },
25
28
  "publishConfig": {
26
29
  "access": "public"