@simplysm/core-common 13.0.0-beta.2 → 13.0.0-beta.21

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.
Files changed (84) hide show
  1. package/dist/common.types.js +4 -4
  2. package/dist/errors/argument-error.js +1 -1
  3. package/dist/errors/not-implemented-error.js +1 -1
  4. package/dist/errors/timeout-error.js +1 -1
  5. package/dist/extensions/arr-ext.helpers.js +4 -4
  6. package/dist/extensions/arr-ext.js +9 -9
  7. package/dist/features/debounce-queue.js +2 -2
  8. package/dist/features/serial-queue.js +3 -3
  9. package/dist/index.js +30 -30
  10. package/dist/types/date-only.js +2 -2
  11. package/dist/types/date-time.js +2 -2
  12. package/dist/types/time.js +2 -2
  13. package/dist/types/uuid.js +1 -1
  14. package/dist/utils/bytes.js +1 -1
  15. package/dist/utils/json.js +8 -8
  16. package/dist/utils/obj.js +5 -5
  17. package/dist/utils/primitive.js +5 -5
  18. package/dist/utils/transferable.js +4 -4
  19. package/dist/utils/wait.js +1 -1
  20. package/package.json +7 -4
  21. package/.cache/typecheck-browser.tsbuildinfo +0 -1
  22. package/.cache/typecheck-node.tsbuildinfo +0 -1
  23. package/.cache/typecheck-tests-browser.tsbuildinfo +0 -1
  24. package/.cache/typecheck-tests-node.tsbuildinfo +0 -1
  25. package/src/common.types.ts +0 -91
  26. package/src/env.ts +0 -11
  27. package/src/errors/argument-error.ts +0 -40
  28. package/src/errors/not-implemented-error.ts +0 -32
  29. package/src/errors/sd-error.ts +0 -53
  30. package/src/errors/timeout-error.ts +0 -36
  31. package/src/extensions/arr-ext.helpers.ts +0 -53
  32. package/src/extensions/arr-ext.ts +0 -777
  33. package/src/extensions/arr-ext.types.ts +0 -258
  34. package/src/extensions/map-ext.ts +0 -86
  35. package/src/extensions/set-ext.ts +0 -68
  36. package/src/features/debounce-queue.ts +0 -116
  37. package/src/features/event-emitter.ts +0 -112
  38. package/src/features/serial-queue.ts +0 -94
  39. package/src/globals.ts +0 -12
  40. package/src/index.ts +0 -55
  41. package/src/types/date-only.ts +0 -329
  42. package/src/types/date-time.ts +0 -294
  43. package/src/types/lazy-gc-map.ts +0 -244
  44. package/src/types/time.ts +0 -210
  45. package/src/types/uuid.ts +0 -113
  46. package/src/utils/bytes.ts +0 -160
  47. package/src/utils/date-format.ts +0 -239
  48. package/src/utils/json.ts +0 -230
  49. package/src/utils/num.ts +0 -97
  50. package/src/utils/obj.ts +0 -956
  51. package/src/utils/path.ts +0 -40
  52. package/src/utils/primitive.ts +0 -33
  53. package/src/utils/str.ts +0 -252
  54. package/src/utils/template-strings.ts +0 -132
  55. package/src/utils/transferable.ts +0 -269
  56. package/src/utils/wait.ts +0 -40
  57. package/src/utils/xml.ts +0 -105
  58. package/src/zip/sd-zip.ts +0 -218
  59. package/tests/errors/errors.spec.ts +0 -196
  60. package/tests/extensions/array-extension.spec.ts +0 -790
  61. package/tests/extensions/map-extension.spec.ts +0 -147
  62. package/tests/extensions/set-extension.spec.ts +0 -74
  63. package/tests/types/date-only.spec.ts +0 -636
  64. package/tests/types/date-time.spec.ts +0 -391
  65. package/tests/types/lazy-gc-map.spec.ts +0 -692
  66. package/tests/types/time.spec.ts +0 -559
  67. package/tests/types/types.spec.ts +0 -55
  68. package/tests/types/uuid.spec.ts +0 -91
  69. package/tests/utils/bytes-utils.spec.ts +0 -230
  70. package/tests/utils/date-format.spec.ts +0 -371
  71. package/tests/utils/debounce-queue.spec.ts +0 -272
  72. package/tests/utils/json.spec.ts +0 -475
  73. package/tests/utils/number.spec.ts +0 -184
  74. package/tests/utils/object.spec.ts +0 -827
  75. package/tests/utils/path.spec.ts +0 -78
  76. package/tests/utils/primitive.spec.ts +0 -55
  77. package/tests/utils/sd-event-emitter.spec.ts +0 -216
  78. package/tests/utils/serial-queue.spec.ts +0 -365
  79. package/tests/utils/string.spec.ts +0 -294
  80. package/tests/utils/template-strings.spec.ts +0 -96
  81. package/tests/utils/transferable.spec.ts +0 -698
  82. package/tests/utils/wait.spec.ts +0 -145
  83. package/tests/utils/xml.spec.ts +0 -146
  84. package/tests/zip/sd-zip.spec.ts +0 -234
