hanni 0.1.0 → 0.1.3

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 ADDED
@@ -0,0 +1,15 @@
1
+ # hanni
2
+
3
+ To install dependencies:
4
+
5
+ ```bash
6
+ bun install
7
+ ```
8
+
9
+ To run:
10
+
11
+ ```bash
12
+ bun run ./src/hanni.js
13
+ ```
14
+
15
+ This project was created using `bun init` in bun v1.3.5. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "hanni",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Minimalist Bun web framework with built-in Swagger UI",
5
5
  "type": "module",
6
- "main": "./index.js",
6
+ "main": "./src/hanni.js",
7
7
  "exports": {
8
- ".": "./index.js"
8
+ ".": "./src/hanni.js"
9
9
  },
10
10
  "files": [
11
- "index.js",
11
+ "src/hanni.js",
12
12
  "src"
13
13
  ],
14
14
  "keywords": [
@@ -18,9 +18,9 @@
18
18
  "swagger",
19
19
  "openapi"
20
20
  ],
21
- "author": "Your Name",
21
+ "author": "2matheww",
22
22
  "license": "MIT",
23
23
  "engines": {
24
24
  "bun": ">=1.0.0"
25
25
  }
26
- }
26
+ }
package/src/swagger.js CHANGED
@@ -92,8 +92,8 @@ export function buildSpec(routes, cfg = {}) {
92
92
  return {
93
93
  openapi: '3.0.3',
94
94
  info: {
95
- title: cfg.title || 'API',
96
- version: cfg.version || '1.0.0',
95
+ title: cfg.title || 'Hanni',
96
+ version: cfg.version || '0.1.2',
97
97
  description: cfg.description || ''
98
98
  },
99
99
  tags: Array.from(tagsMap.values()),
package/index.js DELETED
@@ -1,103 +0,0 @@
1
- import { Hanni } from './src/hanni.js'
2
-
3
- const app = Hanni({
4
- swagger: {
5
- path: '/docs',
6
- title: 'My API',
7
- description:
8
- 'Contoh REST API sederhana untuk manajemen user. Dibangun dengan hanni.js.',
9
- version: '2.0.0'
10
- }
11
- })
12
-
13
- const users = [
14
- { id: '1', name: 'Hanni', age: 21 },
15
- { id: '2', name: 'Minji', age: 22 }
16
- ]
17
-
18
- app.get(
19
- '/users',
20
- c => {
21
- return c.json({
22
- total: users.length,
23
- data: users
24
- })
25
- },
26
- {
27
- summary: 'Get all users',
28
- tags: ['Users'],
29
- response: {
30
- type: 'object',
31
- properties: {
32
- total: { type: 'number' },
33
- data: {
34
- type: 'array',
35
- items: {
36
- type: 'object',
37
- properties: {
38
- id: { type: 'string' },
39
- name: { type: 'string' },
40
- age: { type: 'number' }
41
- }
42
- }
43
- }
44
- }
45
- }
46
- }
47
- )
48
-
49
- app.post(
50
- '/users/:id',
51
- c => {
52
- const { id } = c.params
53
- const { verbose } = c.query
54
- const body = c.body || {}
55
-
56
- let user = users.find(u => u.id === id)
57
-
58
- if (!user) {
59
- user = { id, ...body }
60
- users.push(user)
61
- } else {
62
- Object.assign(user, body)
63
- }
64
-
65
- return c.json({
66
- success: true,
67
- verbose: !!verbose,
68
- user
69
- })
70
- },
71
- {
72
- summary: 'Update user',
73
- description: 'Update user by id',
74
- tags: ['Users'],
75
- query: {
76
- verbose: true
77
- },
78
- body: {
79
- type: 'object',
80
- properties: {
81
- name: { type: 'string' },
82
- age: { type: 'number' }
83
- }
84
- },
85
- response: {
86
- type: 'object',
87
- properties: {
88
- success: { type: 'boolean' },
89
- verbose: { type: 'boolean' },
90
- user: {
91
- type: 'object',
92
- properties: {
93
- id: { type: 'string' },
94
- name: { type: 'string' },
95
- age: { type: 'number' }
96
- }
97
- }
98
- }
99
- }
100
- }
101
- )
102
-
103
- app.listen(3000)