@simplysm/core-common 13.0.99 → 14.0.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/dist/common.types.d.ts +14 -14
- package/dist/common.types.js +2 -1
- package/dist/common.types.js.map +1 -6
- package/dist/env.d.ts +5 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +12 -8
- package/dist/env.js.map +1 -6
- package/dist/errors/argument-error.d.ts +10 -10
- package/dist/errors/argument-error.d.ts.map +1 -1
- package/dist/errors/argument-error.js +31 -14
- package/dist/errors/argument-error.js.map +1 -6
- package/dist/errors/not-implemented-error.d.ts +8 -8
- package/dist/errors/not-implemented-error.js +30 -12
- package/dist/errors/not-implemented-error.js.map +1 -6
- package/dist/errors/sd-error.d.ts +10 -10
- package/dist/errors/sd-error.d.ts.map +1 -1
- package/dist/errors/sd-error.js +45 -24
- package/dist/errors/sd-error.js.map +1 -6
- package/dist/errors/timeout-error.d.ts +10 -10
- package/dist/errors/timeout-error.js +34 -15
- package/dist/errors/timeout-error.js.map +1 -6
- package/dist/extensions/arr-ext.d.ts +2 -2
- package/dist/extensions/arr-ext.helpers.d.ts +10 -10
- package/dist/extensions/arr-ext.helpers.js +112 -89
- package/dist/extensions/arr-ext.helpers.js.map +1 -6
- package/dist/extensions/arr-ext.js +458 -422
- package/dist/extensions/arr-ext.js.map +1 -6
- package/dist/extensions/arr-ext.types.d.ts +57 -57
- package/dist/extensions/arr-ext.types.d.ts.map +1 -1
- package/dist/extensions/arr-ext.types.js +6 -1
- package/dist/extensions/arr-ext.types.js.map +1 -6
- package/dist/extensions/map-ext.d.ts +16 -16
- package/dist/extensions/map-ext.js +27 -22
- package/dist/extensions/map-ext.js.map +1 -6
- package/dist/extensions/set-ext.d.ts +11 -11
- package/dist/extensions/set-ext.js +32 -25
- package/dist/extensions/set-ext.js.map +1 -6
- package/dist/features/debounce-queue.d.ts +17 -17
- package/dist/features/debounce-queue.js +98 -70
- package/dist/features/debounce-queue.js.map +1 -6
- package/dist/features/event-emitter.d.ts +20 -20
- package/dist/features/event-emitter.js +101 -78
- package/dist/features/event-emitter.js.map +1 -6
- package/dist/features/serial-queue.d.ts +11 -11
- package/dist/features/serial-queue.js +78 -57
- package/dist/features/serial-queue.js.map +1 -6
- package/dist/globals.d.ts +4 -4
- package/dist/globals.js +9 -1
- package/dist/globals.js.map +1 -6
- package/dist/index.js +28 -27
- package/dist/index.js.map +1 -6
- package/dist/types/date-only.d.ts +64 -64
- package/dist/types/date-only.d.ts.map +1 -1
- package/dist/types/date-only.js +263 -252
- package/dist/types/date-only.js.map +1 -6
- package/dist/types/date-time.d.ts +36 -36
- package/dist/types/date-time.d.ts.map +1 -1
- package/dist/types/date-time.js +196 -288
- package/dist/types/date-time.js.map +1 -6
- package/dist/types/lazy-gc-map.d.ts +26 -26
- package/dist/types/lazy-gc-map.d.ts.map +1 -1
- package/dist/types/lazy-gc-map.js +202 -159
- package/dist/types/lazy-gc-map.js.map +1 -6
- package/dist/types/time.d.ts +23 -23
- package/dist/types/time.d.ts.map +1 -1
- package/dist/types/time.js +169 -158
- package/dist/types/time.js.map +1 -6
- package/dist/types/uuid.d.ts +11 -11
- package/dist/types/uuid.d.ts.map +1 -1
- package/dist/types/uuid.js +95 -70
- package/dist/types/uuid.js.map +1 -6
- package/dist/utils/bytes.d.ts +17 -17
- package/dist/utils/bytes.js +137 -81
- package/dist/utils/bytes.js.map +1 -6
- package/dist/utils/date-format.d.ts +40 -40
- package/dist/utils/date-format.js +187 -101
- package/dist/utils/date-format.js.map +1 -6
- package/dist/utils/error.d.ts +4 -4
- package/dist/utils/error.js +11 -6
- package/dist/utils/error.js.map +1 -6
- package/dist/utils/json.d.ts +19 -19
- package/dist/utils/json.js +187 -135
- package/dist/utils/json.js.map +1 -6
- package/dist/utils/num.d.ts +20 -20
- package/dist/utils/num.js +76 -34
- package/dist/utils/num.js.map +1 -6
- package/dist/utils/obj.d.ts +111 -111
- package/dist/utils/obj.d.ts.map +1 -1
- package/dist/utils/obj.js +706 -496
- package/dist/utils/obj.js.map +1 -6
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +35 -18
- package/dist/utils/path.js.map +1 -6
- package/dist/utils/primitive.d.ts +5 -5
- package/dist/utils/primitive.js +34 -14
- package/dist/utils/primitive.js.map +1 -6
- package/dist/utils/str.d.ts +38 -38
- package/dist/utils/str.js +217 -113
- package/dist/utils/str.js.map +1 -6
- package/dist/utils/template-strings.d.ts +26 -26
- package/dist/utils/template-strings.js +113 -40
- package/dist/utils/template-strings.js.map +1 -6
- package/dist/utils/transferable.d.ts +18 -18
- package/dist/utils/transferable.js +218 -151
- package/dist/utils/transferable.js.map +1 -6
- package/dist/utils/wait.d.ts +9 -9
- package/dist/utils/wait.js +30 -15
- package/dist/utils/wait.js.map +1 -6
- package/dist/utils/xml.d.ts +13 -13
- package/dist/utils/xml.js +84 -46
- package/dist/utils/xml.js.map +1 -6
- package/dist/utils/zip.d.ts +22 -22
- package/dist/utils/zip.js +172 -148
- package/dist/utils/zip.js.map +1 -6
- package/package.json +5 -7
- package/src/common.types.ts +14 -14
- package/src/env.ts +9 -1
- package/src/errors/argument-error.ts +15 -15
- package/src/errors/not-implemented-error.ts +9 -9
- package/src/errors/sd-error.ts +12 -12
- package/src/errors/timeout-error.ts +12 -12
- package/src/extensions/arr-ext.helpers.ts +16 -16
- package/src/extensions/arr-ext.ts +35 -35
- package/src/extensions/arr-ext.types.ts +57 -57
- package/src/extensions/map-ext.ts +16 -16
- package/src/extensions/set-ext.ts +11 -11
- package/src/features/debounce-queue.ts +23 -23
- package/src/features/event-emitter.ts +25 -25
- package/src/features/serial-queue.ts +13 -13
- package/src/globals.ts +4 -4
- package/src/index.ts +5 -5
- package/src/types/date-only.ts +84 -83
- package/src/types/date-time.ts +43 -42
- package/src/types/lazy-gc-map.ts +44 -44
- package/src/types/time.ts +29 -29
- package/src/types/uuid.ts +15 -15
- package/src/utils/bytes.ts +35 -35
- package/src/utils/date-format.ts +59 -59
- package/src/utils/error.ts +4 -4
- package/src/utils/json.ts +41 -41
- package/src/utils/num.ts +20 -20
- package/src/utils/obj.ts +138 -138
- package/src/utils/path.ts +10 -10
- package/src/utils/primitive.ts +6 -6
- package/src/utils/str.ts +48 -48
- package/src/utils/template-strings.ts +29 -29
- package/src/utils/transferable.ts +38 -38
- package/src/utils/wait.ts +10 -10
- package/src/utils/xml.ts +19 -19
- package/src/utils/zip.ts +25 -25
- package/README.md +0 -160
- package/docs/errors.md +0 -119
- package/docs/extensions.md +0 -387
- package/docs/features.md +0 -143
- package/docs/types.md +0 -287
- package/docs/utils.md +0 -757
- package/tests/errors/errors.spec.ts +0 -80
- package/tests/extensions/array-extension.spec.ts +0 -654
- package/tests/extensions/map-extension.spec.ts +0 -117
- package/tests/extensions/set-extension.spec.ts +0 -67
- package/tests/types/date-only.spec.ts +0 -533
- package/tests/types/date-time.spec.ts +0 -246
- package/tests/types/lazy-gc-map.spec.ts +0 -606
- package/tests/types/time.spec.ts +0 -428
- package/tests/types/uuid.spec.ts +0 -74
- package/tests/utils/bytes-utils.spec.ts +0 -197
- package/tests/utils/date-format.spec.ts +0 -350
- package/tests/utils/debounce-queue.spec.ts +0 -226
- package/tests/utils/json.spec.ts +0 -400
- package/tests/utils/number.spec.ts +0 -136
- package/tests/utils/object.spec.ts +0 -810
- package/tests/utils/path.spec.ts +0 -70
- package/tests/utils/primitive.spec.ts +0 -43
- package/tests/utils/sd-event-emitter.spec.ts +0 -189
- package/tests/utils/serial-queue.spec.ts +0 -305
- package/tests/utils/string.spec.ts +0 -265
- package/tests/utils/template-strings.spec.ts +0 -48
- package/tests/utils/transferable.spec.ts +0 -639
- package/tests/utils/wait.spec.ts +0 -123
- package/tests/utils/xml.spec.ts +0 -146
- package/tests/utils/zip.spec.ts +0 -221
package/src/utils/xml.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* XML
|
|
2
|
+
* XML 변환 유틸리티
|
|
3
3
|
*/
|
|
4
4
|
import type { XmlBuilderOptions } from "fast-xml-parser";
|
|
5
5
|
import { XMLBuilder, XMLParser } from "fast-xml-parser";
|
|
@@ -7,14 +7,14 @@ import { XMLBuilder, XMLParser } from "fast-xml-parser";
|
|
|
7
7
|
//#region parse
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param str XML
|
|
12
|
-
* @param options
|
|
13
|
-
* @param options.stripTagPrefix
|
|
14
|
-
* @returns
|
|
15
|
-
* -
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
10
|
+
* XML 문자열을 객체로 파싱
|
|
11
|
+
* @param str XML 문자열
|
|
12
|
+
* @param options 옵션
|
|
13
|
+
* @param options.stripTagPrefix 태그 접두사(네임스페이스) 제거 여부
|
|
14
|
+
* @returns 파싱된 객체. 구조:
|
|
15
|
+
* - 속성: `$` 객체에 그룹화
|
|
16
|
+
* - 텍스트 노드: `_` key에 저장
|
|
17
|
+
* - 자식 요소: array로 변환 (루트 요소 제외)
|
|
18
18
|
* @example
|
|
19
19
|
* xmlParse('<root id="1"><item>hello</item></root>');
|
|
20
20
|
* // { root: { $: { id: "1" }, item: [{ _: "hello" }] } }
|
|
@@ -40,10 +40,10 @@ export function parse(str: string, options?: { stripTagPrefix?: boolean }): unkn
|
|
|
40
40
|
//#region stringify
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param obj
|
|
45
|
-
* @param options fast-xml-parser XmlBuilderOptions (
|
|
46
|
-
* @returns XML
|
|
43
|
+
* 객체를 XML 문자열로 직렬화
|
|
44
|
+
* @param obj 직렬화할 객체
|
|
45
|
+
* @param options fast-xml-parser XmlBuilderOptions (선택사항)
|
|
46
|
+
* @returns XML 문자열
|
|
47
47
|
* @example
|
|
48
48
|
* xmlStringify({
|
|
49
49
|
* root: {
|
|
@@ -69,10 +69,10 @@ export function stringify(obj: unknown, options?: XmlBuilderOptions): string {
|
|
|
69
69
|
//#region private
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @note
|
|
74
|
-
*
|
|
75
|
-
*
|
|
72
|
+
* 태그 이름에서 네임스페이스 접두사 제거
|
|
73
|
+
* @note XML 파싱 결과에서 "ns:tag" 형식의 네임스페이스 접두사를 제거하여 태그 이름만 남김.
|
|
74
|
+
* 네임스페이스를 고려하지 않고 XML 데이터에 일관되게 접근 가능.
|
|
75
|
+
* 단, 속성은 접두사가 유지됨.
|
|
76
76
|
*/
|
|
77
77
|
function stripTagPrefix(obj: unknown): unknown {
|
|
78
78
|
if (Array.isArray(obj)) {
|
|
@@ -86,11 +86,11 @@ function stripTagPrefix(obj: unknown): unknown {
|
|
|
86
86
|
for (const key of Object.keys(record)) {
|
|
87
87
|
const value = record[key];
|
|
88
88
|
|
|
89
|
-
//
|
|
89
|
+
// 속성은 접두사를 제거하면 안 됨
|
|
90
90
|
if (key === "$") {
|
|
91
91
|
newObj[key] = value;
|
|
92
92
|
} else {
|
|
93
|
-
//
|
|
93
|
+
// 첫 번째 ":"를 기준으로 태그 이름에서만 접두사 제거
|
|
94
94
|
const colonIndex = key.indexOf(":");
|
|
95
95
|
const cleanKey = colonIndex !== -1 ? key.slice(colonIndex + 1) : key;
|
|
96
96
|
newObj[cleanKey] = stripTagPrefix(value);
|
package/src/utils/zip.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ZIP
|
|
2
|
+
* ZIP 파일 처리 유틸리티
|
|
3
3
|
*/
|
|
4
4
|
import type { FileEntry } from "@zip.js/zip.js";
|
|
5
5
|
import {
|
|
@@ -18,25 +18,25 @@ export interface ZipArchiveProgress {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* ZIP
|
|
21
|
+
* ZIP 아카이브 처리 클래스
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* ZIP 파일의 읽기, 쓰기, 압축, 해제를 처리.
|
|
24
|
+
* 동일 파일의 중복 해제를 방지하기 위해 내부 캐싱 사용.
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
27
|
-
* //
|
|
27
|
+
* // ZIP 파일 읽기
|
|
28
28
|
* await using archive = new ZipArchive(zipBytes);
|
|
29
29
|
* const content = await archive.get("file.txt");
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
|
-
* //
|
|
32
|
+
* // ZIP 파일 생성
|
|
33
33
|
* await using archive = new ZipArchive();
|
|
34
34
|
* archive.write("file.txt", textBytes);
|
|
35
35
|
* archive.write("data.json", jsonBytes);
|
|
36
36
|
* const zipBytes = await archive.compress();
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
|
-
* //
|
|
39
|
+
* // 모든 파일 추출 (진행률 보고 포함)
|
|
40
40
|
* await using archive = new ZipArchive(zipBytes);
|
|
41
41
|
* const files = await archive.extractAll((progress) => {
|
|
42
42
|
* console.log(`${progress.fileName}: ${progress.extractedSize}/${progress.totalSize}`);
|
|
@@ -48,8 +48,8 @@ export class ZipArchive {
|
|
|
48
48
|
private _entries?: Awaited<ReturnType<ZipReader<Blob | Bytes>["getEntries"]>>;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @param data ZIP
|
|
51
|
+
* ZipArchive 생성
|
|
52
|
+
* @param data ZIP 데이터 (생략하면 새 아카이브 생성)
|
|
53
53
|
*/
|
|
54
54
|
constructor(data?: Blob | Bytes) {
|
|
55
55
|
if (!data) return;
|
|
@@ -70,8 +70,8 @@ export class ZipArchive {
|
|
|
70
70
|
|
|
71
71
|
//#region extractAll
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
74
|
-
* @param progressCallback
|
|
73
|
+
* 모든 파일 추출
|
|
74
|
+
* @param progressCallback 진행률 콜백
|
|
75
75
|
*/
|
|
76
76
|
async extractAll(
|
|
77
77
|
progressCallback?: (progress: ZipArchiveProgress) => void,
|
|
@@ -79,7 +79,7 @@ export class ZipArchive {
|
|
|
79
79
|
const entries = await this._getEntries();
|
|
80
80
|
if (entries == null) return this._cache;
|
|
81
81
|
|
|
82
|
-
//
|
|
82
|
+
// 추출할 전체 크기 계산
|
|
83
83
|
const totalSize = entries
|
|
84
84
|
.filter((e) => !e.directory)
|
|
85
85
|
.reduce((acc, e) => acc + e.uncompressedSize, 0);
|
|
@@ -112,7 +112,7 @@ export class ZipArchive {
|
|
|
112
112
|
|
|
113
113
|
this._cache.set(entry.filename, entryBytes);
|
|
114
114
|
|
|
115
|
-
//
|
|
115
|
+
// 개별 파일 완료 시 누적
|
|
116
116
|
totalExtracted += entry.uncompressedSize;
|
|
117
117
|
|
|
118
118
|
progressCallback?.({
|
|
@@ -128,8 +128,8 @@ export class ZipArchive {
|
|
|
128
128
|
|
|
129
129
|
//#region get
|
|
130
130
|
/**
|
|
131
|
-
*
|
|
132
|
-
* @param fileName
|
|
131
|
+
* 특정 파일 추출
|
|
132
|
+
* @param fileName 파일 이름
|
|
133
133
|
*/
|
|
134
134
|
async get(fileName: string): Promise<Bytes | undefined> {
|
|
135
135
|
if (this._cache.has(fileName)) {
|
|
@@ -156,8 +156,8 @@ export class ZipArchive {
|
|
|
156
156
|
|
|
157
157
|
//#region exists
|
|
158
158
|
/**
|
|
159
|
-
*
|
|
160
|
-
* @param fileName
|
|
159
|
+
* 파일 존재 여부 확인
|
|
160
|
+
* @param fileName 파일 이름
|
|
161
161
|
*/
|
|
162
162
|
async exists(fileName: string): Promise<boolean> {
|
|
163
163
|
if (this._cache.has(fileName)) {
|
|
@@ -176,9 +176,9 @@ export class ZipArchive {
|
|
|
176
176
|
|
|
177
177
|
//#region write
|
|
178
178
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @param fileName
|
|
181
|
-
* @param bytes
|
|
179
|
+
* 파일 쓰기 (캐시에 저장)
|
|
180
|
+
* @param fileName 파일 이름
|
|
181
|
+
* @param bytes 파일 내용
|
|
182
182
|
*/
|
|
183
183
|
write(fileName: string, bytes: Bytes): void {
|
|
184
184
|
this._cache.set(fileName, bytes);
|
|
@@ -187,11 +187,11 @@ export class ZipArchive {
|
|
|
187
187
|
|
|
188
188
|
//#region compress
|
|
189
189
|
/**
|
|
190
|
-
*
|
|
190
|
+
* 캐시된 파일을 ZIP으로 압축
|
|
191
191
|
*
|
|
192
192
|
* @remarks
|
|
193
|
-
*
|
|
194
|
-
*
|
|
193
|
+
* 내부적으로 `extractAll()`을 호출하여 모든 파일을 메모리에 로드한 후 압축.
|
|
194
|
+
* 대용량 ZIP 파일 처리 시 메모리 사용량에 주의.
|
|
195
195
|
*/
|
|
196
196
|
async compress(): Promise<Bytes> {
|
|
197
197
|
const fileMap = await this.extractAll();
|
|
@@ -211,7 +211,7 @@ export class ZipArchive {
|
|
|
211
211
|
|
|
212
212
|
//#region close
|
|
213
213
|
/**
|
|
214
|
-
*
|
|
214
|
+
* 리더 닫기 및 캐시 비우기
|
|
215
215
|
*/
|
|
216
216
|
async close(): Promise<void> {
|
|
217
217
|
await this._reader?.close();
|
|
@@ -219,7 +219,7 @@ export class ZipArchive {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
222
|
+
* await using 지원
|
|
223
223
|
*/
|
|
224
224
|
async [Symbol.asyncDispose](): Promise<void> {
|
|
225
225
|
await this.close();
|
package/README.md
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# @simplysm/core-common
|
|
2
|
-
|
|
3
|
-
Core module (common) -- platform-neutral core utilities for the Simplysm framework.
|
|
4
|
-
|
|
5
|
-
Provides error classes, immutable date/time types, prototype extensions, event handling, and utility namespaces that work in both browser and Node.js environments.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @simplysm/core-common
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Side-Effect Imports
|
|
14
|
-
|
|
15
|
-
Importing the package entry point (`@simplysm/core-common`) automatically patches `Array`, `Map`, and `Set` prototypes with extension methods. These are declared as side effects in `package.json`:
|
|
16
|
-
|
|
17
|
-
- `extensions/arr-ext` -- Array prototype extensions
|
|
18
|
-
- `extensions/map-ext` -- Map prototype extensions
|
|
19
|
-
- `extensions/set-ext` -- Set prototype extensions
|
|
20
|
-
|
|
21
|
-
If you import only specific modules (e.g., `@simplysm/core-common/dist/types/date-time`), the prototype extensions are **not** applied unless you also import the entry point or the extension modules directly.
|
|
22
|
-
|
|
23
|
-
## API Overview
|
|
24
|
-
|
|
25
|
-
### Errors
|
|
26
|
-
|
|
27
|
-
| API | Type | Description |
|
|
28
|
-
|-----|------|-------------|
|
|
29
|
-
| `SdError` | class | Error with tree-structured cause chaining |
|
|
30
|
-
| `ArgumentError` | class | Invalid argument error with YAML-formatted details |
|
|
31
|
-
| `NotImplementedError` | class | Unimplemented feature error |
|
|
32
|
-
| `TimeoutError` | class | Waiting time exceeded error |
|
|
33
|
-
|
|
34
|
-
-> See [docs/errors.md](./docs/errors.md) for details.
|
|
35
|
-
|
|
36
|
-
### Types
|
|
37
|
-
|
|
38
|
-
| API | Type | Description |
|
|
39
|
-
|-----|------|-------------|
|
|
40
|
-
| `Uuid` | class | UUID v4 generation and parsing |
|
|
41
|
-
| `DateTime` | class | Immutable date+time (millisecond precision) |
|
|
42
|
-
| `DateOnly` | class | Immutable date without time |
|
|
43
|
-
| `Time` | class | Immutable time without date (24h wraparound) |
|
|
44
|
-
| `LazyGcMap` | class | Map with LRU-based automatic expiration |
|
|
45
|
-
| `Bytes` | type alias | `Uint8Array` (replaces `Buffer`) |
|
|
46
|
-
| `PrimitiveTypeMap` | type | Mapping of type name strings to types |
|
|
47
|
-
| `PrimitiveTypeStr` | type | `keyof PrimitiveTypeMap` |
|
|
48
|
-
| `PrimitiveType` | type | Union of all primitive types |
|
|
49
|
-
| `DeepPartial<T>` | type | Recursively makes all properties optional |
|
|
50
|
-
| `Type<T>` | interface | Constructor type for DI and factory patterns |
|
|
51
|
-
| `env` | const | Unified `DEV` / `VER` environment accessor |
|
|
52
|
-
|
|
53
|
-
-> See [docs/types.md](./docs/types.md) for details.
|
|
54
|
-
|
|
55
|
-
### Features
|
|
56
|
-
|
|
57
|
-
| API | Type | Description |
|
|
58
|
-
|-----|------|-------------|
|
|
59
|
-
| `EventEmitter` | class | Type-safe event emitter (EventTarget wrapper) |
|
|
60
|
-
| `DebounceQueue` | class | Async debounce -- only the last call executes |
|
|
61
|
-
| `SerialQueue` | class | Async serial execution queue |
|
|
62
|
-
|
|
63
|
-
-> See [docs/features.md](./docs/features.md) for details.
|
|
64
|
-
|
|
65
|
-
### Prototype Extensions (side-effect)
|
|
66
|
-
|
|
67
|
-
| API | Type | Description |
|
|
68
|
-
|-----|------|-------------|
|
|
69
|
-
| `Array` extensions | prototype | 34 methods -- query, transform, diff, sort, mutate |
|
|
70
|
-
| `Map` extensions | prototype | `getOrCreate`, `update` |
|
|
71
|
-
| `Set` extensions | prototype | `adds`, `toggle` |
|
|
72
|
-
|
|
73
|
-
-> See [docs/extensions.md](./docs/extensions.md) for details.
|
|
74
|
-
|
|
75
|
-
### Utilities
|
|
76
|
-
|
|
77
|
-
| API | Type | Description |
|
|
78
|
-
|-----|------|-------------|
|
|
79
|
-
| `obj` | namespace | clone, equal, merge, merge3, omit, pick, chain access |
|
|
80
|
-
| `str` | namespace | Korean particles, case conversion, full-width replacement |
|
|
81
|
-
| `num` | namespace | parseInt, parseFloat, format with separators |
|
|
82
|
-
| `bytes` | namespace | concat, hex, base64 conversion |
|
|
83
|
-
| `path` | namespace | POSIX-only join, basename, extname |
|
|
84
|
-
| `json` | namespace | Custom-type-aware JSON stringify/parse |
|
|
85
|
-
| `xml` | namespace | XML parse/stringify via fast-xml-parser |
|
|
86
|
-
| `wait` | namespace | `until` (polling) and `time` (delay) |
|
|
87
|
-
| `transfer` | namespace | Worker-safe encode/decode for custom types |
|
|
88
|
-
| `err` | namespace | Extract message from unknown error |
|
|
89
|
-
| `dt` | namespace | Date format, month normalization, 12h/24h conversion |
|
|
90
|
-
| `primitive` | namespace | Infer `PrimitiveTypeStr` from a value |
|
|
91
|
-
| `js`, `ts`, `html`, `tsql`, `mysql`, `pgsql` | function | Template tag functions for syntax highlighting |
|
|
92
|
-
| `ZipArchive` | class | ZIP read/write/compress with caching |
|
|
93
|
-
|
|
94
|
-
-> See [docs/utils.md](./docs/utils.md) for details.
|
|
95
|
-
|
|
96
|
-
## Quick Usage Examples
|
|
97
|
-
|
|
98
|
-
### DateTime (immutable date/time)
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
import { DateTime, DateOnly } from "@simplysm/core-common";
|
|
102
|
-
|
|
103
|
-
const now = new DateTime();
|
|
104
|
-
const tomorrow = now.addDays(1);
|
|
105
|
-
const formatted = now.toFormatString("yyyy-MM-dd HH:mm:ss");
|
|
106
|
-
const parsed = DateTime.parse("2025-01-15 10:30:00");
|
|
107
|
-
|
|
108
|
-
const today = new DateOnly();
|
|
109
|
-
const weekInfo = today.getWeekSeqOfYear(); // { year, weekSeq }
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Object utilities
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
import { obj, json } from "@simplysm/core-common";
|
|
116
|
-
|
|
117
|
-
const cloned = obj.clone(deepObject);
|
|
118
|
-
const isEqual = obj.equal(a, b, { ignoreArrayIndex: true });
|
|
119
|
-
const merged = obj.merge(base, override);
|
|
120
|
-
const value = obj.getChainValue(data, "a.b[0].c");
|
|
121
|
-
|
|
122
|
-
// Custom-type-aware JSON
|
|
123
|
-
const str = json.stringify({ date: new DateTime(), id: Uuid.generate() });
|
|
124
|
-
const restored = json.parse(str); // DateTime and Uuid instances restored
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Array extensions
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
import "@simplysm/core-common";
|
|
131
|
-
|
|
132
|
-
const items = [3, 1, 4, 1, 5];
|
|
133
|
-
items.distinct(); // [3, 1, 4, 5]
|
|
134
|
-
items.orderBy(); // [1, 1, 3, 4, 5]
|
|
135
|
-
items.sum(); // 14
|
|
136
|
-
items.groupBy((x) => x % 2 === 0 ? "even" : "odd");
|
|
137
|
-
|
|
138
|
-
const users = [{ id: 1, name: "A" }, { id: 2, name: "B" }];
|
|
139
|
-
users.toMap((u) => u.id); // Map { 1 => {...}, 2 => {...} }
|
|
140
|
-
users.single((u) => u.id === 1); // { id: 1, name: "A" }
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### EventEmitter
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
import { EventEmitter } from "@simplysm/core-common";
|
|
147
|
-
|
|
148
|
-
interface MyEvents { data: string; done: void }
|
|
149
|
-
|
|
150
|
-
class MyService extends EventEmitter<MyEvents> {}
|
|
151
|
-
|
|
152
|
-
const svc = new MyService();
|
|
153
|
-
svc.on("data", (msg) => console.log(msg));
|
|
154
|
-
svc.emit("data", "hello");
|
|
155
|
-
svc.emit("done");
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## License
|
|
159
|
-
|
|
160
|
-
Apache-2.0
|
package/docs/errors.md
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# Errors
|
|
2
|
-
|
|
3
|
-
Error classes for the Simplysm framework. All classes extend `SdError`, which itself extends `Error`.
|
|
4
|
-
|
|
5
|
-
Source: `src/errors/*.ts`
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## `SdError`
|
|
10
|
-
|
|
11
|
-
Error class supporting tree-structured cause chaining. Utilizes ES2024 `cause` property. Messages are joined in reverse order with ` => ` separator, and cause stack traces are appended.
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
export class SdError extends Error {
|
|
15
|
-
override cause?: Error;
|
|
16
|
-
|
|
17
|
-
/** Create by wrapping a cause error. Messages are joined in reverse order (upper message => lower message => cause message) */
|
|
18
|
-
constructor(cause: Error, ...messages: string[]);
|
|
19
|
-
/** Create with messages only. Messages are joined in reverse order (upper message => lower message) */
|
|
20
|
-
constructor(...messages: string[]);
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
**Example:**
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
try {
|
|
28
|
-
await fetch(url);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
throw new SdError(err, "API call failed", "User load failed");
|
|
31
|
-
}
|
|
32
|
-
// Result message: "User load failed => API call failed => original error message"
|
|
33
|
-
|
|
34
|
-
throw new SdError("invalid state", "processing not possible");
|
|
35
|
-
// Result message: "processing not possible => invalid state"
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
## `ArgumentError`
|
|
41
|
-
|
|
42
|
-
An error thrown when invalid arguments are received. Includes the argument object in YAML format in the message to facilitate debugging. Extends `SdError`.
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
export class ArgumentError extends SdError {
|
|
46
|
-
/** Output argument object in YAML format with default message ("Invalid arguments.") */
|
|
47
|
-
constructor(argObj: Record<string, unknown>);
|
|
48
|
-
/** Output argument object in YAML format with a custom message */
|
|
49
|
-
constructor(message: string, argObj: Record<string, unknown>);
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**Example:**
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
throw new ArgumentError({ userId: 123, name: null });
|
|
57
|
-
// Result message: "Invalid arguments.\n\nuserId: 123\nname: null"
|
|
58
|
-
|
|
59
|
-
throw new ArgumentError("Invalid user", { userId: 123 });
|
|
60
|
-
// Result message: "Invalid user\n\nuserId: 123"
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
|
|
65
|
-
## `NotImplementedError`
|
|
66
|
-
|
|
67
|
-
An error thrown when a feature that has not yet been implemented is called. Extends `SdError`.
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
export class NotImplementedError extends SdError {
|
|
71
|
-
/**
|
|
72
|
-
* @param message Additional description message
|
|
73
|
-
*/
|
|
74
|
-
constructor(message?: string);
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
**Example:**
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
class BaseService {
|
|
82
|
-
process(): void {
|
|
83
|
-
throw new NotImplementedError("Implementation required in subclass");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
switch (type) {
|
|
88
|
-
case "A": return handleA();
|
|
89
|
-
case "B": throw new NotImplementedError(`Handling for type ${type}`);
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
## `TimeoutError`
|
|
96
|
-
|
|
97
|
-
An error that occurs when the waiting time is exceeded. Automatically thrown when the maximum number of attempts is exceeded in `wait.until()`. Extends `SdError`.
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
export class TimeoutError extends SdError {
|
|
101
|
-
/**
|
|
102
|
-
* @param count Number of attempts
|
|
103
|
-
* @param message Additional message
|
|
104
|
-
*/
|
|
105
|
-
constructor(count?: number, message?: string);
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
**Example:**
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
try {
|
|
113
|
-
await wait.until(() => isReady, 100, 50);
|
|
114
|
-
} catch (err) {
|
|
115
|
-
if (err instanceof TimeoutError) {
|
|
116
|
-
// "Waiting time exceeded(50 attempts)"
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
```
|