@simplysm/core-common 13.0.0-beta.1
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/.cache/typecheck-browser.tsbuildinfo +1 -0
- package/.cache/typecheck-node.tsbuildinfo +1 -0
- package/.cache/typecheck-tests-browser.tsbuildinfo +1 -0
- package/.cache/typecheck-tests-node.tsbuildinfo +1 -0
- package/README.md +887 -0
- package/dist/common.types.d.ts +74 -0
- package/dist/common.types.d.ts.map +1 -0
- package/dist/common.types.js +5 -0
- package/dist/common.types.js.map +7 -0
- package/dist/env.d.ts +6 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +9 -0
- package/dist/env.js.map +7 -0
- package/dist/errors/argument-error.d.ts +25 -0
- package/dist/errors/argument-error.d.ts.map +1 -0
- package/dist/errors/argument-error.js +18 -0
- package/dist/errors/argument-error.js.map +7 -0
- package/dist/errors/not-implemented-error.d.ts +29 -0
- package/dist/errors/not-implemented-error.d.ts.map +1 -0
- package/dist/errors/not-implemented-error.js +14 -0
- package/dist/errors/not-implemented-error.js.map +7 -0
- package/dist/errors/sd-error.d.ts +27 -0
- package/dist/errors/sd-error.d.ts.map +1 -0
- package/dist/errors/sd-error.js +23 -0
- package/dist/errors/sd-error.js.map +7 -0
- package/dist/errors/timeout-error.d.ts +31 -0
- package/dist/errors/timeout-error.d.ts.map +1 -0
- package/dist/errors/timeout-error.js +17 -0
- package/dist/errors/timeout-error.js.map +7 -0
- package/dist/extensions/arr-ext.d.ts +15 -0
- package/dist/extensions/arr-ext.d.ts.map +1 -0
- package/dist/extensions/arr-ext.helpers.d.ts +19 -0
- package/dist/extensions/arr-ext.helpers.d.ts.map +1 -0
- package/dist/extensions/arr-ext.helpers.js +35 -0
- package/dist/extensions/arr-ext.helpers.js.map +7 -0
- package/dist/extensions/arr-ext.js +546 -0
- package/dist/extensions/arr-ext.js.map +7 -0
- package/dist/extensions/arr-ext.types.d.ts +215 -0
- package/dist/extensions/arr-ext.types.d.ts.map +1 -0
- package/dist/extensions/arr-ext.types.js +1 -0
- package/dist/extensions/arr-ext.types.js.map +7 -0
- package/dist/extensions/map-ext.d.ts +57 -0
- package/dist/extensions/map-ext.d.ts.map +1 -0
- package/dist/extensions/map-ext.js +26 -0
- package/dist/extensions/map-ext.js.map +7 -0
- package/dist/extensions/set-ext.d.ts +36 -0
- package/dist/extensions/set-ext.d.ts.map +1 -0
- package/dist/extensions/set-ext.js +29 -0
- package/dist/extensions/set-ext.js.map +7 -0
- package/dist/features/debounce-queue.d.ts +53 -0
- package/dist/features/debounce-queue.d.ts.map +1 -0
- package/dist/features/debounce-queue.js +80 -0
- package/dist/features/debounce-queue.js.map +7 -0
- package/dist/features/event-emitter.d.ts +66 -0
- package/dist/features/event-emitter.d.ts.map +1 -0
- package/dist/features/event-emitter.js +82 -0
- package/dist/features/event-emitter.js.map +7 -0
- package/dist/features/serial-queue.d.ts +47 -0
- package/dist/features/serial-queue.d.ts.map +1 -0
- package/dist/features/serial-queue.js +66 -0
- package/dist/features/serial-queue.js.map +7 -0
- package/dist/globals.d.ts +12 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +1 -0
- package/dist/globals.js.map +7 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +7 -0
- package/dist/types/date-only.d.ts +152 -0
- package/dist/types/date-only.d.ts.map +1 -0
- package/dist/types/date-only.js +251 -0
- package/dist/types/date-only.js.map +7 -0
- package/dist/types/date-time.d.ts +96 -0
- package/dist/types/date-time.d.ts.map +1 -0
- package/dist/types/date-time.js +220 -0
- package/dist/types/date-time.js.map +7 -0
- package/dist/types/lazy-gc-map.d.ts +80 -0
- package/dist/types/lazy-gc-map.d.ts.map +1 -0
- package/dist/types/lazy-gc-map.js +179 -0
- package/dist/types/lazy-gc-map.js.map +7 -0
- package/dist/types/time.d.ts +68 -0
- package/dist/types/time.d.ts.map +1 -0
- package/dist/types/time.js +151 -0
- package/dist/types/time.js.map +7 -0
- package/dist/types/uuid.d.ts +35 -0
- package/dist/types/uuid.d.ts.map +1 -0
- package/dist/types/uuid.js +71 -0
- package/dist/types/uuid.js.map +7 -0
- package/dist/utils/bytes.d.ts +51 -0
- package/dist/utils/bytes.d.ts.map +1 -0
- package/dist/utils/bytes.js +89 -0
- package/dist/utils/bytes.js.map +7 -0
- package/dist/utils/date-format.d.ts +90 -0
- package/dist/utils/date-format.d.ts.map +1 -0
- package/dist/utils/date-format.js +106 -0
- package/dist/utils/date-format.js.map +7 -0
- package/dist/utils/json.d.ts +34 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +152 -0
- package/dist/utils/json.js.map +7 -0
- package/dist/utils/num.d.ts +60 -0
- package/dist/utils/num.d.ts.map +1 -0
- package/dist/utils/num.js +39 -0
- package/dist/utils/num.js.map +7 -0
- package/dist/utils/obj.d.ts +258 -0
- package/dist/utils/obj.d.ts.map +1 -0
- package/dist/utils/obj.js +538 -0
- package/dist/utils/obj.js.map +7 -0
- package/dist/utils/path.d.ts +23 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +21 -0
- package/dist/utils/path.js.map +7 -0
- package/dist/utils/primitive.d.ts +18 -0
- package/dist/utils/primitive.d.ts.map +1 -0
- package/dist/utils/primitive.js +20 -0
- package/dist/utils/primitive.js.map +7 -0
- package/dist/utils/str.d.ts +103 -0
- package/dist/utils/str.d.ts.map +1 -0
- package/dist/utils/str.js +128 -0
- package/dist/utils/str.js.map +7 -0
- package/dist/utils/template-strings.d.ts +84 -0
- package/dist/utils/template-strings.d.ts.map +1 -0
- package/dist/utils/template-strings.js +49 -0
- package/dist/utils/template-strings.js.map +7 -0
- package/dist/utils/transferable.d.ts +47 -0
- package/dist/utils/transferable.d.ts.map +1 -0
- package/dist/utils/transferable.js +153 -0
- package/dist/utils/transferable.js.map +7 -0
- package/dist/utils/wait.d.ts +19 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +19 -0
- package/dist/utils/wait.js.map +7 -0
- package/dist/utils/xml.d.ts +36 -0
- package/dist/utils/xml.d.ts.map +1 -0
- package/dist/utils/xml.js +51 -0
- package/dist/utils/xml.js.map +7 -0
- package/dist/zip/sd-zip.d.ts +80 -0
- package/dist/zip/sd-zip.d.ts.map +1 -0
- package/dist/zip/sd-zip.js +153 -0
- package/dist/zip/sd-zip.js.map +7 -0
- package/package.json +31 -0
- package/src/common.types.ts +91 -0
- package/src/env.ts +11 -0
- package/src/errors/argument-error.ts +40 -0
- package/src/errors/not-implemented-error.ts +32 -0
- package/src/errors/sd-error.ts +53 -0
- package/src/errors/timeout-error.ts +36 -0
- package/src/extensions/arr-ext.helpers.ts +53 -0
- package/src/extensions/arr-ext.ts +777 -0
- package/src/extensions/arr-ext.types.ts +258 -0
- package/src/extensions/map-ext.ts +86 -0
- package/src/extensions/set-ext.ts +68 -0
- package/src/features/debounce-queue.ts +116 -0
- package/src/features/event-emitter.ts +112 -0
- package/src/features/serial-queue.ts +94 -0
- package/src/globals.ts +12 -0
- package/src/index.ts +55 -0
- package/src/types/date-only.ts +329 -0
- package/src/types/date-time.ts +294 -0
- package/src/types/lazy-gc-map.ts +244 -0
- package/src/types/time.ts +210 -0
- package/src/types/uuid.ts +113 -0
- package/src/utils/bytes.ts +160 -0
- package/src/utils/date-format.ts +239 -0
- package/src/utils/json.ts +230 -0
- package/src/utils/num.ts +97 -0
- package/src/utils/obj.ts +956 -0
- package/src/utils/path.ts +40 -0
- package/src/utils/primitive.ts +33 -0
- package/src/utils/str.ts +252 -0
- package/src/utils/template-strings.ts +132 -0
- package/src/utils/transferable.ts +269 -0
- package/src/utils/wait.ts +40 -0
- package/src/utils/xml.ts +105 -0
- package/src/zip/sd-zip.ts +218 -0
- package/tests/errors/errors.spec.ts +196 -0
- package/tests/extensions/array-extension.spec.ts +790 -0
- package/tests/extensions/map-extension.spec.ts +147 -0
- package/tests/extensions/set-extension.spec.ts +74 -0
- package/tests/types/date-only.spec.ts +636 -0
- package/tests/types/date-time.spec.ts +391 -0
- package/tests/types/lazy-gc-map.spec.ts +692 -0
- package/tests/types/time.spec.ts +559 -0
- package/tests/types/types.spec.ts +55 -0
- package/tests/types/uuid.spec.ts +91 -0
- package/tests/utils/bytes-utils.spec.ts +230 -0
- package/tests/utils/date-format.spec.ts +371 -0
- package/tests/utils/debounce-queue.spec.ts +272 -0
- package/tests/utils/json.spec.ts +475 -0
- package/tests/utils/number.spec.ts +184 -0
- package/tests/utils/object.spec.ts +827 -0
- package/tests/utils/path.spec.ts +78 -0
- package/tests/utils/primitive.spec.ts +55 -0
- package/tests/utils/sd-event-emitter.spec.ts +216 -0
- package/tests/utils/serial-queue.spec.ts +365 -0
- package/tests/utils/string.spec.ts +294 -0
- package/tests/utils/template-strings.spec.ts +96 -0
- package/tests/utils/transferable.spec.ts +698 -0
- package/tests/utils/wait.spec.ts +145 -0
- package/tests/utils/xml.spec.ts +146 -0
- package/tests/zip/sd-zip.spec.ts +234 -0
|
@@ -0,0 +1,272 @@
|
|
|
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
|
+
});
|