@yolo-croket-dev/core 1.7.38-slowquery.3 → 1.7.38-slowquery.5

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.
@@ -11,7 +11,7 @@ interface RequestContext {
11
11
  export declare class AbortContext {
12
12
  private static asyncLocalStorage;
13
13
  private static contextCounter;
14
- static run<T>(abortSignal: AbortSignal, requestId: string, callback: () => T): T;
14
+ static run<T>(abortSignal: AbortSignal, requestId: string, callback: (context: RequestContext) => T): T;
15
15
  static getCurrentAbortSignal(): AbortSignal | null;
16
16
  static getCurrentRequestId(): string | null;
17
17
  static getCurrentContext(): {
@@ -12,7 +12,7 @@ class AbortContext {
12
12
  createdAt: Date.now(),
13
13
  parentContext: currentContext || undefined,
14
14
  };
15
- return this.asyncLocalStorage.run(newContext, callback);
15
+ return this.asyncLocalStorage.run(newContext, callback.bind(this, newContext));
16
16
  }
17
17
  static getCurrentAbortSignal() {
18
18
  const context = this.asyncLocalStorage.getStore();
@@ -1,9 +1,7 @@
1
1
  export declare class ContextPromisePatch {
2
2
  private static isPatched;
3
3
  private static originalPromise;
4
- private static originalSetTimeout;
5
4
  static patch(): void;
6
5
  private static patchPromise;
7
- private static patchSetTimeout;
8
6
  static unpatch(): void;
9
7
  }
@@ -3,13 +3,14 @@ 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;
6
7
  static patch() {
7
8
  if (this.isPatched) {
8
9
  return;
9
10
  }
10
11
  this.originalPromise = global.Promise;
11
12
  this.patchPromise();
12
- this.patchSetTimeout();
13
+ // this.patchSetTimeout();
13
14
  this.isPatched = true;
14
15
  }
15
16
  static patchPromise() {
@@ -104,53 +105,57 @@ class ContextPromisePatch {
104
105
  return originalReject.call(global.Promise, reason);
105
106
  };
106
107
  }
107
- static patchSetTimeout() {
108
- this.originalSetTimeout = global.setTimeout;
109
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
- global.setTimeout = (callback, delay, ...args) => {
111
- const currentContext = abort_context_1.AbortContext.getCurrentContext();
112
- if (!currentContext) {
113
- return this.originalSetTimeout(callback, delay, ...args);
114
- }
115
- const abortSignal = currentContext.abortSignal;
116
- const contextId = currentContext.requestId;
117
- if (abortSignal.aborted) {
118
- throw new Error(`REQUEST_ABORTED: setTimeout이 중단되었습니다 (${contextId})`);
119
- }
120
- const wrappedCallback = () => {
121
- // 컨텍스트가 여전히 유효한지 확인
122
- const currentContextCheck = abort_context_1.AbortContext.getCurrentContext();
123
- if (!currentContextCheck || currentContextCheck.requestId !== contextId) {
124
- // 컨텍스트가 변경되었으면 원본 콜백 실행
125
- // eslint-disable-next-line prefer-spread
126
- callback.apply(null, args);
127
- return;
128
- }
129
- if (abortSignal.aborted) {
130
- throw new Error(`REQUEST_ABORTED: setTimeout 콜백이 중단되었습니다 (${contextId})`);
131
- }
132
- // eslint-disable-next-line prefer-spread
133
- callback.apply(null, args);
134
- };
135
- const timerId = this.originalSetTimeout(wrappedCallback, delay, ...args);
136
- // 중단 이벤트 리스너 등록
137
- const abortHandler = () => {
138
- clearTimeout(timerId);
139
- };
140
- abortSignal.addEventListener('abort', abortHandler, { once: true });
141
- abort_context_1.AbortContext.updateContext({
142
- abortHandler,
143
- timerId,
144
- });
145
- return timerId;
146
- };
147
- }
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
+ // }
148
153
  static unpatch() {
149
154
  if (!this.isPatched) {
150
155
  return;
151
156
  }
152
157
  global.Promise = this.originalPromise;
153
- global.setTimeout = this.originalSetTimeout;
158
+ // global.setTimeout = this.originalSetTimeout;
154
159
  this.isPatched = false;
155
160
  }
156
161
  }
@@ -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, () => next
332
+ return functions_1.AbortContext.run(abortController.signal, execInterceptor.traceId, (context) => next
333
333
  .handle()
334
334
  .pipe((0, operators_1.timeout)({
335
335
  each: this.DEFAULT_TIMEOUT,
@@ -362,7 +362,7 @@ let RPCInterceptor = RPCInterceptor_1 = class RPCInterceptor {
362
362
  }), (0, operators_1.finalize)(() => {
363
363
  this.gracefulShutdownService.popActiveInterceptors(execInterceptor);
364
364
  console.log('finalize called', execInterceptor.traceId);
365
- functions_1.AbortContext.endContext();
365
+ functions_1.AbortContext.endContext(context);
366
366
  abortController = null;
367
367
  return new rxjs_1.Observable();
368
368
  })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-croket-dev/core",
3
- "version": "1.7.38-slowquery.3",
3
+ "version": "1.7.38-slowquery.5",
4
4
  "author": "Yolo Co., Ltd.",
5
5
  "description": "Yolo commonization module",
6
6
  "main": "index.js",