mcl-axios-kit 0.0.1 → 0.0.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/dist/McAxios.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import axios from "axios";
2
2
  import McRequest from "./McRequest";
3
- import { ERROR_HANDLER_KEY, METHOD_META_KEY, PATH_PARAMS_KEY, REQUEST_KEY, RESPONSE_TYPE_KEY, SUCCESS_HANDLER_KEY } from "./McAxiosAnnotations";
3
+ import { ERROR_HANDLER_KEY, METHOD_META_KEY, PATH_PARAMS_KEY, REQUEST_KEY, RESPONSE_TYPE_KEY, SUCCESS_HANDLER_KEY, FORMDATA_KEY } from "./McAxiosAnnotations";
4
4
  export default class McAxios {
5
5
  _axios;
6
6
  constructor() {
@@ -23,6 +23,7 @@ export default class McAxios {
23
23
  const errorHandler = Reflect.getMetadata(ERROR_HANDLER_KEY, proto, name);
24
24
  const requestBody = Reflect.getMetadata(REQUEST_KEY, proto, name);
25
25
  const responseType = Reflect.getMetadata(RESPONSE_TYPE_KEY, proto, name);
26
+ const formData = Reflect.getMetadata(FORMDATA_KEY, proto, name);
26
27
  const pathParams = Reflect.getMetadata(PATH_PARAMS_KEY, proto, name) || {};
27
28
  Object.defineProperty(this, name, {
28
29
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -33,6 +34,30 @@ export default class McAxios {
33
34
  const value = encodeURIComponent(args[index]);
34
35
  url = url.replace(`{${key}}`, value);
35
36
  }
37
+ if (method === "MULTIPART") {
38
+ const data = formData !== undefined ? args[formData] : undefined;
39
+ try {
40
+ const response = await this._axios
41
+ .request({
42
+ method: "POST",
43
+ url,
44
+ data,
45
+ headers: { "Content-Type": "multipart/form-data" },
46
+ })
47
+ .catch((err) => {
48
+ throw err;
49
+ });
50
+ if (successHandler)
51
+ return successHandler(response);
52
+ if (responseType)
53
+ return new responseType(response);
54
+ return response.data;
55
+ }
56
+ catch (reqErr) {
57
+ const err = errorHandler ? errorHandler(reqErr) : reqErr;
58
+ throw reqErr;
59
+ }
60
+ }
36
61
  const request = requestBody !== undefined ? args[requestBody] : undefined;
37
62
  if (request !== undefined && request instanceof McRequest === false) {
38
63
  const err = new Error("Request 형식이 잘못 되었습니다.");
@@ -6,13 +6,16 @@ export declare const RESPONSE_TYPE_KEY: unique symbol;
6
6
  export declare const PATH_PARAMS_KEY: unique symbol;
7
7
  export declare const SUCCESS_HANDLER_KEY: unique symbol;
8
8
  export declare const ERROR_HANDLER_KEY: unique symbol;
9
+ export declare const FORMDATA_KEY: unique symbol;
9
10
  declare const McAxiosAnnotations: {
10
11
  GET: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
11
12
  POST: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
12
13
  PUT: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
13
14
  DELETE: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
15
+ MULTIPART: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
14
16
  PATCH: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
15
17
  Request: (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
18
+ FormData: (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
16
19
  Path: (name: string) => (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
17
20
  Success: (fn: Function) => (target: any, propertyKey: string) => void;
18
21
  Error: (fn: Function) => (target: any, propertyKey: string) => void;
@@ -6,6 +6,7 @@ export const RESPONSE_TYPE_KEY = Symbol("mc:responseType");
6
6
  export const PATH_PARAMS_KEY = Symbol("mc:pathParams");
7
7
  export const SUCCESS_HANDLER_KEY = Symbol("mc:successHandler");
8
8
  export const ERROR_HANDLER_KEY = Symbol("mc:errorHandler");
9
+ export const FORMDATA_KEY = Symbol("mc:formdata");
9
10
  const McAxiosAnnotations = {
10
11
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
11
12
  GET: (url, type) => {
@@ -24,6 +25,10 @@ const McAxiosAnnotations = {
24
25
  return createDecorator("DELETE", url, type);
25
26
  },
26
27
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
28
+ MULTIPART: (url, type) => {
29
+ return createDecorator("MULTIPART", url, type);
30
+ },
31
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
27
32
  PATCH: (url, type) => {
28
33
  return createDecorator("PATCH", url, type);
29
34
  },
@@ -31,6 +36,10 @@ const McAxiosAnnotations = {
31
36
  Request: (target, propertyKey, parameterIndex) => {
32
37
  Reflect.defineMetadata(REQUEST_KEY, parameterIndex, target, propertyKey);
33
38
  },
39
+ // biome-ignore lint/complexity/noBannedTypes: <explanation>
40
+ FormData: (target, propertyKey, parameterIndex) => {
41
+ Reflect.defineMetadata(FORMDATA_KEY, parameterIndex, target, propertyKey);
42
+ },
34
43
  Path: (name) => {
35
44
  // biome-ignore lint/complexity/noBannedTypes: <explanation>
36
45
  return (target, propertyKey, parameterIndex) => {
@@ -0,0 +1,38 @@
1
+ import McAxiosOrigin from './McAxios';
2
+ import McAxiosManager from './McAxiosManager';
3
+ import McAxiosAnnotations from './McAxiosAnnotations';
4
+ import McDataAnnotations from './McDataAnnotations';
5
+ import McRequest from './McRequest';
6
+ import McResponse from './McResponse';
7
+ /**
8
+ * 2. McAxios 클래스에 다른 클래스들을 정적(static) 속성으로 결합합니다.
9
+ * 이렇게 하면 McAxios.Manager와 같은 방식으로 접근이 가능해집니다.
10
+ */
11
+ declare const McAxios: typeof McAxiosOrigin & {
12
+ Manager: typeof McAxiosManager;
13
+ AxiosAnnotations: {
14
+ GET: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
15
+ POST: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
16
+ PUT: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
17
+ DELETE: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
18
+ MULTIPART: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
19
+ PATCH: (url: string, type: new (res: any) => any) => (target: any, propertyKey: string) => void;
20
+ Request: (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
21
+ FormData: (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
22
+ Path: (name: string) => (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
23
+ Success: (fn: Function) => (target: any, propertyKey: string) => void;
24
+ Error: (fn: Function) => (target: any, propertyKey: string) => void;
25
+ };
26
+ DataAnnotations: {
27
+ Entity: <T extends {
28
+ new (...args: any[]): {};
29
+ }>(constructor: T) => T;
30
+ Serialize: (jsonKey: string) => (target: any, propertyKey: string) => void;
31
+ Field: (type: any, path?: string, defaultValue?: any) => (target: any, propertyKey: string) => void;
32
+ ArrayField: (type: any, path?: string, defaultValue?: any) => (target: any, propertyKey: string) => void;
33
+ };
34
+ Request: typeof McRequest;
35
+ Response: typeof McResponse;
36
+ };
37
+ export default McAxios;
38
+ export { McAxios, McAxiosManager, McAxiosAnnotations, McDataAnnotations, McRequest, McResponse };
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ // 1. 모든 클래스를 가져옵니다.
2
+ // (각 파일들이 export default로 되어 있다고 가정합니다.)
3
+ import McAxiosOrigin from './McAxios';
4
+ import McAxiosManager from './McAxiosManager';
5
+ import McAxiosAnnotations from './McAxiosAnnotations';
6
+ import McDataAnnotations from './McDataAnnotations';
7
+ import McRequest from './McRequest';
8
+ import McResponse from './McResponse';
9
+ /**
10
+ * 2. McAxios 클래스에 다른 클래스들을 정적(static) 속성으로 결합합니다.
11
+ * 이렇게 하면 McAxios.Manager와 같은 방식으로 접근이 가능해집니다.
12
+ */
13
+ const McAxios = Object.assign(McAxiosOrigin, {
14
+ Manager: McAxiosManager,
15
+ AxiosAnnotations: McAxiosAnnotations,
16
+ DataAnnotations: McDataAnnotations,
17
+ Request: McRequest,
18
+ Response: McResponse,
19
+ });
20
+ // 3. 통합된 McAxios를 default로 내보냅니다.
21
+ export default McAxios;
22
+ // 4. 필요한 경우 { McAxiosManager } 처럼 별도로 쓰고 싶을 때를 대비한 Named Export
23
+ export { McAxios, McAxiosManager, McAxiosAnnotations, McDataAnnotations, McRequest, McResponse };
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "mcl-axios-kit",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "McL에서 Axios를 활용해 API를 보다 효율적이고 깔끔하게 활용할 수 있도록 구현된 Kit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./dist/index.d.ts",
10
11
  "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
+ "require": "./dist/index.js"
12
13
  }
13
14
  },
14
15
  "files": [
File without changes
@@ -1 +0,0 @@
1
- "use strict";