@simplysm/core-common 13.0.0-beta.4 → 13.0.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +191 -815
  2. package/dist/common.types.js +4 -4
  3. package/dist/env.js +2 -2
  4. package/dist/env.js.map +2 -2
  5. package/dist/errors/argument-error.js +1 -1
  6. package/dist/errors/not-implemented-error.js +1 -1
  7. package/dist/errors/timeout-error.js +1 -1
  8. package/dist/extensions/arr-ext.helpers.js +4 -4
  9. package/dist/extensions/arr-ext.js +9 -9
  10. package/dist/features/debounce-queue.d.ts.map +1 -1
  11. package/dist/features/debounce-queue.js +4 -4
  12. package/dist/features/debounce-queue.js.map +2 -2
  13. package/dist/features/serial-queue.d.ts.map +1 -1
  14. package/dist/features/serial-queue.js +5 -5
  15. package/dist/features/serial-queue.js.map +2 -2
  16. package/dist/index.js +30 -30
  17. package/dist/types/date-only.js +2 -2
  18. package/dist/types/date-time.js +2 -2
  19. package/dist/types/lazy-gc-map.d.ts.map +1 -1
  20. package/dist/types/lazy-gc-map.js +2 -2
  21. package/dist/types/lazy-gc-map.js.map +2 -2
  22. package/dist/types/time.js +2 -2
  23. package/dist/types/uuid.js +1 -1
  24. package/dist/utils/bytes.js +1 -1
  25. package/dist/utils/json.js +8 -8
  26. package/dist/utils/obj.js +5 -5
  27. package/dist/utils/primitive.js +5 -5
  28. package/dist/utils/transferable.js +4 -4
  29. package/dist/utils/wait.js +1 -1
  30. package/docs/extensions.md +381 -0
  31. package/docs/features.md +94 -0
  32. package/docs/types.md +338 -0
  33. package/docs/utils.md +631 -0
  34. package/package.json +8 -4
  35. package/.cache/typecheck-browser.tsbuildinfo +0 -1
  36. package/.cache/typecheck-node.tsbuildinfo +0 -1
  37. package/.cache/typecheck-tests-browser.tsbuildinfo +0 -1
  38. package/.cache/typecheck-tests-node.tsbuildinfo +0 -1
  39. package/src/common.types.ts +0 -91
  40. package/src/env.ts +0 -11
  41. package/src/errors/argument-error.ts +0 -40
  42. package/src/errors/not-implemented-error.ts +0 -32
  43. package/src/errors/sd-error.ts +0 -53
  44. package/src/errors/timeout-error.ts +0 -36
  45. package/src/extensions/arr-ext.helpers.ts +0 -53
  46. package/src/extensions/arr-ext.ts +0 -777
  47. package/src/extensions/arr-ext.types.ts +0 -258
  48. package/src/extensions/map-ext.ts +0 -86
  49. package/src/extensions/set-ext.ts +0 -68
  50. package/src/features/debounce-queue.ts +0 -116
  51. package/src/features/event-emitter.ts +0 -112
  52. package/src/features/serial-queue.ts +0 -94
  53. package/src/globals.ts +0 -12
  54. package/src/index.ts +0 -55
  55. package/src/types/date-only.ts +0 -329
  56. package/src/types/date-time.ts +0 -294
  57. package/src/types/lazy-gc-map.ts +0 -244
  58. package/src/types/time.ts +0 -210
  59. package/src/types/uuid.ts +0 -113
  60. package/src/utils/bytes.ts +0 -160
  61. package/src/utils/date-format.ts +0 -239
  62. package/src/utils/json.ts +0 -230
  63. package/src/utils/num.ts +0 -97
  64. package/src/utils/obj.ts +0 -956
  65. package/src/utils/path.ts +0 -40
  66. package/src/utils/primitive.ts +0 -33
  67. package/src/utils/str.ts +0 -252
  68. package/src/utils/template-strings.ts +0 -132
  69. package/src/utils/transferable.ts +0 -269
  70. package/src/utils/wait.ts +0 -40
  71. package/src/utils/xml.ts +0 -105
  72. package/src/zip/sd-zip.ts +0 -218
  73. package/tests/errors/errors.spec.ts +0 -196
  74. package/tests/extensions/array-extension.spec.ts +0 -790
  75. package/tests/extensions/map-extension.spec.ts +0 -147
  76. package/tests/extensions/set-extension.spec.ts +0 -74
  77. package/tests/types/date-only.spec.ts +0 -636
  78. package/tests/types/date-time.spec.ts +0 -391
  79. package/tests/types/lazy-gc-map.spec.ts +0 -692
  80. package/tests/types/time.spec.ts +0 -559
  81. package/tests/types/types.spec.ts +0 -55
  82. package/tests/types/uuid.spec.ts +0 -91
  83. package/tests/utils/bytes-utils.spec.ts +0 -230
  84. package/tests/utils/date-format.spec.ts +0 -371
  85. package/tests/utils/debounce-queue.spec.ts +0 -272
  86. package/tests/utils/json.spec.ts +0 -475
  87. package/tests/utils/number.spec.ts +0 -184
  88. package/tests/utils/object.spec.ts +0 -827
  89. package/tests/utils/path.spec.ts +0 -78
  90. package/tests/utils/primitive.spec.ts +0 -55
  91. package/tests/utils/sd-event-emitter.spec.ts +0 -216
  92. package/tests/utils/serial-queue.spec.ts +0 -365
  93. package/tests/utils/string.spec.ts +0 -294
  94. package/tests/utils/template-strings.spec.ts +0 -96
  95. package/tests/utils/transferable.spec.ts +0 -698
  96. package/tests/utils/wait.spec.ts +0 -145
  97. package/tests/utils/xml.spec.ts +0 -146
  98. package/tests/zip/sd-zip.spec.ts +0 -234
