@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/docs/types.md
DELETED
|
@@ -1,486 +0,0 @@
|
|
|
1
|
-
# Types
|
|
2
|
-
|
|
3
|
-
## Errors
|
|
4
|
-
|
|
5
|
-
Custom error classes. All are based on `SdError` and support cause chaining.
|
|
6
|
-
|
|
7
|
-
### SdError
|
|
8
|
-
|
|
9
|
-
Base error class with cause chain tracking and automatic nested stack integration.
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
import { SdError } from "@simplysm/core-common";
|
|
13
|
-
|
|
14
|
-
// Track errors with cause chain
|
|
15
|
-
try {
|
|
16
|
-
await fetch(url);
|
|
17
|
-
} catch (err) {
|
|
18
|
-
throw new SdError(err, "API call failed", "Failed to load user");
|
|
19
|
-
// Result message: "Failed to load user => API call failed => original error message"
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### ArgumentError
|
|
24
|
-
|
|
25
|
-
Argument validation error with YAML formatting.
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { ArgumentError } from "@simplysm/core-common";
|
|
29
|
-
|
|
30
|
-
throw new ArgumentError("Invalid user", { userId: 123 });
|
|
31
|
-
// Result message: "Invalid user\n\nuserId: 123"
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### NotImplementedError
|
|
35
|
-
|
|
36
|
-
Indicates unimplemented functionality.
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
import { NotImplementedError } from "@simplysm/core-common";
|
|
40
|
-
|
|
41
|
-
switch (type) {
|
|
42
|
-
case "A": return handleA();
|
|
43
|
-
case "B": throw new NotImplementedError(`Handling type ${type}`);
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### TimeoutError
|
|
48
|
-
|
|
49
|
-
Timeout error. Thrown automatically by `waitUntil` when max attempts are exceeded.
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
import { TimeoutError } from "@simplysm/core-common";
|
|
53
|
-
|
|
54
|
-
// Thrown automatically by waitUntil on timeout
|
|
55
|
-
try {
|
|
56
|
-
await waitUntil(() => isReady, 100, 50);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
if (err instanceof TimeoutError) {
|
|
59
|
-
console.log("Timed out");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Throw manually
|
|
64
|
-
throw new TimeoutError(5, "API response wait exceeded");
|
|
65
|
-
// count: number of attempts, message: additional description (both optional)
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## Custom Types
|
|
71
|
-
|
|
72
|
-
Immutable custom type classes. All transformation methods return new instances.
|
|
73
|
-
|
|
74
|
-
### DateTime
|
|
75
|
-
|
|
76
|
-
Date + time (millisecond precision, local timezone).
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
import { DateTime } from "@simplysm/core-common";
|
|
80
|
-
|
|
81
|
-
// Creation
|
|
82
|
-
const now = new DateTime(); // Current time
|
|
83
|
-
const dt = new DateTime(2025, 1, 15, 10, 30, 0); // Year, month, day, hour, minute, second
|
|
84
|
-
const fromTick = new DateTime(1705312200000); // Tick (milliseconds)
|
|
85
|
-
const fromDate = new DateTime(new Date()); // Date object
|
|
86
|
-
|
|
87
|
-
// Parsing
|
|
88
|
-
DateTime.parse("2025-01-15 10:30:00"); // yyyy-MM-dd HH:mm:ss
|
|
89
|
-
DateTime.parse("2025-01-15 10:30:00.123"); // yyyy-MM-dd HH:mm:ss.fff
|
|
90
|
-
DateTime.parse("20250115103000"); // yyyyMMddHHmmss
|
|
91
|
-
DateTime.parse("2025-01-15 오전 10:30:00"); // Korean AM/PM
|
|
92
|
-
DateTime.parse("2025-01-15T10:30:00Z"); // ISO 8601
|
|
93
|
-
|
|
94
|
-
// Properties (read-only)
|
|
95
|
-
dt.year; // 2025
|
|
96
|
-
dt.month; // 1 (1-12)
|
|
97
|
-
dt.day; // 15
|
|
98
|
-
dt.hour; // 10
|
|
99
|
-
dt.minute; // 30
|
|
100
|
-
dt.second; // 0
|
|
101
|
-
dt.millisecond; // 0
|
|
102
|
-
dt.tick; // Millisecond timestamp
|
|
103
|
-
dt.dayOfWeek; // Day of week (Sun~Sat: 0~6)
|
|
104
|
-
dt.timezoneOffsetMinutes; // Timezone offset in minutes (e.g. 540 for UTC+9)
|
|
105
|
-
dt.isValid; // Validity check
|
|
106
|
-
|
|
107
|
-
// Immutable transformations (return new instances)
|
|
108
|
-
dt.setYear(2026); // Change year
|
|
109
|
-
dt.setMonth(3); // Change month (day auto-adjusted)
|
|
110
|
-
dt.setDay(1); // Change day
|
|
111
|
-
dt.setHour(9); // Change hour
|
|
112
|
-
dt.setMinute(0); // Change minute
|
|
113
|
-
dt.setSecond(0); // Change second
|
|
114
|
-
dt.setMillisecond(0); // Change millisecond
|
|
115
|
-
dt.addYears(1); // 1 year later
|
|
116
|
-
dt.addMonths(1); // 1 month later
|
|
117
|
-
dt.addDays(7); // 7 days later
|
|
118
|
-
dt.addHours(-2); // 2 hours ago
|
|
119
|
-
dt.addMinutes(30); // 30 minutes later
|
|
120
|
-
dt.addSeconds(10); // 10 seconds later
|
|
121
|
-
dt.addMilliseconds(500); // 500ms later
|
|
122
|
-
|
|
123
|
-
// Formatting
|
|
124
|
-
dt.toFormatString("yyyy-MM-dd"); // "2025-01-15"
|
|
125
|
-
dt.toFormatString("yyyy년 M월 d일 (ddd)"); // "2025년 1월 15일 (수)"
|
|
126
|
-
dt.toFormatString("tt h:mm:ss"); // "오전 10:30:00"
|
|
127
|
-
dt.toString(); // "2025-01-15T10:30:00.000+09:00"
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### DateOnly
|
|
131
|
-
|
|
132
|
-
Date only (no time).
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
import { DateOnly } from "@simplysm/core-common";
|
|
136
|
-
|
|
137
|
-
// Creation and parsing
|
|
138
|
-
const today = new DateOnly();
|
|
139
|
-
const d = new DateOnly(2025, 1, 15);
|
|
140
|
-
DateOnly.parse("2025-01-15"); // No timezone influence
|
|
141
|
-
DateOnly.parse("20250115"); // No timezone influence
|
|
142
|
-
|
|
143
|
-
// Properties (read-only)
|
|
144
|
-
d.year; // 2025
|
|
145
|
-
d.month; // 1
|
|
146
|
-
d.day; // 15
|
|
147
|
-
d.tick; // Millisecond timestamp
|
|
148
|
-
d.dayOfWeek; // Day of week (Sun~Sat: 0~6)
|
|
149
|
-
d.isValid; // Validity check
|
|
150
|
-
|
|
151
|
-
// Immutable transformations (return new instances)
|
|
152
|
-
d.setYear(2026);
|
|
153
|
-
d.setMonth(2); // Jan 31 -> Feb 28 (auto-adjusted)
|
|
154
|
-
d.setDay(1);
|
|
155
|
-
d.addYears(1);
|
|
156
|
-
d.addMonths(-1);
|
|
157
|
-
d.addDays(30);
|
|
158
|
-
|
|
159
|
-
// Week calculation (ISO 8601 standard: Monday start, min 4 days in first week)
|
|
160
|
-
d.getWeekSeqOfYear(); // { year: 2025, weekSeq: 3 }
|
|
161
|
-
d.getWeekSeqOfMonth(); // { year: 2025, monthSeq: 1, weekSeq: 3 }
|
|
162
|
-
|
|
163
|
-
// US-style week (Sunday start, first week with 1+ days)
|
|
164
|
-
d.getWeekSeqOfYear(0, 1);
|
|
165
|
-
d.getWeekSeqOfMonth(0, 1);
|
|
166
|
-
|
|
167
|
-
// Start date of the week containing this date
|
|
168
|
-
d.getWeekSeqStartDate(); // ISO 8601 (Monday start)
|
|
169
|
-
d.getWeekSeqStartDate(0, 1); // US-style (Sunday start)
|
|
170
|
-
|
|
171
|
-
// Base year/month for week sequence calculations
|
|
172
|
-
d.getBaseYearMonthSeqForWeekSeq(); // { year: 2025, monthSeq: 1 }
|
|
173
|
-
|
|
174
|
-
// Reverse calculate date from week number
|
|
175
|
-
DateOnly.getDateByYearWeekSeq({ year: 2025, weekSeq: 2 }); // 2025-01-06 (Monday)
|
|
176
|
-
DateOnly.getDateByYearWeekSeq({ year: 2025, month: 1, weekSeq: 3 }); // 2025-01-13 (Monday)
|
|
177
|
-
|
|
178
|
-
// Formatting
|
|
179
|
-
d.toFormatString("yyyy년 MM월 dd일"); // "2025년 01월 15일"
|
|
180
|
-
d.toString(); // "2025-01-15"
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### Time
|
|
184
|
-
|
|
185
|
-
Time only (no date, 24-hour cycle).
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
import { Time } from "@simplysm/core-common";
|
|
189
|
-
|
|
190
|
-
// Creation and parsing
|
|
191
|
-
const now = new Time();
|
|
192
|
-
const t = new Time(14, 30, 0);
|
|
193
|
-
Time.parse("14:30:00"); // HH:mm:ss
|
|
194
|
-
Time.parse("14:30:00.123"); // HH:mm:ss.fff
|
|
195
|
-
Time.parse("오후 2:30:00"); // Korean AM/PM
|
|
196
|
-
Time.parse("2025-01-15T14:30:00"); // ISO 8601 (time part only)
|
|
197
|
-
|
|
198
|
-
// Properties (read-only)
|
|
199
|
-
t.hour; // 14
|
|
200
|
-
t.minute; // 30
|
|
201
|
-
t.second; // 0
|
|
202
|
-
t.millisecond; // 0
|
|
203
|
-
t.tick; // Milliseconds since midnight
|
|
204
|
-
t.isValid; // Validity check
|
|
205
|
-
|
|
206
|
-
// Immutable transformations (return new instances, 24-hour cycle)
|
|
207
|
-
t.setHour(9);
|
|
208
|
-
t.setMinute(0);
|
|
209
|
-
t.setSecond(0);
|
|
210
|
-
t.setMillisecond(0);
|
|
211
|
-
t.addHours(12); // 14:30 + 12 hours = 02:30 (wraps around midnight)
|
|
212
|
-
t.addMinutes(-60); // 14:30 - 60 minutes = 13:30
|
|
213
|
-
t.addSeconds(30);
|
|
214
|
-
t.addMilliseconds(500);
|
|
215
|
-
|
|
216
|
-
// Formatting
|
|
217
|
-
t.toFormatString("tt h:mm"); // "오후 2:30"
|
|
218
|
-
t.toString(); // "14:30:00.000"
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### Uuid
|
|
222
|
-
|
|
223
|
-
UUID v4 (based on `crypto.getRandomValues`).
|
|
224
|
-
|
|
225
|
-
```typescript
|
|
226
|
-
import { Uuid } from "@simplysm/core-common";
|
|
227
|
-
|
|
228
|
-
// Generate new UUID (cryptographically secure)
|
|
229
|
-
const id = Uuid.new();
|
|
230
|
-
|
|
231
|
-
// Create from string
|
|
232
|
-
const fromStr = new Uuid("550e8400-e29b-41d4-a716-446655440000");
|
|
233
|
-
|
|
234
|
-
// Byte conversion
|
|
235
|
-
const bytes = id.toBytes(); // Uint8Array (16 bytes)
|
|
236
|
-
const fromBytes = Uuid.fromBytes(bytes);
|
|
237
|
-
|
|
238
|
-
id.toString(); // "550e8400-e29b-41d4-a716-446655440000"
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### LazyGcMap
|
|
242
|
-
|
|
243
|
-
Map with auto-expiration (LRU style).
|
|
244
|
-
|
|
245
|
-
```typescript
|
|
246
|
-
import { LazyGcMap } from "@simplysm/core-common";
|
|
247
|
-
|
|
248
|
-
// using statement (recommended)
|
|
249
|
-
using map = new LazyGcMap<string, object>({
|
|
250
|
-
gcInterval: 10000, // GC execution interval: 10 seconds (optional, defaults to expireTime/10)
|
|
251
|
-
expireTime: 60000, // Item expiration time: 60 seconds
|
|
252
|
-
onExpire: (key, value) => {
|
|
253
|
-
console.log(`Expired: ${key}`);
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
map.set("key1", { data: "hello" });
|
|
258
|
-
map.get("key1"); // Refreshes access time (LRU)
|
|
259
|
-
map.getOrCreate("key2", () => ({})); // Create and return if not exists
|
|
260
|
-
map.has("key1"); // Does not refresh access time
|
|
261
|
-
map.size; // Number of stored entries
|
|
262
|
-
map.delete("key1");
|
|
263
|
-
map.clear(); // Remove all items (instance remains usable)
|
|
264
|
-
|
|
265
|
-
// Iteration
|
|
266
|
-
for (const [key, value] of map.entries()) { /* ... */ }
|
|
267
|
-
for (const key of map.keys()) { /* ... */ }
|
|
268
|
-
for (const value of map.values()) { /* ... */ }
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
## Type Utilities
|
|
274
|
-
|
|
275
|
-
TypeScript utility types.
|
|
276
|
-
|
|
277
|
-
### Bytes
|
|
278
|
-
|
|
279
|
-
Alias for `Uint8Array` (`Buffer` replacement).
|
|
280
|
-
|
|
281
|
-
```typescript
|
|
282
|
-
import type { Bytes } from "@simplysm/core-common";
|
|
283
|
-
|
|
284
|
-
const data: Bytes = new Uint8Array([1, 2, 3]);
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
### PrimitiveTypeStr
|
|
288
|
-
|
|
289
|
-
Primitive type string keys.
|
|
290
|
-
|
|
291
|
-
```typescript
|
|
292
|
-
type PrimitiveTypeStr = "string" | "number" | "boolean" | "DateTime" | "DateOnly" | "Time" | "Uuid" | "Bytes";
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### PrimitiveTypeMap
|
|
296
|
-
|
|
297
|
-
Mapping from `PrimitiveTypeStr` to actual type.
|
|
298
|
-
|
|
299
|
-
```typescript
|
|
300
|
-
type PrimitiveTypeMap = {
|
|
301
|
-
string: string;
|
|
302
|
-
number: number;
|
|
303
|
-
boolean: boolean;
|
|
304
|
-
DateTime: DateTime;
|
|
305
|
-
DateOnly: DateOnly;
|
|
306
|
-
Time: Time;
|
|
307
|
-
Uuid: Uuid;
|
|
308
|
-
Bytes: Bytes;
|
|
309
|
-
};
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
### PrimitiveType
|
|
313
|
-
|
|
314
|
-
Union of all Primitive types (includes `undefined`).
|
|
315
|
-
|
|
316
|
-
```typescript
|
|
317
|
-
type PrimitiveType = string | number | boolean | DateTime | DateOnly | Time | Uuid | Bytes | undefined;
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
### DeepPartial
|
|
321
|
-
|
|
322
|
-
Recursively convert all properties to optional.
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
import type { DeepPartial } from "@simplysm/core-common";
|
|
326
|
-
|
|
327
|
-
interface Config {
|
|
328
|
-
db: { host: string; port: number };
|
|
329
|
-
}
|
|
330
|
-
const partial: DeepPartial<Config> = { db: { host: "localhost" } };
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### Type
|
|
334
|
-
|
|
335
|
-
Constructor type (for dependency injection, factory patterns).
|
|
336
|
-
|
|
337
|
-
```typescript
|
|
338
|
-
import type { Type } from "@simplysm/core-common";
|
|
339
|
-
|
|
340
|
-
function create<T>(ctor: Type<T>): T {
|
|
341
|
-
return new ctor();
|
|
342
|
-
}
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
### ObjUndefToOptional
|
|
346
|
-
|
|
347
|
-
Convert properties with `undefined` to optional.
|
|
348
|
-
|
|
349
|
-
```typescript
|
|
350
|
-
import type { ObjUndefToOptional } from "@simplysm/core-common";
|
|
351
|
-
|
|
352
|
-
type Input = { a: string; b: number | undefined };
|
|
353
|
-
type Output = ObjUndefToOptional<Input>; // { a: string; b?: number }
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### ObjOptionalToUndef
|
|
357
|
-
|
|
358
|
-
Convert optional properties to `required + undefined` union.
|
|
359
|
-
|
|
360
|
-
```typescript
|
|
361
|
-
import type { ObjOptionalToUndef } from "@simplysm/core-common";
|
|
362
|
-
|
|
363
|
-
type Input = { a: string; b?: number };
|
|
364
|
-
type Output = ObjOptionalToUndef<Input>; // { a: string; b: number | undefined }
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
### EqualOptions
|
|
368
|
-
|
|
369
|
-
Options for `objEqual`.
|
|
370
|
-
|
|
371
|
-
```typescript
|
|
372
|
-
import type { EqualOptions } from "@simplysm/core-common";
|
|
373
|
-
|
|
374
|
-
// topLevelIncludes: only compare these keys (top level only)
|
|
375
|
-
// topLevelExcludes: skip these keys (top level only)
|
|
376
|
-
// ignoreArrayIndex: treat arrays as sets (O(n²))
|
|
377
|
-
// onlyOneDepth: shallow comparison (reference equality for nested values)
|
|
378
|
-
const options: EqualOptions = {
|
|
379
|
-
topLevelExcludes: ["updatedAt"],
|
|
380
|
-
ignoreArrayIndex: true,
|
|
381
|
-
};
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### ObjMergeOptions
|
|
385
|
-
|
|
386
|
-
Options for `objMerge`.
|
|
387
|
-
|
|
388
|
-
```typescript
|
|
389
|
-
import type { ObjMergeOptions } from "@simplysm/core-common";
|
|
390
|
-
|
|
391
|
-
// arrayProcess: "replace" (default) replaces arrays, "concat" merges and deduplicates
|
|
392
|
-
// useDelTargetNull: when true, a null target value deletes the key from the result
|
|
393
|
-
const options: ObjMergeOptions = {
|
|
394
|
-
arrayProcess: "concat",
|
|
395
|
-
useDelTargetNull: true,
|
|
396
|
-
};
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
### ObjMerge3KeyOptions
|
|
400
|
-
|
|
401
|
-
Per-key comparison options for `objMerge3`.
|
|
402
|
-
|
|
403
|
-
```typescript
|
|
404
|
-
import type { ObjMerge3KeyOptions } from "@simplysm/core-common";
|
|
405
|
-
|
|
406
|
-
// keys: sub-keys to compare (equivalent to topLevelIncludes in objEqual)
|
|
407
|
-
// excludes: sub-keys to exclude from comparison
|
|
408
|
-
// ignoreArrayIndex: ignore array order when comparing
|
|
409
|
-
const options: ObjMerge3KeyOptions = {
|
|
410
|
-
keys: ["id", "name"],
|
|
411
|
-
ignoreArrayIndex: false,
|
|
412
|
-
};
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
### DtNormalizedMonth
|
|
416
|
-
|
|
417
|
-
Return type of `normalizeMonth`. Contains year/month/day after overflow normalization.
|
|
418
|
-
|
|
419
|
-
```typescript
|
|
420
|
-
import type { DtNormalizedMonth } from "@simplysm/core-common";
|
|
421
|
-
|
|
422
|
-
// { year: number; month: number; day: number }
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
### ZipArchiveProgress
|
|
426
|
-
|
|
427
|
-
Progress information passed to the callback of `ZipArchive.extractAll`.
|
|
428
|
-
|
|
429
|
-
```typescript
|
|
430
|
-
import type { ZipArchiveProgress } from "@simplysm/core-common";
|
|
431
|
-
|
|
432
|
-
// { fileName: string; totalSize: number; extractedSize: number }
|
|
433
|
-
await archive.extractAll((progress: ZipArchiveProgress) => {
|
|
434
|
-
const pct = Math.round((progress.extractedSize / progress.totalSize) * 100);
|
|
435
|
-
console.log(`${progress.fileName}: ${pct}%`);
|
|
436
|
-
});
|
|
437
|
-
```
|
|
438
|
-
|
|
439
|
-
### ArrayDiffsResult
|
|
440
|
-
|
|
441
|
-
Result of `Array.diffs()` — insert / delete / update entries.
|
|
442
|
-
|
|
443
|
-
```typescript
|
|
444
|
-
import type { ArrayDiffsResult } from "@simplysm/core-common";
|
|
445
|
-
|
|
446
|
-
const diffs: ArrayDiffsResult<User, User>[] = oldUsers.diffs(newUsers, { keys: ["id"] });
|
|
447
|
-
for (const diff of diffs) {
|
|
448
|
-
if (diff.source === undefined) { /* INSERT */ }
|
|
449
|
-
else if (diff.target === undefined) { /* DELETE */ }
|
|
450
|
-
else { /* UPDATE */ }
|
|
451
|
-
}
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
### ArrayDiffs2Result
|
|
455
|
-
|
|
456
|
-
Result of `Array.oneWayDiffs()` — create / update / same entries.
|
|
457
|
-
|
|
458
|
-
```typescript
|
|
459
|
-
import type { ArrayDiffs2Result } from "@simplysm/core-common";
|
|
460
|
-
|
|
461
|
-
// { type: "create"; item: T; orgItem: undefined }
|
|
462
|
-
// { type: "update"; item: T; orgItem: T }
|
|
463
|
-
// { type: "same"; item: T; orgItem: T }
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
### TreeArray
|
|
467
|
-
|
|
468
|
-
Result of `Array.toTree()` — `T & { children: TreeArray<T>[] }`.
|
|
469
|
-
|
|
470
|
-
```typescript
|
|
471
|
-
import type { TreeArray } from "@simplysm/core-common";
|
|
472
|
-
|
|
473
|
-
interface Category { id: number; parentId: number | undefined; name: string }
|
|
474
|
-
const tree: TreeArray<Category>[] = categories.toTree("id", "parentId");
|
|
475
|
-
// Each node has a `children` array of the same type
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
### ComparableType
|
|
479
|
-
|
|
480
|
-
Union of types that can be used as sort keys in `orderBy`, `orderByDesc`, etc.
|
|
481
|
-
|
|
482
|
-
```typescript
|
|
483
|
-
import type { ComparableType } from "@simplysm/core-common";
|
|
484
|
-
|
|
485
|
-
// string | number | boolean | DateTime | DateOnly | Time | undefined
|
|
486
|
-
```
|