@yolo-croket-dev/core 1.7.38-slowquery.6 → 1.7.38-slowquery.8
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/functions/abort/abort-context.d.ts +1 -3
- package/functions/abort/abort-context.js +3 -12
- package/functions/abort/context-promise-patch.js +0 -48
- package/functions/abort/index.d.ts +0 -1
- package/functions/abort/index.js +0 -1
- package/interceptors/rpc.interceptor.js +2 -6
- package/package.json +1 -1
- package/functions/abort/enhanced-promise-patch.d.ts +0 -17
- package/functions/abort/enhanced-promise-patch.js +0 -115
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
interface RequestContext {
|
|
4
3
|
abortSignal: AbortSignal;
|
|
5
4
|
requestId: string;
|
|
6
5
|
createdAt: number;
|
|
7
6
|
parentContext?: RequestContext;
|
|
8
|
-
abortHandler?: () => void;
|
|
9
|
-
timerId?: NodeJS.Timeout;
|
|
10
7
|
}
|
|
11
8
|
export declare class AbortContext {
|
|
12
9
|
private static asyncLocalStorage;
|
|
@@ -18,6 +15,7 @@ export declare class AbortContext {
|
|
|
18
15
|
abortSignal: AbortSignal;
|
|
19
16
|
requestId: string;
|
|
20
17
|
} | null;
|
|
18
|
+
static disable(): void;
|
|
21
19
|
static endContext(context?: RequestContext): void;
|
|
22
20
|
static updateContext(updatedData: Partial<RequestContext>): void;
|
|
23
21
|
/**
|
|
@@ -32,24 +32,17 @@ class AbortContext {
|
|
|
32
32
|
}
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
|
+
static disable() {
|
|
36
|
+
this.asyncLocalStorage.disable();
|
|
37
|
+
}
|
|
35
38
|
// 컨텍스트 종료
|
|
36
39
|
// eslint-disable-next-line consistent-return
|
|
37
40
|
static endContext(context) {
|
|
38
41
|
const selectContext = context || this.asyncLocalStorage.getStore();
|
|
39
|
-
console.log('selectContext', selectContext);
|
|
40
42
|
if (selectContext) {
|
|
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
|
-
}
|
|
49
43
|
this.asyncLocalStorage.disable();
|
|
50
44
|
// parent context가 있으면 전부 종료
|
|
51
45
|
if (selectContext.parentContext) {
|
|
52
|
-
console.log('selectContext.parentContext', selectContext.parentContext);
|
|
53
46
|
return this.endContext(selectContext.parentContext);
|
|
54
47
|
}
|
|
55
48
|
}
|
|
@@ -58,7 +51,6 @@ class AbortContext {
|
|
|
58
51
|
static updateContext(updatedData) {
|
|
59
52
|
const currentContext = this.asyncLocalStorage.getStore();
|
|
60
53
|
if (!currentContext) {
|
|
61
|
-
console.log('currentContext not found');
|
|
62
54
|
return;
|
|
63
55
|
}
|
|
64
56
|
// 업데이트할 데이터만 갱신
|
|
@@ -67,7 +59,6 @@ class AbortContext {
|
|
|
67
59
|
...updatedData,
|
|
68
60
|
updatedAt: Date.now(), // `updatedAt` 값을 갱신
|
|
69
61
|
};
|
|
70
|
-
console.log('currentContext update!', currentContext, updatedContext);
|
|
71
62
|
// 업데이트된 컨텍스트를 다시 저장
|
|
72
63
|
this.asyncLocalStorage.enterWith(updatedContext);
|
|
73
64
|
}
|
|
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ContextPromisePatch = void 0;
|
|
4
4
|
const abort_context_1 = require("./abort-context");
|
|
5
5
|
class ContextPromisePatch {
|
|
6
|
-
// private static originalSetTimeout: typeof setTimeout;
|
|
7
6
|
static patch() {
|
|
8
7
|
if (this.isPatched) {
|
|
9
8
|
return;
|
|
10
9
|
}
|
|
11
10
|
this.originalPromise = global.Promise;
|
|
12
11
|
this.patchPromise();
|
|
13
|
-
// this.patchSetTimeout();
|
|
14
12
|
this.isPatched = true;
|
|
15
13
|
}
|
|
16
14
|
static patchPromise() {
|
|
@@ -105,57 +103,11 @@ class ContextPromisePatch {
|
|
|
105
103
|
return originalReject.call(global.Promise, reason);
|
|
106
104
|
};
|
|
107
105
|
}
|
|
108
|
-
// private static patchSetTimeout(): void {
|
|
109
|
-
// this.originalSetTimeout = global.setTimeout;
|
|
110
|
-
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
-
// (global as any).setTimeout = (callback: () => void, delay: number, ...args: unknown[]) => {
|
|
112
|
-
// const currentContext = AbortContext.getCurrentContext();
|
|
113
|
-
// if (!currentContext) {
|
|
114
|
-
// return (this.originalSetTimeout as (...args: unknown[]) => unknown)(
|
|
115
|
-
// callback,
|
|
116
|
-
// delay,
|
|
117
|
-
// ...args as [unknown],
|
|
118
|
-
// );
|
|
119
|
-
// }
|
|
120
|
-
// const abortSignal: AbortSignal = currentContext.abortSignal;
|
|
121
|
-
// const contextId: string = currentContext.requestId;
|
|
122
|
-
// if (abortSignal.aborted) {
|
|
123
|
-
// throw new Error(`REQUEST_ABORTED: setTimeout이 중단되었습니다 (${contextId})`);
|
|
124
|
-
// }
|
|
125
|
-
// const wrappedCallback = () => {
|
|
126
|
-
// // 컨텍스트가 여전히 유효한지 확인
|
|
127
|
-
// const currentContextCheck = AbortContext.getCurrentContext();
|
|
128
|
-
// if (!currentContextCheck || currentContextCheck.requestId !== contextId) {
|
|
129
|
-
// // 컨텍스트가 변경되었으면 원본 콜백 실행
|
|
130
|
-
// // eslint-disable-next-line prefer-spread
|
|
131
|
-
// callback.apply(null, args as []);
|
|
132
|
-
// return;
|
|
133
|
-
// }
|
|
134
|
-
// if (abortSignal.aborted) {
|
|
135
|
-
// throw new Error(`REQUEST_ABORTED: setTimeout 콜백이 중단되었습니다 (${contextId})`);
|
|
136
|
-
// }
|
|
137
|
-
// // eslint-disable-next-line prefer-spread
|
|
138
|
-
// callback.apply(null, args as []);
|
|
139
|
-
// };
|
|
140
|
-
// const timerId = this.originalSetTimeout(wrappedCallback, delay, ...args as []);
|
|
141
|
-
// // 중단 이벤트 리스너 등록
|
|
142
|
-
// const abortHandler = () => {
|
|
143
|
-
// clearTimeout(timerId);
|
|
144
|
-
// };
|
|
145
|
-
// abortSignal.addEventListener('abort', abortHandler, { once: true });
|
|
146
|
-
// AbortContext.updateContext({
|
|
147
|
-
// abortHandler,
|
|
148
|
-
// timerId,
|
|
149
|
-
// });
|
|
150
|
-
// return timerId;
|
|
151
|
-
// };
|
|
152
|
-
// }
|
|
153
106
|
static unpatch() {
|
|
154
107
|
if (!this.isPatched) {
|
|
155
108
|
return;
|
|
156
109
|
}
|
|
157
110
|
global.Promise = this.originalPromise;
|
|
158
|
-
// global.setTimeout = this.originalSetTimeout;
|
|
159
111
|
this.isPatched = false;
|
|
160
112
|
}
|
|
161
113
|
}
|
package/functions/abort/index.js
CHANGED
|
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./abort"), exports);
|
|
18
18
|
__exportStar(require("./abort-context"), exports);
|
|
19
|
-
__exportStar(require("./enhanced-promise-patch"), exports);
|
|
@@ -329,7 +329,7 @@ let RPCInterceptor = RPCInterceptor_1 = class RPCInterceptor {
|
|
|
329
329
|
}
|
|
330
330
|
this.gracefulShutdownService.pushActiveInterceptors(execInterceptor);
|
|
331
331
|
// eslint-disable-next-line consistent-return
|
|
332
|
-
return functions_1.AbortContext.run(abortController.signal, execInterceptor.traceId, (
|
|
332
|
+
return functions_1.AbortContext.run(abortController.signal, execInterceptor.traceId, () => next
|
|
333
333
|
.handle()
|
|
334
334
|
.pipe((0, operators_1.timeout)({
|
|
335
335
|
each: this.DEFAULT_TIMEOUT,
|
|
@@ -361,11 +361,7 @@ let RPCInterceptor = RPCInterceptor_1 = class RPCInterceptor {
|
|
|
361
361
|
error: localErrorProcessor,
|
|
362
362
|
}), (0, operators_1.finalize)(() => {
|
|
363
363
|
this.gracefulShutdownService.popActiveInterceptors(execInterceptor);
|
|
364
|
-
|
|
365
|
-
console.log('before endContext', context);
|
|
366
|
-
functions_1.AbortContext.endContext(context);
|
|
367
|
-
console.log('after endContext');
|
|
368
|
-
functions_1.AbortContext.endContext();
|
|
364
|
+
functions_1.AbortContext.disable();
|
|
369
365
|
abortController = null;
|
|
370
366
|
return rxjs_1.EMPTY;
|
|
371
367
|
})));
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
var Promise: PromiseConstructor;
|
|
3
|
-
}
|
|
4
|
-
export declare class EnhancedPromisePatch {
|
|
5
|
-
private static isPatched;
|
|
6
|
-
private static originalPromise;
|
|
7
|
-
private static originalSetTimeout;
|
|
8
|
-
static patch(): void;
|
|
9
|
-
private static patchPromise;
|
|
10
|
-
private static patchSetTimeout;
|
|
11
|
-
static unpatch(): void;
|
|
12
|
-
/**
|
|
13
|
-
* 현재 패치 상태 확인
|
|
14
|
-
* @returns 패치 여부
|
|
15
|
-
*/
|
|
16
|
-
static getPatchStatus(): boolean;
|
|
17
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnhancedPromisePatch = void 0;
|
|
4
|
-
const abort_1 = require("./abort");
|
|
5
|
-
class EnhancedPromisePatch {
|
|
6
|
-
static patch() {
|
|
7
|
-
if (this.isPatched) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
this.patchPromise();
|
|
11
|
-
this.patchSetTimeout();
|
|
12
|
-
this.isPatched = true;
|
|
13
|
-
}
|
|
14
|
-
static patchPromise() {
|
|
15
|
-
this.originalPromise = global.Promise;
|
|
16
|
-
// Promise 생성자 패치
|
|
17
|
-
global.Promise = new Proxy(global.Promise, {
|
|
18
|
-
construct(target, args) {
|
|
19
|
-
const abortSignal = (0, abort_1.getCurrentAbortSignal)();
|
|
20
|
-
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
21
|
-
return Promise.reject(new Error('REQUEST_ABORTED: Promise가 중단되었습니다'));
|
|
22
|
-
}
|
|
23
|
-
// target은 Promise 생성자이므로, new 연산자와 함께 사용해야 하며, args는 [executor] 형태의 튜플임을 명시합니다.
|
|
24
|
-
const promise = Reflect.construct(target, args);
|
|
25
|
-
if (!abortSignal) {
|
|
26
|
-
return promise;
|
|
27
|
-
}
|
|
28
|
-
// Promise 체인에 중단 확인 추가
|
|
29
|
-
return promise.then((result) => {
|
|
30
|
-
if (abortSignal.aborted) {
|
|
31
|
-
throw new Error('REQUEST_ABORTED: Promise 실행 중 중단되었습니다');
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}, (error) => {
|
|
35
|
-
if (abortSignal.aborted) {
|
|
36
|
-
throw new Error('REQUEST_ABORTED: Promise 실행 중 중단되었습니다');
|
|
37
|
-
}
|
|
38
|
-
throw error;
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
// Promise.resolve 패치
|
|
43
|
-
const originalResolve = global.Promise.resolve;
|
|
44
|
-
global.Promise.resolve = (value) => {
|
|
45
|
-
const abortSignal = (0, abort_1.getCurrentAbortSignal)();
|
|
46
|
-
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
47
|
-
return Promise.reject(new Error('REQUEST_ABORTED: Promise.resolve가 중단되었습니다'));
|
|
48
|
-
}
|
|
49
|
-
const promise = originalResolve.call(global.Promise, value);
|
|
50
|
-
if (!abortSignal) {
|
|
51
|
-
return promise;
|
|
52
|
-
}
|
|
53
|
-
return promise.then((result) => {
|
|
54
|
-
if (abortSignal.aborted) {
|
|
55
|
-
throw new Error('REQUEST_ABORTED: Promise.resolve 실행 중 중단되었습니다');
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
}, (error) => {
|
|
59
|
-
if (abortSignal.aborted) {
|
|
60
|
-
throw new Error('REQUEST_ABORTED: Promise.resolve 실행 중 중단되었습니다');
|
|
61
|
-
}
|
|
62
|
-
throw error;
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
// Promise.reject 패치
|
|
66
|
-
const originalReject = global.Promise.reject;
|
|
67
|
-
global.Promise.reject = (reason) => {
|
|
68
|
-
const abortSignal = (0, abort_1.getCurrentAbortSignal)();
|
|
69
|
-
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
70
|
-
return Promise.reject(new Error('REQUEST_ABORTED: Promise.reject가 중단되었습니다'));
|
|
71
|
-
}
|
|
72
|
-
return originalReject.call(global.Promise, reason);
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
static patchSetTimeout() {
|
|
76
|
-
this.originalSetTimeout = global.setTimeout;
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
78
|
-
global.setTimeout = (callback, delay, ...args) => {
|
|
79
|
-
const abortSignal = (0, abort_1.getCurrentAbortSignal)();
|
|
80
|
-
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
81
|
-
throw new Error('REQUEST_ABORTED: setTimeout이 중단되었습니다');
|
|
82
|
-
}
|
|
83
|
-
const timerId = this.originalSetTimeout(() => {
|
|
84
|
-
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
85
|
-
throw new Error('REQUEST_ABORTED: setTimeout 콜백이 중단되었습니다');
|
|
86
|
-
}
|
|
87
|
-
callback(...args);
|
|
88
|
-
}, delay);
|
|
89
|
-
if (abortSignal) {
|
|
90
|
-
const abortHandler = () => {
|
|
91
|
-
clearTimeout(timerId);
|
|
92
|
-
};
|
|
93
|
-
abortSignal.addEventListener('abort', abortHandler, { once: true });
|
|
94
|
-
}
|
|
95
|
-
return timerId;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
static unpatch() {
|
|
99
|
-
if (!this.isPatched) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
global.Promise = this.originalPromise;
|
|
103
|
-
global.setTimeout = this.originalSetTimeout;
|
|
104
|
-
this.isPatched = false;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* 현재 패치 상태 확인
|
|
108
|
-
* @returns 패치 여부
|
|
109
|
-
*/
|
|
110
|
-
static getPatchStatus() {
|
|
111
|
-
return this.isPatched;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.EnhancedPromisePatch = EnhancedPromisePatch;
|
|
115
|
-
EnhancedPromisePatch.isPatched = false;
|