badak 0.1.8 → 1.0.1
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/.eslintrc.json +102 -0
- package/.mocharc.json +9 -0
- package/README-KR.md +135 -0
- package/README.md +5 -0
- package/build/badak.d.ts +3 -3
- package/build/{badak.js → cjs/badak.js} +136 -125
- package/build/cjs/badak.js.map +1 -0
- package/build/cjs/constants.js +25 -0
- package/build/cjs/constants.js.map +1 -0
- package/build/{interfaces.js → cjs/interfaces.js} +0 -0
- package/build/{interfaces.js.map → cjs/interfaces.js.map} +1 -1
- package/build/{public_api.js → cjs/public_api.js} +1 -0
- package/build/cjs/public_api.js.map +1 -0
- package/build/{util.js → cjs/util.js} +50 -27
- package/build/cjs/util.js.map +1 -0
- package/build/constants.d.ts +4 -0
- package/build/esm/badak.js +902 -0
- package/build/esm/badak.js.map +1 -0
- package/build/esm/constants.js +22 -0
- package/build/esm/constants.js.map +1 -0
- package/build/esm/interfaces.js +2 -0
- package/build/esm/interfaces.js.map +1 -0
- package/build/esm/public_api.js +3 -0
- package/build/esm/public_api.js.map +1 -0
- package/build/esm/util.js +165 -0
- package/build/esm/util.js.map +1 -0
- package/build/interfaces.d.ts +9 -9
- package/build/public_api.d.ts +1 -1
- package/build/util.d.ts +4 -3
- package/package.json +45 -46
- package/sample/index.ts +10 -10
- package/sample/tsconfig.json +7 -7
- package/spec/badak.spec.ts +370 -3555
- package/spec/config.spec.ts +711 -0
- package/spec/middleware.spec.ts +101 -87
- package/spec/route.spec.ts +1944 -0
- package/spec/setSPARoot.spec.ts +259 -0
- package/spec/static/test.json +2 -2
- package/spec/static.spec.ts +387 -0
- package/spec/test-util.ts +28 -0
- package/src/badak.ts +374 -300
- package/src/constants.ts +16 -0
- package/src/interfaces.ts +26 -24
- package/src/public_api.ts +1 -1
- package/src/util.ts +86 -63
- package/tsconfig.cjs.json +6 -0
- package/tsconfig.esm.json +10 -0
- package/tsconfig.json +15 -19
- package/build/badak.js.map +0 -1
- package/build/constants.js +0 -11
- package/build/constants.js.map +0 -1
- package/build/public_api.js.map +0 -1
- package/build/util.js.map +0 -1
- package/scripts/cp_static_files.js +0 -27
- package/tsconfig.spec.json +0 -18
- package/tslint.json +0 -142
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"es2021": true,
|
|
4
|
+
"node": true
|
|
5
|
+
},
|
|
6
|
+
"extends": [
|
|
7
|
+
"eslint:recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended"
|
|
9
|
+
],
|
|
10
|
+
"parser": "@typescript-eslint/parser",
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"ecmaVersion": 12,
|
|
13
|
+
"sourceType": "module"
|
|
14
|
+
},
|
|
15
|
+
"plugins": [
|
|
16
|
+
"@typescript-eslint"
|
|
17
|
+
],
|
|
18
|
+
"rules": {
|
|
19
|
+
"indent": "off",
|
|
20
|
+
"@typescript-eslint/indent": [
|
|
21
|
+
"warn",
|
|
22
|
+
"tab",
|
|
23
|
+
{
|
|
24
|
+
"ignoreComments": true,
|
|
25
|
+
"SwitchCase": 1,
|
|
26
|
+
"ignoredNodes": [
|
|
27
|
+
"CallExpression *",
|
|
28
|
+
"ExpressionStatement *",
|
|
29
|
+
"NewExpression *"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"linebreak-style": [
|
|
34
|
+
"warn",
|
|
35
|
+
"windows"
|
|
36
|
+
],
|
|
37
|
+
"arrow-parens": "warn",
|
|
38
|
+
"quotes": [
|
|
39
|
+
"warn",
|
|
40
|
+
"single"
|
|
41
|
+
],
|
|
42
|
+
"semi": [
|
|
43
|
+
"warn",
|
|
44
|
+
"always"
|
|
45
|
+
],
|
|
46
|
+
"@typescript-eslint/member-delimiter-style": [
|
|
47
|
+
"warn",
|
|
48
|
+
{
|
|
49
|
+
"multiline": {
|
|
50
|
+
"delimiter": "semi",
|
|
51
|
+
"requireLast": true
|
|
52
|
+
},
|
|
53
|
+
"singleline": {
|
|
54
|
+
"delimiter": "comma",
|
|
55
|
+
"requireLast": false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"no-shadow": "off",
|
|
60
|
+
"@typescript-eslint/no-shadow": "warn",
|
|
61
|
+
"no-trailing-spaces": "warn",
|
|
62
|
+
"no-var": "warn",
|
|
63
|
+
"prefer-const": "warn",
|
|
64
|
+
"space-before-function-paren": "warn",
|
|
65
|
+
"brace-style": [
|
|
66
|
+
"warn",
|
|
67
|
+
"stroustrup"
|
|
68
|
+
],
|
|
69
|
+
"key-spacing": [
|
|
70
|
+
"warn",
|
|
71
|
+
{
|
|
72
|
+
"beforeColon": false,
|
|
73
|
+
"afterColon": true
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"@typescript-eslint/type-annotation-spacing": [
|
|
77
|
+
"warn",
|
|
78
|
+
{
|
|
79
|
+
"before": false,
|
|
80
|
+
"after": true,
|
|
81
|
+
"overrides": {
|
|
82
|
+
"arrow": {
|
|
83
|
+
"before": true,
|
|
84
|
+
"after": true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"@typescript-eslint/explicit-function-return-type": "warn",
|
|
90
|
+
"@typescript-eslint/no-inferrable-types": "off",
|
|
91
|
+
"@typescript-eslint/no-non-null-assertion": "warn",
|
|
92
|
+
"@typescript-eslint/no-empty-function": "warn",
|
|
93
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
94
|
+
"@typescript-eslint/explicit-module-boundary-types": "warn",
|
|
95
|
+
"operator-linebreak": [
|
|
96
|
+
"warn",
|
|
97
|
+
"before"
|
|
98
|
+
],
|
|
99
|
+
"no-param-reassign": "warn",
|
|
100
|
+
"@typescript-eslint/no-empty-interface": "off"
|
|
101
|
+
}
|
|
102
|
+
}
|
package/.mocharc.json
ADDED
package/README-KR.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
# badak
|
|
6
|
+
|
|
7
|
+
badak은 Promise, TypeScript 기반으로 개발된 백엔드 프레임워크입니다.
|
|
8
|
+
|
|
9
|
+
> badak은 TypeScript로 작성되었으며 JavaScript 코드로 컴파일되어 배포됩니다. 따라서 TypeScript 문법으로 사용할 수도 있고 JavaScript 문법으로 사용할 수도 있습니다.
|
|
10
|
+
|
|
11
|
+
## 설치방법
|
|
12
|
+
|
|
13
|
+
badak은 npm으로 배포되며 npm/yarn 으로 설치할 수 있습니다.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install badak
|
|
17
|
+
|
|
18
|
+
# 또는
|
|
19
|
+
|
|
20
|
+
yarn install badak
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 사용방법
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { Badak } from 'badak';
|
|
27
|
+
|
|
28
|
+
const rule : RouteRule = {
|
|
29
|
+
users : {
|
|
30
|
+
GET : () => {
|
|
31
|
+
// return user list
|
|
32
|
+
return {
|
|
33
|
+
list : ['han', 'kim', 'lee']
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
POST : (user : User) => {
|
|
37
|
+
// add user
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
result : 'ok'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const app : Badak = new Badak();
|
|
48
|
+
await app.route(routeRule);
|
|
49
|
+
await app.listen(3000);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 메서드
|
|
53
|
+
|
|
54
|
+
### `new Badak(option?: Partial<BadakOption>)`
|
|
55
|
+
|
|
56
|
+
badak 인스턴스를 생성합니다. 생성자로 옵션을 전달할 수 있습니다.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const app : Badak = new Badak();
|
|
60
|
+
|
|
61
|
+
const appWithLog : Badak = new Badak({
|
|
62
|
+
catchErrorLog : true
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `auth() : Promise<void>`
|
|
67
|
+
|
|
68
|
+
### `before() : Promise<void>`
|
|
69
|
+
|
|
70
|
+
### `after() : Promise<void>`
|
|
71
|
+
|
|
72
|
+
### `config() : Promise<void>`
|
|
73
|
+
|
|
74
|
+
### `listen(port : number) : Promise<void>`
|
|
75
|
+
|
|
76
|
+
### `isRunning() : boolean`
|
|
77
|
+
|
|
78
|
+
### `getHttpServer() : Server | undefined`
|
|
79
|
+
|
|
80
|
+
### `stop() : Promise<void>`
|
|
81
|
+
|
|
82
|
+
### `route(rule : RouteRule) : Promise<void>`
|
|
83
|
+
|
|
84
|
+
### `get(address : string, fnc : RouteFunction, option ?: RouteOption) : Promise<void>`
|
|
85
|
+
|
|
86
|
+
### `post(address : string, fnc : RouteFunction, option ?: RouteOption) : Promise<void>`
|
|
87
|
+
|
|
88
|
+
### `put(address : string, fnc : RouteFunction, option ?: RouteOption) : Promise<void>`
|
|
89
|
+
|
|
90
|
+
### `delete(address : string, fnc : RouteFunction, option ?: RouteOption) : Promise<void>`
|
|
91
|
+
|
|
92
|
+
### `static(uri : string, path : string) : Promise<void>`
|
|
93
|
+
|
|
94
|
+
### `setSPARoot(uri : string, path : string) : Promise<void>`
|
|
95
|
+
|
|
96
|
+
## 인터페이스
|
|
97
|
+
|
|
98
|
+
### `BadakOption`
|
|
99
|
+
|
|
100
|
+
Badak 앱의 동작 방식을 지정합니다.
|
|
101
|
+
|
|
102
|
+
#### `catchErrorLog : boolean`
|
|
103
|
+
|
|
104
|
+
에러가 발생하면 콘솔에 로그를 출력합니다.
|
|
105
|
+
|
|
106
|
+
기본값은 `true` 입니다.
|
|
107
|
+
|
|
108
|
+
#### `preventError : boolean`
|
|
109
|
+
|
|
110
|
+
에러가 발생하면 node로 전달합니다. `false` 값을 지정하면 에러를 전달하지 않고 무시합니다.
|
|
111
|
+
|
|
112
|
+
기본값은 `true` 입니다.
|
|
113
|
+
|
|
114
|
+
#### `defaultMethod : Method | undefined`
|
|
115
|
+
|
|
116
|
+
라우팅에 사용할 기본 HTTP 메서드 타입을 지정합니다. 이 값을 지정하면 `Badak.route()` 메서드를 사용할 때 HTTP 메서드 지정을 생략할 수 있습니다.
|
|
117
|
+
|
|
118
|
+
- 지정 전 :
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
{
|
|
122
|
+
'users' : {
|
|
123
|
+
GET : getUserList
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
- `app.config('defaultMethod', 'GET')` 지정 후 :
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
{
|
|
132
|
+
'users' : getUserList
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
package/README.md
CHANGED
package/build/badak.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class Badak {
|
|
|
19
19
|
auth(fnc: MiddlewareFunction): Promise<void>;
|
|
20
20
|
before(middleware: MiddlewareFunction): Promise<void>;
|
|
21
21
|
after(middleware: MiddlewareFunction): Promise<void>;
|
|
22
|
-
config(key: string, value:
|
|
22
|
+
config(key: string, value: unknown): Promise<void>;
|
|
23
23
|
private _routeAbbrValidator;
|
|
24
24
|
get(address: string, fnc: RouteFunction, option?: RouteOption): Promise<void>;
|
|
25
25
|
post(address: string, fnc: RouteFunction, option?: RouteOption): Promise<void>;
|
|
@@ -33,6 +33,6 @@ export declare class Badak {
|
|
|
33
33
|
setSPARoot(uri: string, path: string): Promise<void>;
|
|
34
34
|
listen(port: number): Promise<void>;
|
|
35
35
|
isRunning(): boolean;
|
|
36
|
-
getHttpServer(): Server;
|
|
37
|
-
stop(): Promise<
|
|
36
|
+
getHttpServer(): Server | undefined;
|
|
37
|
+
stop(): Promise<void>;
|
|
38
38
|
}
|