@@ -1,272 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { DebounceQueue, waitTime as time, SdError } from "@simplysm/core-common";
3
-
4
- describe("DebounceQueue", () => {
5
- //#region 디바운스 동작
6
-
7
- describe("디바운스 동작", () => {
8
- it("마지막 요청만 실행한다", async () => {
9
- const queue = new DebounceQueue(50);
10
- const calls: number[] = [];
11
-
12
- queue.run(() => {
13
- calls.push(1);
14
- });
15
- queue.run(() => {
16
- calls.push(2);
17
- });
18
- queue.run(() => {
19
- calls.push(3);
20
- });
21
-
22
- // 디바운스 대기
23
- await time(100);
24
-
25
- // 마지막 요청만 실행됨
26
- expect(calls).toEqual([3]);
27
- });
28
-
29
- it("delay 이후에 실행한다", async () => {
30
- const queue = new DebounceQueue(100);
31
- const calls: number[] = [];
32
-
33
- queue.run(() => {
34
- calls.push(1);
35
- });
36
-
37
- // 50ms 후에는 아직 실행 안 됨
38
- await time(50);
39
- expect(calls).toEqual([]);
40
-
41
- // 100ms 후에는 실행됨
42
- await time(100);
43
- expect(calls).toEqual([1]);
44
- });
45
-
46
- it("delay가 없으면 즉시 실행한다", async () => {
47
- const queue = new DebounceQueue();
48
- const calls: number[] = [];
49
-
50
- queue.run(() => {
51
- calls.push(1);
52
- });
53
-
54
- // 약간의 대기 (이벤트 루프)
55
- await time(10);
56
-
57
- expect(calls).toEqual([1]);
58
- });
59
-
60
- it("실행 중에 새 요청이 들어오면 완료 후 실행한다", async () => {
61
- const queue = new DebounceQueue(10);
62
- const calls: number[] = [];
63
-
64
- queue.run(async () => {
65
- calls.push(1);
66
- await time(50); // 실행 중 대기
67
- });
68
-
69
- // 첫 실행 시작 대기
70
- await time(20);
71
-
72
- // 실행 중에 새 요청 추가
73
- queue.run(() => {
74
- calls.push(2);
75
- });
76
-
77
- // 모든 작업 완료 대기
78
- await time(100);
79
-
80
- expect(calls).toEqual([1, 2]);
81
- });
82
- });
83
-
84
- //#endregion
85
-
86
- //#region 에러 처리
87
-
88
- describe("에러 처리", () => {
89
- it("에러 발생 시 error 이벤트를 발생시킨다", async () => {
90
- const queue = new DebounceQueue(10);
91
- const errors: SdError[] = [];
92
-
93
- queue.on("error", (err) => {
94
- errors.push(err);
95
- });
96
-
97
- queue.run(() => {
98
- throw new Error("test error");
99
- });
100
-
101
- await time(50);
102
-
103
- expect(errors).toHaveLength(1);
104
- expect(errors[0]).toBeInstanceOf(SdError);
105
- expect(errors[0].message).toContain("작업 실행 중 오류 발생");
106
- expect(errors[0].message).toContain("test error");
107
- });
108
-
109
- it("에러가 발생해도 다음 요청은 정상 실행된다", async () => {
110
- const queue = new DebounceQueue(10);
111
- const calls: number[] = [];
112
- const errors: SdError[] = [];
113
-
114
- // 에러 리스너 추가하여 unhandled rejection 방지
115
- queue.on("error", (err) => {
116
- errors.push(err);
117
- });
118
-
119
- queue.run(() => {
120
- throw new Error("error");
121
- });
122
-
123
- await time(50);
124
-
125
- queue.run(() => {
126
- calls.push(1);
127
- });
128
-
129
- await time(50);
130
-
131
- expect(calls).toEqual([1]);
132
- expect(errors).toHaveLength(1);
133
- });
134
-
135
- it("실행 중 에러가 발생해도 pendingFn은 실행된다", async () => {
136
- const queue = new DebounceQueue(10);
137
- const calls: number[] = [];
138
- const errors: SdError[] = [];
139
-
140
- queue.on("error", (err) => {
141
- errors.push(err);
142
- });
143
-
144
- // 첫 요청: 에러 발생
145
- queue.run(() => {
146
- calls.push(1);
147
- throw new Error("error 1");
148
- });
149
-
150
- await time(20);
151
-
152
- // 실행 중 새 요청 추가
153
- queue.run(() => {
154
- calls.push(2);
155
- });
156
-
157
- await time(100);
158
-
159
- expect(calls).toEqual([1, 2]);
160
- expect(errors).toHaveLength(1);
161
- });
162
- });
163
-
164
- //#endregion
165
-
166
- //#region dispose
167
-
168
- describe("dispose()", () => {
169
- it("대기 중인 작업과 타이머를 정리한다", async () => {
170
- const queue = new DebounceQueue(100);
171
- const calls: number[] = [];
172
-
173
- queue.run(() => {
174
- calls.push(1);
175
- });
176
-
177
- // 디바운스 대기 중 dispose
178
- await time(50);
179
- queue.dispose();
180
-
181
- // 디바운스 시간 경과 후에도 실행 안 됨
182
- await time(100);
183
-
184
- expect(calls).toEqual([]);
185
- });
186
-
187
- it("dispose 후 새 작업은 무시된다", async () => {
188
- const queue = new DebounceQueue(50);
189
- const calls: number[] = [];
190
-
191
- queue.run(() => {
192
- calls.push(1);
193
- });
194
- queue.dispose();
195
-
196
- // dispose 후 새 작업 추가 - 무시됨
197
- queue.run(() => {
198
- calls.push(2);
199
- });
200
-
201
- await time(100);
202
-
203
- // dispose 후 새 작업은 실행되지 않음
204
- expect(calls).toEqual([]);
205
- });
206
-
207
- it("여러 번 호출해도 안전하다", () => {
208
- const queue = new DebounceQueue(50);
209
-
210
- // 여러 번 호출해도 에러 없음
211
- queue.dispose();
212
- queue.dispose();
213
- queue.dispose();
214
- });
215
-
216
- it("using 문으로 자동 dispose된다", async () => {
217
- const calls: number[] = [];
218
- {
219
- using queue = new DebounceQueue(100);
220
- queue.run(() => {
221
- calls.push(1);
222
- });
223
- await time(50);
224
- } // using 블록 종료 시 dispose 자동 호출
225
- await time(100);
226
- // 디바운스 대기 중 dispose되어 실행 안 됨
227
- expect(calls).toEqual([]);
228
- });
229
- });
230
-
231
- //#endregion
232
-
233
- //#region 동기 함수 지원
234
-
235
- describe("동기 함수 지원", () => {
236
- it("동기 함수도 실행할 수 있다", async () => {
237
- const queue = new DebounceQueue(10);
238
- const calls: number[] = [];
239
-
240
- queue.run(() => {
241
- calls.push(1);
242
- });
243
-
244
- await time(50);
245
-
246
- expect(calls).toEqual([1]);
247
- });
248
-
249
- it("동기/비동기 함수를 혼합해서 사용할 수 있다", async () => {
250
- const queue = new DebounceQueue(10);
251
- const calls: number[] = [];
252
-
253
- queue.run(() => {
254
- calls.push(1);
255
- });
256
- queue.run(async () => {
257
- await time(10);
258
- calls.push(2);
259
- });
260
- queue.run(() => {
261
- calls.push(3);
262
- });
263
-
264
- await time(100);
265
-
266
- // 마지막 요청만 실행
267
- expect(calls).toEqual([3]);
268
- });
269
- });
270
-
271
- //#endregion
272
- });