@yolo-croket-dev/core 1.7.38-slowquery.0 → 1.7.38-slowquery.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.
@@ -1,9 +1,12 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  interface RequestContext {
3
4
  abortSignal: AbortSignal;
4
5
  requestId: string;
5
6
  createdAt: number;
6
7
  parentContext?: RequestContext;
8
+ abortHandler?: () => void;
9
+ timerId?: NodeJS.Timeout;
7
10
  }
8
11
  export declare class AbortContext {
9
12
  private static asyncLocalStorage;
@@ -16,6 +19,7 @@ export declare class AbortContext {
16
19
  requestId: string;
17
20
  } | null;
18
21
  static endContext(context?: RequestContext): void;
22
+ static updateContext(updatedData: Partial<RequestContext>): void;
19
23
  /**
20
24
  * 컨텍스트가 유효한지 확인
21
25
  */
@@ -36,15 +36,41 @@ class AbortContext {
36
36
  // eslint-disable-next-line consistent-return
37
37
  static endContext(context) {
38
38
  const selectContext = context || this.asyncLocalStorage.getStore();
39
+ console.log('selectContext', selectContext);
39
40
  if (selectContext) {
40
- selectContext.abortSignal.removeEventListener('abort', () => { });
41
+ if (selectContext.abortHandler) {
42
+ console.log('selectContext.abortHandler', selectContext.abortHandler);
43
+ selectContext.abortSignal.removeEventListener('abort', selectContext.abortHandler || (() => { }));
44
+ }
45
+ if (selectContext.timerId) {
46
+ console.log('selectContext.timerId', selectContext.timerId);
47
+ clearTimeout(selectContext.timerId);
48
+ }
41
49
  this.asyncLocalStorage.disable();
42
50
  // parent context가 있으면 전부 종료
43
51
  if (selectContext.parentContext) {
52
+ console.log('selectContext.parentContext', selectContext.parentContext);
44
53
  return this.endContext(selectContext.parentContext);
45
54
  }
46
55
  }
47
56
  }
57
+ // 현재 컨텍스트를 업데이트하는 방법
58
+ static updateContext(updatedData) {
59
+ const currentContext = this.asyncLocalStorage.getStore();
60
+ if (!currentContext) {
61
+ console.log('currentContext not found');
62
+ return;
63
+ }
64
+ // 업데이트할 데이터만 갱신
65
+ const updatedContext = {
66
+ ...currentContext,
67
+ ...updatedData,
68
+ updatedAt: Date.now(), // `updatedAt` 값을 갱신
69
+ };
70
+ console.log('currentContext update!', currentContext, updatedContext);
71
+ // 업데이트된 컨텍스트를 다시 저장
72
+ this.asyncLocalStorage.enterWith(updatedContext);
73
+ }
48
74
  /**
49
75
  * 컨텍스트가 유효한지 확인
50
76
  */
@@ -26,6 +26,7 @@ class ContextPromisePatch {
26
26
  const contextId = currentContext.requestId;
27
27
  // 이미 중단된 경우
28
28
  if (abortSignal.aborted) {
29
+ console.log('Promise 생성자 패치: 이미 중단된 경우');
29
30
  return Promise.reject(new Error(`REQUEST_ABORTED: Promise가 중단되었습니다 (${contextId})`));
30
31
  }
31
32
  const promise = Reflect.construct(target, args);
@@ -38,6 +39,7 @@ class ContextPromisePatch {
38
39
  return result;
39
40
  }
40
41
  if (abortSignal.aborted) {
42
+ console.log('Promise 생성자 패치: Promise 실행 중 중단된 경우');
41
43
  throw new Error(`REQUEST_ABORTED: Promise 실행 중 중단되었습니다 (${contextId})`);
42
44
  }
43
45
  return result;
@@ -49,6 +51,7 @@ class ContextPromisePatch {
49
51
  throw error;
50
52
  }
51
53
  if (abortSignal.aborted) {
54
+ console.log('Promise 생성자 패치: Promise 실행 중 중단된 경우');
52
55
  throw new Error(`REQUEST_ABORTED: Promise 실행 중 중단되었습니다 (${contextId})`);
53
56
  }
54
57
  throw error;
@@ -66,6 +69,7 @@ class ContextPromisePatch {
66
69
  const abortSignal = currentContext.abortSignal;
67
70
  const contextId = currentContext.requestId;
68
71
  if (abortSignal.aborted) {
72
+ console.log('Promise 생성자 패치: Promise.resolve가 중단된 경우');
69
73
  return Promise.reject(new Error(`REQUEST_ABORTED: Promise.resolve가 중단되었습니다 (${contextId})`));
70
74
  }
71
75
  const promise = originalResolve.call(global.Promise, value);
@@ -75,6 +79,7 @@ class ContextPromisePatch {
75
79
  return result;
76
80
  }
77
81
  if (abortSignal.aborted) {
82
+ console.log('Promise 생성자 패치: Promise.resolve 실행 중 중단된 경우');
78
83
  throw new Error(`REQUEST_ABORTED: Promise.resolve 실행 중 중단되었습니다 (${contextId})`);
79
84
  }
80
85
  return result;
@@ -84,6 +89,7 @@ class ContextPromisePatch {
84
89
  throw error;
85
90
  }
86
91
  if (abortSignal.aborted) {
92
+ console.log('Promise 생성자 패치: Promise.resolve 실행 중 중단된 경우');
87
93
  throw new Error(`REQUEST_ABORTED: Promise.resolve 실행 중 중단되었습니다 (${contextId})`);
88
94
  }
89
95
  throw error;
@@ -99,6 +105,7 @@ class ContextPromisePatch {
99
105
  }
100
106
  const abortSignal = currentContext.abortSignal;
101
107
  if (abortSignal.aborted) {
108
+ console.log('Promise 생성자 패치: Promise.reject가 중단된 경우');
102
109
  return Promise.reject(new Error(`REQUEST_ABORTED: Promise.reject가 중단되었습니다 (${currentContext.requestId})`));
103
110
  }
104
111
  return originalReject.call(global.Promise, reason);
@@ -115,6 +122,7 @@ class ContextPromisePatch {
115
122
  const abortSignal = currentContext.abortSignal;
116
123
  const contextId = currentContext.requestId;
117
124
  if (abortSignal.aborted) {
125
+ console.log('Promise 생성자 패치: setTimeout이 중단된 경우');
118
126
  throw new Error(`REQUEST_ABORTED: setTimeout이 중단되었습니다 (${contextId})`);
119
127
  }
120
128
  const wrappedCallback = () => {
@@ -127,6 +135,7 @@ class ContextPromisePatch {
127
135
  return;
128
136
  }
129
137
  if (abortSignal.aborted) {
138
+ console.log('Promise 생성자 패치: setTimeout 콜백이 중단된 경우');
130
139
  throw new Error(`REQUEST_ABORTED: setTimeout 콜백이 중단되었습니다 (${contextId})`);
131
140
  }
132
141
  // eslint-disable-next-line prefer-spread
@@ -138,6 +147,10 @@ class ContextPromisePatch {
138
147
  clearTimeout(timerId);
139
148
  };
140
149
  abortSignal.addEventListener('abort', abortHandler, { once: true });
150
+ abort_context_1.AbortContext.updateContext({
151
+ abortHandler,
152
+ timerId,
153
+ });
141
154
  return timerId;
142
155
  };
143
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-croket-dev/core",
3
- "version": "1.7.38-slowquery.0",
3
+ "version": "1.7.38-slowquery.2",
4
4
  "author": "Yolo Co., Ltd.",
5
5
  "description": "Yolo commonization module",
6
6
  "main": "index.js",