@@ -0,0 +1,381 @@
1
+ # Extensions
2
+
3
+ Array, Map, Set prototype extensions. Activated by `import "@simplysm/core-common"`.
4
+
5
+ ## Array extension methods
6
+
7
+ ### Query
8
+
9
+ #### single
10
+
11
+ Return single element (error if 2+).
12
+
13
+ ```typescript
14
+ import "@simplysm/core-common";
15
+
16
+ const users = [{ id: 1, name: "Alice" }];
17
+ users.single((u) => u.id === 1); // { id: 1, name: "Alice" }
18
+ ```
19
+
20
+ #### first
21
+
22
+ Return first element.
23
+
24
+ ```typescript
25
+ users.first(); // { id: 1, name: "Alice" }
26
+ ```
27
+
28
+ #### last
29
+
30
+ Return last element.
31
+
32
+ ```typescript
33
+ users.last(); // Last user
34
+ ```
35
+
36
+ ---
37
+
38
+ ### Filtering
39
+
40
+ #### filterExists
41
+
42
+ Remove `null`/`undefined`.
43
+
44
+ ```typescript
45
+ [1, null, 2, undefined, 3].filterExists(); // [1, 2, 3]
46
+ ```
47
+
48
+ #### ofType
49
+
50
+ Filter by type (`PrimitiveTypeStr` or constructor).
51
+
52
+ ```typescript
53
+ import "@simplysm/core-common";
54
+ ```
55
+
56
+ #### filterAsync
57
+
58
+ Async filter.
59
+
60
+ ```typescript
61
+ import "@simplysm/core-common";
62
+ ```
63
+
64
+ ---
65
+
66
+ ### Mapping/Transformation
67
+
68
+ #### mapAsync
69
+
70
+ Async mapping (sequential execution).
71
+
72
+ ```typescript
73
+ await ids.mapAsync(async (id) => await fetchUser(id));
74
+ ```
75
+
76
+ #### mapMany
77
+
78
+ flat + filterExists.
79
+
80
+ ```typescript
81
+ import "@simplysm/core-common";
82
+ ```
83
+
84
+ #### mapManyAsync
85
+
86
+ Async mapMany.
87
+
88
+ ```typescript
89
+ import "@simplysm/core-common";
90
+ ```
91
+
92
+ #### parallelAsync
93
+
94
+ Parallel async mapping (`Promise.all`).
95
+
96
+ ```typescript
97
+ await ids.parallelAsync(async (id) => await fetchUser(id));
98
+ ```
99
+
100
+ ---
101
+
102
+ ### Grouping/Transformation
103
+
104
+ #### groupBy
105
+
106
+ Group by key.
107
+
108
+ ```typescript
109
+ const users = [
110
+ { id: 1, name: "Alice", dept: "dev" },
111
+ { id: 2, name: "Bob", dept: "dev" },
112
+ { id: 3, name: "Charlie", dept: "hr" },
113
+ ];
114
+
115
+ users.groupBy((u) => u.dept);
116
+ // [{ key: "dev", values: [...] }, { key: "hr", values: [...] }]
117
+ ```
118
+
119
+ #### toMap
120
+
121
+ Convert to Map (error on duplicate key).
122
+
123
+ ```typescript
124
+ users.toMap((u) => u.id); // Map<number, User>
125
+ ```
126
+
127
+ #### toMapAsync
128
+
129
+ Async Map conversion.
130
+
131
+ ```typescript
132
+ import "@simplysm/core-common";
133
+ ```
134
+
135
+ #### toArrayMap
136
+
137
+ Convert to `Map<K, V[]>`.
138
+
139
+ ```typescript
140
+ users.toArrayMap((u) => u.dept); // Map<string, User[]>
141
+ ```
142
+
143
+ #### toSetMap
144
+
145
+ Convert to `Map<K, Set<V>>`.
146
+
147
+ ```typescript
148
+ import "@simplysm/core-common";
149
+ ```
150
+
151
+ #### toMapValues
152
+
153
+ Aggregate Map by group.
154
+
155
+ ```typescript
156
+ import "@simplysm/core-common";
157
+ ```
158
+
159
+ #### toObject
160
+
161
+ Convert to `Record<string, V>`.
162
+
163
+ ```typescript
164
+ import "@simplysm/core-common";
165
+ ```
166
+
167
+ #### toTree
168
+
169
+ Convert to tree structure.
170
+
171
+ ```typescript
172
+ import "@simplysm/core-common";
173
+ ```
174
+
175
+ ---
176
+
177
+ ### Deduplication
178
+
179
+ #### distinct
180
+
181
+ Remove duplicates (return new array).
182
+
183
+ ```typescript
184
+ [1, 2, 2, 3, 3].distinct(); // [1, 2, 3]
185
+ ```
186
+
187
+ #### distinctThis
188
+
189
+ Remove duplicates (modify original).
190
+
191
+ ```typescript
192
+ import "@simplysm/core-common";
193
+ ```
194
+
195
+ ---
196
+
197
+ ### Sorting
198
+
199
+ #### orderBy
200
+
201
+ Ascending sort (return new array).
202
+
203
+ ```typescript
204
+ users.orderBy((u) => u.name);
205
+ ```
206
+
207
+ #### orderByDesc
208
+
209
+ Descending sort (return new array).
210
+
211
+ ```typescript
212
+ users.orderByDesc((u) => u.id);
213
+ ```
214
+
215
+ #### orderByThis
216
+
217
+ Ascending sort (modify original).
218
+
219
+ ```typescript
220
+ import "@simplysm/core-common";
221
+ ```
222
+
223
+ #### orderByDescThis
224
+
225
+ Descending sort (modify original).
226
+
227
+ ```typescript
228
+ import "@simplysm/core-common";
229
+ ```
230
+
231
+ ---
232
+
233
+ ### Comparison/Merging
234
+
235
+ #### diffs
236
+
237
+ Compare differences between two arrays.
238
+
239
+ ```typescript
240
+ import "@simplysm/core-common";
241
+ ```
242
+
243
+ #### oneWayDiffs
244
+
245
+ One-way diff comparison (create/update/same).
246
+
247
+ ```typescript
248
+ import "@simplysm/core-common";
249
+ ```
250
+
251
+ #### merge
252
+
253
+ Merge arrays.
254
+
255
+ ```typescript
256
+ import "@simplysm/core-common";
257
+ ```
258
+
259
+ ---
260
+
261
+ ### Aggregation
262
+
263
+ #### sum
264
+
265
+ Sum.
266
+
267
+ ```typescript
268
+ import "@simplysm/core-common";
269
+ ```
270
+
271
+ #### min
272
+
273
+ Minimum.
274
+
275
+ ```typescript
276
+ import "@simplysm/core-common";
277
+ ```
278
+
279
+ #### max
280
+
281
+ Maximum.
282
+
283
+ ```typescript
284
+ import "@simplysm/core-common";
285
+ ```
286
+
287
+ ---
288
+
289
+ ### Mutation
290
+
291
+ #### insert
292
+
293
+ Insert at specific position.
294
+
295
+ ```typescript
296
+ import "@simplysm/core-common";
297
+ ```
298
+
299
+ #### remove
300
+
301
+ Remove item.
302
+
303
+ ```typescript
304
+ import "@simplysm/core-common";
305
+ ```
306
+
307
+ #### toggle
308
+
309
+ Remove if exists, add if not.
310
+
311
+ ```typescript
312
+ import "@simplysm/core-common";
313
+ ```
314
+
315
+ #### clear
316
+
317
+ Remove all items.
318
+
319
+ ```typescript
320
+ import "@simplysm/core-common";
321
+ ```
322
+
323
+ #### shuffle
324
+
325
+ Shuffle (return new array).
326
+
327
+ ```typescript
328
+ import "@simplysm/core-common";
329
+ ```
330
+
331
+ ---
332
+
333
+ ## Map extension methods
334
+
335
+ ### getOrCreate
336
+
337
+ If key doesn't exist, set new value and return.
338
+
339
+ ```typescript
340
+ const map = new Map<string, number[]>();
341
+
342
+ // Create and return if value doesn't exist
343
+ const arr = map.getOrCreate("key", []);
344
+ arr.push(1);
345
+
346
+ // Create with factory function (when computation is expensive)
347
+ map.getOrCreate("key2", () => expensiveComputation());
348
+ ```
349
+
350
+ ### update
351
+
352
+ Update value for key using function.
353
+
354
+ ```typescript
355
+ const countMap = new Map<string, number>();
356
+ countMap.update("key", (v) => (v ?? 0) + 1); // Increment counter
357
+ ```
358
+
359
+ ---
360
+
361
+ ## Set extension methods
362
+
363
+ ### adds
364
+
365
+ Add multiple values at once.
366
+
367
+ ```typescript
368
+ const set = new Set<number>([1, 2, 3]);
369
+ set.adds(4, 5, 6); // {1, 2, 3, 4, 5, 6}
370
+ ```
371
+
372
+ ### toggle
373
+
374
+ Toggle value (remove if exists, add if not).
375
+
376
+ ```typescript
377
+ set.toggle(2); // 2 exists so remove -> {1, 3, 4, 5, 6}
378
+ set.toggle(7); // 7 doesn't exist so add -> {1, 3, 4, 5, 6, 7}
379
+ set.toggle(8, "add"); // Force add
380
+ set.toggle(1, "del"); // Force delete
381
+ ```
@@ -0,0 +1,94 @@
1
+ # Features
2
+
3
+ Async operation control and event handling classes. All support `using` statements or `dispose()`.
4
+
5
+ ## DebounceQueue
6
+
7
+ Async debounce queue (executes only last request).
8
+
9
+ ```typescript
10
+ import { DebounceQueue } from "@simplysm/core-common";
11
+
12
+ using queue = new DebounceQueue(300); // 300ms debounce
13
+
14
+ // Error handling
15
+ queue.on("error", (err) => console.error(err));
16
+
17
+ // Only last call is executed
18
+ queue.run(() => console.log("1")); // Ignored
19
+ queue.run(() => console.log("2")); // Ignored
20
+ queue.run(() => console.log("3")); // Executed after 300ms
21
+ ```
22
+
23
+ ---
24
+
25
+ ## SerialQueue
26
+
27
+ Async serial queue (sequential execution).
28
+
29
+ ```typescript
30
+ import { SerialQueue } from "@simplysm/core-common";
31
+
32
+ using queue = new SerialQueue(100); // 100ms interval between tasks
33
+
34
+ queue.on("error", (err) => console.error(err));
35
+
36
+ queue.run(async () => { await fetch("/api/1"); });
37
+ queue.run(async () => { await fetch("/api/2"); }); // Runs after #1 completes
38
+ queue.run(async () => { await fetch("/api/3"); }); // Runs after #2 completes
39
+ ```
40
+
41
+ ---
42
+
43
+ ## EventEmitter
44
+
45
+ EventTarget wrapper with type-safe events.
46
+
47
+ ```typescript
48
+ import { EventEmitter } from "@simplysm/core-common";
49
+
50
+ interface MyEvents {
51
+ data: string;
52
+ error: Error;
53
+ done: void;
54
+ }
55
+
56
+ class MyService extends EventEmitter<MyEvents> {
57
+ process(): void {
58
+ this.emit("data", "result data");
59
+ this.emit("done"); // void type called without arguments
60
+ }
61
+ }
62
+
63
+ const service = new MyService();
64
+ service.on("data", (data) => console.log(data)); // data: string (type inferred)
65
+ service.off("data", listener); // Remove listener
66
+ service.listenerCount("data"); // Number of registered listeners
67
+ service.dispose(); // Remove all listeners
68
+ ```
69
+
70
+ ---
71
+
72
+ ## ZipArchive
73
+
74
+ ZIP file compression/decompression utility. Resources can be auto-cleaned with `await using`.
75
+
76
+ ```typescript
77
+ import { ZipArchive } from "@simplysm/core-common";
78
+
79
+ // Read ZIP file
80
+ await using archive = new ZipArchive(zipBytes);
81
+ const content = await archive.get("file.txt");
82
+ const exists = await archive.exists("data.json");
83
+
84
+ // Extract all (with progress)
85
+ const files = await archive.extractAll((progress) => {
86
+ console.log(`${progress.fileName}: ${progress.extractedSize}/${progress.totalSize}`);
87
+ });
88
+
89
+ // Create ZIP file
90
+ await using newArchive = new ZipArchive();
91
+ newArchive.write("file.txt", textBytes);
92
+ newArchive.write("data.json", jsonBytes);
93
+ const zipBytes = await newArchive.compress();
94
+ ```