@simplysm/core-common 13.0.69 → 13.0.71
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/README.md +66 -267
- package/dist/common.types.d.ts +14 -14
- 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 +2 -2
- package/dist/errors/argument-error.js.map +1 -1
- package/dist/errors/not-implemented-error.d.ts +8 -8
- package/dist/errors/not-implemented-error.js +2 -2
- package/dist/errors/not-implemented-error.js.map +1 -1
- package/dist/errors/sd-error.d.ts +10 -10
- package/dist/errors/sd-error.d.ts.map +1 -1
- package/dist/errors/timeout-error.d.ts +10 -10
- package/dist/errors/timeout-error.js +3 -3
- package/dist/errors/timeout-error.js.map +1 -1
- package/dist/extensions/arr-ext.d.ts +2 -2
- package/dist/extensions/arr-ext.helpers.d.ts +8 -8
- package/dist/extensions/arr-ext.helpers.js +1 -1
- package/dist/extensions/arr-ext.helpers.js.map +1 -1
- package/dist/extensions/arr-ext.js +13 -13
- package/dist/extensions/arr-ext.js.map +1 -1
- package/dist/extensions/arr-ext.types.d.ts +57 -57
- package/dist/extensions/arr-ext.types.d.ts.map +1 -1
- package/dist/extensions/map-ext.d.ts +16 -16
- package/dist/extensions/set-ext.d.ts +11 -11
- package/dist/features/debounce-queue.d.ts +17 -15
- package/dist/features/debounce-queue.d.ts.map +1 -1
- package/dist/features/debounce-queue.js +6 -6
- package/dist/features/debounce-queue.js.map +1 -1
- package/dist/features/event-emitter.d.ts +20 -20
- package/dist/features/event-emitter.js +17 -17
- package/dist/features/serial-queue.d.ts +11 -11
- package/dist/features/serial-queue.js +5 -5
- package/dist/features/serial-queue.js.map +1 -1
- package/dist/globals.d.ts +4 -4
- 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 +63 -63
- package/dist/types/date-time.d.ts +37 -37
- package/dist/types/date-time.d.ts.map +1 -1
- package/dist/types/date-time.js +54 -37
- package/dist/types/date-time.js.map +1 -1
- 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 +26 -26
- package/dist/types/lazy-gc-map.js.map +1 -1
- package/dist/types/time.d.ts +25 -25
- package/dist/types/time.d.ts.map +1 -1
- package/dist/types/time.js +25 -25
- package/dist/types/time.js.map +1 -1
- package/dist/types/uuid.d.ts +11 -11
- package/dist/types/uuid.d.ts.map +1 -1
- package/dist/types/uuid.js +12 -12
- package/dist/types/uuid.js.map +1 -1
- package/dist/utils/bytes.d.ts +17 -17
- package/dist/utils/bytes.js +4 -4
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/date-format.d.ts +45 -45
- package/dist/utils/date-format.js +1 -1
- package/dist/utils/date-format.js.map +1 -1
- package/dist/utils/error.d.ts +4 -4
- package/dist/utils/json.d.ts +17 -17
- package/dist/utils/json.js +3 -3
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/num.d.ts +23 -23
- package/dist/utils/obj.d.ts +111 -111
- package/dist/utils/obj.d.ts.map +1 -1
- package/dist/utils/obj.js +3 -3
- package/dist/utils/obj.js.map +1 -1
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/primitive.d.ts +5 -5
- package/dist/utils/primitive.js +1 -1
- package/dist/utils/primitive.js.map +1 -1
- package/dist/utils/str.d.ts +46 -46
- package/dist/utils/str.d.ts.map +1 -1
- package/dist/utils/str.js +5 -5
- package/dist/utils/str.js.map +1 -1
- package/dist/utils/template-strings.d.ts +26 -26
- package/dist/utils/transferable.d.ts +18 -18
- package/dist/utils/transferable.js +1 -1
- package/dist/utils/transferable.js.map +1 -1
- package/dist/utils/wait.d.ts +9 -9
- package/dist/utils/xml.d.ts +13 -13
- package/dist/utils/xml.d.ts.map +1 -1
- package/dist/utils/xml.js +1 -0
- package/dist/utils/xml.js.map +1 -1
- package/dist/zip/sd-zip.d.ts +22 -22
- package/dist/zip/sd-zip.js +16 -16
- package/package.json +4 -4
- package/src/common.types.ts +17 -17
- 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 +10 -10
- package/src/extensions/arr-ext.ts +57 -57
- package/src/extensions/arr-ext.types.ts +59 -59
- package/src/extensions/map-ext.ts +16 -16
- package/src/extensions/set-ext.ts +11 -11
- package/src/features/debounce-queue.ts +21 -19
- 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 +1 -1
- package/src/types/date-only.ts +83 -83
- package/src/types/date-time.ts +64 -44
- package/src/types/lazy-gc-map.ts +45 -45
- package/src/types/time.ts +34 -34
- package/src/types/uuid.ts +17 -17
- package/src/utils/bytes.ts +35 -35
- package/src/utils/date-format.ts +65 -65
- package/src/utils/error.ts +4 -4
- package/src/utils/json.ts +39 -39
- package/src/utils/num.ts +23 -23
- 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 +260 -261
- package/src/utils/template-strings.ts +29 -29
- package/src/utils/transferable.ts +284 -284
- package/src/utils/wait.ts +10 -10
- package/src/utils/xml.ts +20 -19
- package/src/zip/sd-zip.ts +25 -25
- package/tests/errors/errors.spec.ts +80 -0
- package/tests/extensions/array-extension.spec.ts +796 -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 +638 -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/uuid.spec.ts +74 -0
- package/tests/utils/bytes-utils.spec.ts +230 -0
- package/tests/utils/date-format.spec.ts +373 -0
- package/tests/utils/debounce-queue.spec.ts +272 -0
- package/tests/utils/json.spec.ts +486 -0
- package/tests/utils/number.spec.ts +157 -0
- package/tests/utils/object.spec.ts +829 -0
- package/tests/utils/path.spec.ts +78 -0
- package/tests/utils/primitive.spec.ts +43 -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 +281 -0
- package/tests/utils/template-strings.spec.ts +57 -0
- package/tests/utils/transferable.spec.ts +703 -0
- package/tests/utils/wait.spec.ts +145 -0
- package/tests/utils/xml.spec.ts +146 -0
- package/tests/zip/sd-zip.spec.ts +238 -0
- package/docs/extensions.md +0 -503
- package/docs/features.md +0 -109
- package/docs/types.md +0 -486
- package/docs/utils.md +0 -780
package/dist/zip/sd-zip.d.ts
CHANGED
|
@@ -5,25 +5,25 @@ export interface ZipArchiveProgress {
|
|
|
5
5
|
extractedSize: number;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* ZIP
|
|
8
|
+
* ZIP archive processing class
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Handles reading, writing, compression, and decompression of ZIP files.
|
|
11
|
+
* Uses internal caching to prevent duplicate decompression of the same file.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* // ZIP
|
|
14
|
+
* // Read ZIP file
|
|
15
15
|
* await using archive = new ZipArchive(zipBytes);
|
|
16
16
|
* const content = await archive.get("file.txt");
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
-
* // ZIP
|
|
19
|
+
* // Create ZIP file
|
|
20
20
|
* await using archive = new ZipArchive();
|
|
21
21
|
* archive.write("file.txt", textBytes);
|
|
22
22
|
* archive.write("data.json", jsonBytes);
|
|
23
23
|
* const zipBytes = await archive.compress();
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
|
-
* //
|
|
26
|
+
* // Extract all files (with progress reporting)
|
|
27
27
|
* await using archive = new ZipArchive(zipBytes);
|
|
28
28
|
* const files = await archive.extractAll((progress) => {
|
|
29
29
|
* console.log(`${progress.fileName}: ${progress.extractedSize}/${progress.totalSize}`);
|
|
@@ -34,46 +34,46 @@ export declare class ZipArchive {
|
|
|
34
34
|
private readonly _cache;
|
|
35
35
|
private _entries?;
|
|
36
36
|
/**
|
|
37
|
-
* ZipArchive
|
|
38
|
-
* @param data ZIP
|
|
37
|
+
* Create ZipArchive
|
|
38
|
+
* @param data ZIP data (omit to create a new archive)
|
|
39
39
|
*/
|
|
40
40
|
constructor(data?: Blob | Bytes);
|
|
41
41
|
private _getEntries;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param progressCallback
|
|
43
|
+
* Extract all files
|
|
44
|
+
* @param progressCallback Progress callback
|
|
45
45
|
*/
|
|
46
46
|
extractAll(progressCallback?: (progress: ZipArchiveProgress) => void): Promise<Map<string, Bytes | undefined>>;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @param fileName
|
|
48
|
+
* Extract specific file
|
|
49
|
+
* @param fileName File name
|
|
50
50
|
*/
|
|
51
51
|
get(fileName: string): Promise<Bytes | undefined>;
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param fileName
|
|
53
|
+
* Check if file exists
|
|
54
|
+
* @param fileName File name
|
|
55
55
|
*/
|
|
56
56
|
exists(fileName: string): Promise<boolean>;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @param fileName
|
|
60
|
-
* @param bytes
|
|
58
|
+
* Write file (store in cache)
|
|
59
|
+
* @param fileName File name
|
|
60
|
+
* @param bytes File content
|
|
61
61
|
*/
|
|
62
62
|
write(fileName: string, bytes: Bytes): void;
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Compress cached files to ZIP
|
|
65
65
|
*
|
|
66
66
|
* @remarks
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* Internally calls `extractAll()` to load all files into memory before compressing.
|
|
68
|
+
* Be mindful of memory usage when dealing with large ZIP files.
|
|
69
69
|
*/
|
|
70
70
|
compress(): Promise<Bytes>;
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
72
|
+
* Close reader and clear cache
|
|
73
73
|
*/
|
|
74
74
|
close(): Promise<void>;
|
|
75
75
|
/**
|
|
76
|
-
* await using
|
|
76
|
+
* Support for await using
|
|
77
77
|
*/
|
|
78
78
|
[Symbol.asyncDispose](): Promise<void>;
|
|
79
79
|
}
|
package/dist/zip/sd-zip.js
CHANGED
|
@@ -10,8 +10,8 @@ class ZipArchive {
|
|
|
10
10
|
_cache = /* @__PURE__ */ new Map();
|
|
11
11
|
_entries;
|
|
12
12
|
/**
|
|
13
|
-
* ZipArchive
|
|
14
|
-
* @param data ZIP
|
|
13
|
+
* Create ZipArchive
|
|
14
|
+
* @param data ZIP data (omit to create a new archive)
|
|
15
15
|
*/
|
|
16
16
|
constructor(data) {
|
|
17
17
|
if (!data) return;
|
|
@@ -29,8 +29,8 @@ class ZipArchive {
|
|
|
29
29
|
}
|
|
30
30
|
//#region extractAll
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @param progressCallback
|
|
32
|
+
* Extract all files
|
|
33
|
+
* @param progressCallback Progress callback
|
|
34
34
|
*/
|
|
35
35
|
async extractAll(progressCallback) {
|
|
36
36
|
const entries = await this._getEntries();
|
|
@@ -68,8 +68,8 @@ class ZipArchive {
|
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region get
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* @param fileName
|
|
71
|
+
* Extract specific file
|
|
72
|
+
* @param fileName File name
|
|
73
73
|
*/
|
|
74
74
|
async get(fileName) {
|
|
75
75
|
if (this._cache.has(fileName)) {
|
|
@@ -92,8 +92,8 @@ class ZipArchive {
|
|
|
92
92
|
//#endregion
|
|
93
93
|
//#region exists
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param fileName
|
|
95
|
+
* Check if file exists
|
|
96
|
+
* @param fileName File name
|
|
97
97
|
*/
|
|
98
98
|
async exists(fileName) {
|
|
99
99
|
if (this._cache.has(fileName)) {
|
|
@@ -109,9 +109,9 @@ class ZipArchive {
|
|
|
109
109
|
//#endregion
|
|
110
110
|
//#region write
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @param fileName
|
|
114
|
-
* @param bytes
|
|
112
|
+
* Write file (store in cache)
|
|
113
|
+
* @param fileName File name
|
|
114
|
+
* @param bytes File content
|
|
115
115
|
*/
|
|
116
116
|
write(fileName, bytes) {
|
|
117
117
|
this._cache.set(fileName, bytes);
|
|
@@ -119,11 +119,11 @@ class ZipArchive {
|
|
|
119
119
|
//#endregion
|
|
120
120
|
//#region compress
|
|
121
121
|
/**
|
|
122
|
-
*
|
|
122
|
+
* Compress cached files to ZIP
|
|
123
123
|
*
|
|
124
124
|
* @remarks
|
|
125
|
-
*
|
|
126
|
-
*
|
|
125
|
+
* Internally calls `extractAll()` to load all files into memory before compressing.
|
|
126
|
+
* Be mindful of memory usage when dealing with large ZIP files.
|
|
127
127
|
*/
|
|
128
128
|
async compress() {
|
|
129
129
|
const fileMap = await this.extractAll();
|
|
@@ -138,7 +138,7 @@ class ZipArchive {
|
|
|
138
138
|
//#endregion
|
|
139
139
|
//#region close
|
|
140
140
|
/**
|
|
141
|
-
*
|
|
141
|
+
* Close reader and clear cache
|
|
142
142
|
*/
|
|
143
143
|
async close() {
|
|
144
144
|
var _a;
|
|
@@ -146,7 +146,7 @@ class ZipArchive {
|
|
|
146
146
|
this._cache.clear();
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
|
-
* await using
|
|
149
|
+
* Support for await using
|
|
150
150
|
*/
|
|
151
151
|
async [Symbol.asyncDispose]() {
|
|
152
152
|
await this.close();
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/core-common",
|
|
3
|
-
"version": "13.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "13.0.71",
|
|
4
|
+
"description": "Simplysm package - Core module (common)",
|
|
5
|
+
"author": "simplysm",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
17
|
"src",
|
|
18
|
-
"
|
|
18
|
+
"tests"
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": [
|
|
21
21
|
"./src/extensions/arr-ext.ts",
|
package/src/common.types.ts
CHANGED
|
@@ -3,20 +3,20 @@ import { DateOnly } from "./types/date-only";
|
|
|
3
3
|
import { Time } from "./types/time";
|
|
4
4
|
import { Uuid } from "./types/uuid";
|
|
5
5
|
|
|
6
|
-
//#region Bytes
|
|
6
|
+
//#region Bytes Type
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Binary type used instead of Buffer
|
|
10
10
|
*/
|
|
11
11
|
export type Bytes = Uint8Array;
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
|
|
15
|
-
//#region Primitive
|
|
15
|
+
//#region Primitive Type
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Primitive
|
|
19
|
-
* orm-common
|
|
18
|
+
* Primitive type mapping
|
|
19
|
+
* Shared with orm-common
|
|
20
20
|
*/
|
|
21
21
|
export type PrimitiveTypeMap = {
|
|
22
22
|
string: string;
|
|
@@ -30,25 +30,25 @@ export type PrimitiveTypeMap = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Primitive
|
|
33
|
+
* Primitive type string key
|
|
34
34
|
*/
|
|
35
35
|
export type PrimitiveTypeStr = keyof PrimitiveTypeMap;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* Primitive
|
|
38
|
+
* Primitive type union
|
|
39
39
|
*/
|
|
40
40
|
export type PrimitiveType = PrimitiveTypeMap[PrimitiveTypeStr] | undefined;
|
|
41
41
|
|
|
42
42
|
//#endregion
|
|
43
43
|
|
|
44
|
-
//#region
|
|
44
|
+
//#region Utility Types
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* Deep Partial type
|
|
48
48
|
*
|
|
49
|
-
*
|
|
50
|
-
* Primitive
|
|
51
|
-
*
|
|
49
|
+
* Recursively makes all properties of an object optional.
|
|
50
|
+
* Primitive types (string, number, boolean, etc.) are kept as-is,
|
|
51
|
+
* only object/array types have Partial applied recursively.
|
|
52
52
|
*
|
|
53
53
|
* @example
|
|
54
54
|
* ```typescript
|
|
@@ -60,7 +60,7 @@ export type PrimitiveType = PrimitiveTypeMap[PrimitiveTypeStr] | undefined;
|
|
|
60
60
|
* };
|
|
61
61
|
* }
|
|
62
62
|
*
|
|
63
|
-
* //
|
|
63
|
+
* // All properties at every depth become optional
|
|
64
64
|
* const partial: DeepPartial<User> = {
|
|
65
65
|
* profile: { address: {} }
|
|
66
66
|
* };
|
|
@@ -71,10 +71,10 @@ export type DeepPartial<TObject> = Partial<{
|
|
|
71
71
|
}>;
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* Constructor type
|
|
75
75
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
76
|
+
* Used to represent a class constructor as a type.
|
|
77
|
+
* Primarily used in dependency injection, factory patterns, and instanceof checks.
|
|
78
78
|
*
|
|
79
79
|
* @example
|
|
80
80
|
* function create<T>(ctor: Type<T>): T {
|
|
@@ -82,7 +82,7 @@ export type DeepPartial<TObject> = Partial<{
|
|
|
82
82
|
* }
|
|
83
83
|
*
|
|
84
84
|
* class MyClass { name = "test"; }
|
|
85
|
-
* const instance = create(MyClass); // MyClass
|
|
85
|
+
* const instance = create(MyClass); // MyClass instance
|
|
86
86
|
*/
|
|
87
87
|
export interface Type<TInstance> extends Function {
|
|
88
88
|
new (...args: unknown[]): TInstance;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Why we use the yaml library:
|
|
2
|
+
// To represent nested object structures in a readable format.
|
|
3
|
+
// Tree structure is more clearly visible than JSON.stringify.
|
|
4
4
|
import YAML from "yaml";
|
|
5
5
|
import { SdError } from "./sd-error";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Argument error
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* An error thrown when invalid arguments are received.
|
|
11
|
+
* Includes the argument object in YAML format in the message to facilitate debugging.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* //
|
|
14
|
+
* // Passing only the argument object
|
|
15
15
|
* throw new ArgumentError({ userId: 123, name: null });
|
|
16
|
-
* //
|
|
16
|
+
* // Result message: "Invalid arguments.\n\nuserId: 123\nname: null"
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
-
* //
|
|
20
|
-
* throw new ArgumentError("
|
|
21
|
-
* //
|
|
19
|
+
* // Passing a custom message and argument object
|
|
20
|
+
* throw new ArgumentError("Invalid user", { userId: 123 });
|
|
21
|
+
* // Result message: "Invalid user\n\nuserId: 123"
|
|
22
22
|
*/
|
|
23
23
|
export class ArgumentError extends SdError {
|
|
24
|
-
/**
|
|
24
|
+
/** Output argument object in YAML format with default message ("Invalid arguments.") */
|
|
25
25
|
constructor(argObj: Record<string, unknown>);
|
|
26
|
-
/**
|
|
26
|
+
/** Output argument object in YAML format with a custom message */
|
|
27
27
|
constructor(message: string, argObj: Record<string, unknown>);
|
|
28
28
|
constructor(arg1: Record<string, unknown> | string, arg2?: Record<string, unknown>);
|
|
29
29
|
constructor(arg1: Record<string, unknown> | string, arg2?: Record<string, unknown>) {
|
|
@@ -31,9 +31,9 @@ export class ArgumentError extends SdError {
|
|
|
31
31
|
const argObj = typeof arg1 === "string" ? arg2 : arg1;
|
|
32
32
|
|
|
33
33
|
if (argObj != null) {
|
|
34
|
-
super((message ?? "
|
|
34
|
+
super((message ?? "Invalid arguments.") + "\n\n" + YAML.stringify(argObj));
|
|
35
35
|
} else {
|
|
36
|
-
super(message ?? "
|
|
36
|
+
super(message ?? "Invalid arguments.");
|
|
37
37
|
}
|
|
38
38
|
this.name = "ArgumentError";
|
|
39
39
|
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { SdError } from "./sd-error";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Not implemented error
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* An error thrown when a feature that has not yet been implemented is called.
|
|
7
|
+
* Used for abstract method stubs, branches planned for future implementation, etc.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* //
|
|
10
|
+
* // Before abstract method implementation
|
|
11
11
|
* class BaseService {
|
|
12
12
|
* process(): void {
|
|
13
|
-
* throw new NotImplementedError("
|
|
13
|
+
* throw new NotImplementedError("Implementation required in subclass");
|
|
14
14
|
* }
|
|
15
15
|
* }
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
|
-
* //
|
|
18
|
+
* // Branch planned for future implementation
|
|
19
19
|
* switch (type) {
|
|
20
20
|
* case "A": return handleA();
|
|
21
|
-
* case "B": throw new NotImplementedError(
|
|
21
|
+
* case "B": throw new NotImplementedError(`Handling for type ${type}`);
|
|
22
22
|
* }
|
|
23
23
|
*/
|
|
24
24
|
export class NotImplementedError extends SdError {
|
|
25
25
|
/**
|
|
26
|
-
* @param message
|
|
26
|
+
* @param message Additional description message
|
|
27
27
|
*/
|
|
28
28
|
constructor(message?: string) {
|
|
29
|
-
super("
|
|
29
|
+
super("Not implemented" + (message != null ? ": " + message : ""));
|
|
30
30
|
this.name = "NotImplementedError";
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/errors/sd-error.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* ES2024 cause
|
|
2
|
+
* Error class supporting Tree structure composition
|
|
3
|
+
* Utilizes ES2024 cause property
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* //
|
|
6
|
+
* // Wrap a cause error
|
|
7
7
|
* try {
|
|
8
8
|
* await fetch(url);
|
|
9
9
|
* } catch (err) {
|
|
10
|
-
* throw new SdError(err, "API
|
|
10
|
+
* throw new SdError(err, "API call failed", "User load failed");
|
|
11
11
|
* }
|
|
12
|
-
* //
|
|
12
|
+
* // Result message: "User load failed => API call failed => original error message"
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* //
|
|
16
|
-
* throw new SdError("
|
|
17
|
-
* //
|
|
15
|
+
* // Create with message only
|
|
16
|
+
* throw new SdError("invalid state", "processing not possible");
|
|
17
|
+
* // Result message: "processing not possible => invalid state"
|
|
18
18
|
*/
|
|
19
19
|
export class SdError extends Error {
|
|
20
20
|
override cause?: Error;
|
|
21
21
|
|
|
22
|
-
/**
|
|
22
|
+
/** Create by wrapping a cause error. Messages are joined in reverse order (upper message => lower message => cause message) */
|
|
23
23
|
constructor(cause: Error, ...messages: string[]);
|
|
24
|
-
/**
|
|
24
|
+
/** Create with messages only. Messages are joined in reverse order (upper message => lower message) */
|
|
25
25
|
constructor(...messages: string[]);
|
|
26
26
|
constructor(arg1?: unknown, ...messages: string[]);
|
|
27
27
|
constructor(arg1?: unknown, ...messages: string[]) {
|
|
@@ -46,7 +46,7 @@ export class SdError extends Error {
|
|
|
46
46
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
47
47
|
this.name = "SdError";
|
|
48
48
|
|
|
49
|
-
// V8
|
|
49
|
+
// captureStackTrace available only on V8 engine (Node.js, Chrome)
|
|
50
50
|
if ("captureStackTrace" in Error) {
|
|
51
51
|
(Error.captureStackTrace as (targetObject: object, constructorOpt?: Function) => void)(
|
|
52
52
|
this,
|
|
@@ -54,7 +54,7 @@ export class SdError extends Error {
|
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
// cause
|
|
57
|
+
// Add cause chain stack to current stack
|
|
58
58
|
if (cause?.stack != null) {
|
|
59
59
|
this.stack += `\n---- cause stack ----\n${cause.stack}`;
|
|
60
60
|
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { SdError } from "./sd-error";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Timeout error
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* An error that occurs when the waiting time is exceeded.
|
|
7
|
+
* Automatically thrown when the maximum number of attempts is exceeded in async waiting functions like Wait.until().
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* // Wait.until
|
|
10
|
+
* // Automatically thrown from Wait.until
|
|
11
11
|
* try {
|
|
12
|
-
* await Wait.until(() => isReady, 100, 50); // 100ms
|
|
12
|
+
* await Wait.until(() => isReady, 100, 50); // 100ms interval, max 50 attempts
|
|
13
13
|
* } catch (err) {
|
|
14
14
|
* if (err instanceof TimeoutError) {
|
|
15
|
-
* console.log("
|
|
15
|
+
* console.log("Timeout exceeded");
|
|
16
16
|
* }
|
|
17
17
|
* }
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* //
|
|
20
|
+
* // Thrown directly
|
|
21
21
|
* if (elapsed > maxTime) {
|
|
22
|
-
* throw new TimeoutError(undefined, "API
|
|
22
|
+
* throw new TimeoutError(undefined, "Waiting for API response exceeded");
|
|
23
23
|
* }
|
|
24
24
|
*/
|
|
25
25
|
export class TimeoutError extends SdError {
|
|
26
26
|
/**
|
|
27
|
-
* @param count
|
|
28
|
-
* @param message
|
|
27
|
+
* @param count Number of attempts
|
|
28
|
+
* @param message Additional message
|
|
29
29
|
*/
|
|
30
30
|
constructor(count?: number, message?: string) {
|
|
31
31
|
super(
|
|
32
|
-
"
|
|
33
|
-
(count != null ? `(${count}
|
|
32
|
+
"Waiting time exceeded" +
|
|
33
|
+
(count != null ? `(${count} attempts)` : "") +
|
|
34
34
|
(message != null ? `: ${message}` : ""),
|
|
35
35
|
);
|
|
36
36
|
this.name = "TimeoutError";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Array
|
|
2
|
+
* Array extension helper functions
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { DateTime } from "../types/date-time";
|
|
@@ -9,7 +9,7 @@ import { ArgumentError } from "../errors/argument-error";
|
|
|
9
9
|
import type { ComparableType } from "./arr-ext.types";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* DateTime, DateOnly, Time
|
|
12
|
+
* Convert DateTime, DateOnly, Time to comparable primitive values
|
|
13
13
|
*/
|
|
14
14
|
export function toComparable(value: ComparableType): string | number | boolean | undefined {
|
|
15
15
|
if (value instanceof DateOnly || value instanceof DateTime || value instanceof Time) {
|
|
@@ -19,13 +19,13 @@ export function toComparable(value: ComparableType): string | number | boolean |
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Comparison function for sorting
|
|
23
23
|
*
|
|
24
|
-
* @param pp
|
|
25
|
-
* @param pn
|
|
26
|
-
* @param desc true:
|
|
27
|
-
* @returns
|
|
28
|
-
* @note null/undefined
|
|
24
|
+
* @param pp comparison target 1
|
|
25
|
+
* @param pn comparison target 2
|
|
26
|
+
* @param desc true: descending, false: ascending
|
|
27
|
+
* @returns negative: pp comes first, 0: equal, positive: pn comes first
|
|
28
|
+
* @note null/undefined values are sorted first in ascending, last in descending
|
|
29
29
|
*/
|
|
30
30
|
export function compareForOrder(pp: ComparableType, pn: ComparableType, desc: boolean): number {
|
|
31
31
|
const cpp = toComparable(pp);
|
|
@@ -45,11 +45,11 @@ export function compareForOrder(pp: ComparableType, pn: ComparableType, desc: bo
|
|
|
45
45
|
return cpp < cpn ? -1 : cpp > cpn ? 1 : 0;
|
|
46
46
|
}
|
|
47
47
|
if (typeof cpn === "boolean" && typeof cpp === "boolean") {
|
|
48
|
-
// true > false:
|
|
48
|
+
// true > false: true comes last in ascending, first in descending
|
|
49
49
|
return cpn ? (desc ? 1 : -1) : desc ? -1 : 1;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
throw new ArgumentError("orderBy
|
|
52
|
+
throw new ArgumentError("Cannot use orderBy with this type.", {
|
|
53
53
|
type1: typeof cpp,
|
|
54
54
|
type2: typeof cpn,
|
|
55
55
|
});
|