@simplysm/core-common 14.0.22 → 14.0.24

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/docs/errors.md DELETED
@@ -1,68 +0,0 @@
1
- # Errors
2
-
3
- All error classes extend `SdError`, which extends the native `Error`.
4
-
5
- ## `SdError`
6
-
7
- Tree-structured error class. Supports cause chaining via the ES2024 `cause` property. Messages are joined in reverse order with ` => ` separator.
8
-
9
- ```typescript
10
- class SdError extends Error {
11
- override cause?: Error;
12
-
13
- constructor(cause: Error, ...messages: string[]);
14
- constructor(...messages: string[]);
15
- }
16
- ```
17
-
18
- | Constructor Overload | Description |
19
- |----------------------|-------------|
20
- | `new SdError(cause, ...messages)` | Wrap a cause error. Final message: `"outermost => ... => cause.message"` |
21
- | `new SdError(...messages)` | Messages only. Final message: `"outermost => ... => innermost"` |
22
-
23
- The cause chain stack trace is appended to the current stack under a `---- cause stack ----` separator.
24
-
25
- ## `ArgumentError`
26
-
27
- Invalid argument error. Extends `SdError`. Formats the argument object as YAML in the error message for debugging.
28
-
29
- ```typescript
30
- class ArgumentError extends SdError {
31
- constructor(argObj: Record<string, unknown>);
32
- constructor(message: string, argObj: Record<string, unknown>);
33
- }
34
- ```
35
-
36
- | Constructor Overload | Description |
37
- |----------------------|-------------|
38
- | `new ArgumentError(argObj)` | Default message + YAML dump of arguments |
39
- | `new ArgumentError(message, argObj)` | Custom message + YAML dump of arguments |
40
-
41
- ## `NotImplementedError`
42
-
43
- Unimplemented feature error. Extends `SdError`. Use for abstract method stubs or future branches.
44
-
45
- ```typescript
46
- class NotImplementedError extends SdError {
47
- constructor(message?: string);
48
- }
49
- ```
50
-
51
- | Parameter | Type | Description |
52
- |-----------|------|-------------|
53
- | `message` | `string \| undefined` | Optional description of what is not implemented |
54
-
55
- ## `TimeoutError`
56
-
57
- Timeout exceeded error. Extends `SdError`. Thrown by `wait.until()` when max retry count is exceeded.
58
-
59
- ```typescript
60
- class TimeoutError extends SdError {
61
- constructor(count?: number, message?: string);
62
- }
63
- ```
64
-
65
- | Parameter | Type | Description |
66
- |-----------|------|-------------|
67
- | `count` | `number \| undefined` | Number of attempts made before timeout |
68
- | `message` | `string \| undefined` | Additional context message |
package/docs/features.md DELETED
@@ -1,112 +0,0 @@
1
- # Features
2
-
3
- ## `DebounceQueue`
4
-
5
- Async debounce queue. When multiple calls arrive in quick succession, only the last enqueued function executes after the delay. Extends `EventEmitter<{ error: SdError }>`.
6
-
7
- If a new request arrives while a previous one is executing, it runs immediately after the current execution completes (no debounce delay).
8
-
9
- ```typescript
10
- class DebounceQueue extends EventEmitter<{ error: SdError }> {
11
- constructor(delay?: number);
12
-
13
- run(fn: () => void | Promise<void>): void;
14
- dispose(): void;
15
- [Symbol.dispose](): void;
16
- }
17
- ```
18
-
19
- | Parameter | Type | Description |
20
- |-----------|------|-------------|
21
- | `delay` | `number \| undefined` | Debounce delay in ms. If omitted, executes on next event loop tick. |
22
-
23
- ### Methods
24
-
25
- | Method | Description |
26
- |--------|-------------|
27
- | `run(fn)` | Enqueue a function. Replaces any previously pending function. |
28
- | `dispose()` | Cancel pending work and clean up timers. |
29
- | `[Symbol.dispose]()` | Supports `using` statement. |
30
-
31
- ### Error Handling
32
-
33
- Errors from the executed function are emitted as `"error"` events. If no listener is registered, errors are logged via `consola`.
34
-
35
- ---
36
-
37
- ## `SerialQueue`
38
-
39
- Async serial queue. Functions are executed one at a time in FIFO order. Errors in one task do not prevent subsequent tasks from running. Extends `EventEmitter<{ error: SdError }>`.
40
-
41
- ```typescript
42
- class SerialQueue extends EventEmitter<{ error: SdError }> {
43
- constructor(gap?: number);
44
-
45
- run(fn: () => void | Promise<void>): void;
46
- dispose(): void;
47
- [Symbol.dispose](): void;
48
- }
49
- ```
50
-
51
- | Parameter | Type | Description |
52
- |-----------|------|-------------|
53
- | `gap` | `number` | Delay between tasks in ms. Default: `0`. |
54
-
55
- ### Methods
56
-
57
- | Method | Description |
58
- |--------|-------------|
59
- | `run(fn)` | Add a function to the queue. Starts processing if not already running. |
60
- | `dispose()` | Clear the pending queue (current task completes). |
61
- | `[Symbol.dispose]()` | Supports `using` statement. |
62
-
63
- ### Error Handling
64
-
65
- Same as `DebounceQueue`: errors are emitted as `"error"` events or logged if no listener.
66
-
67
- ---
68
-
69
- ## `EventEmitter<TEvents>`
70
-
71
- Type-safe event emitter built on the `EventTarget` API. Works in both browser and Node.js. Duplicate listener registration for the same event is silently ignored.
72
-
73
- ```typescript
74
- class EventEmitter<TEvents extends { [K in keyof TEvents]: unknown } = Record<string, unknown>> {
75
- on<TEventName extends keyof TEvents & string>(
76
- type: TEventName,
77
- listener: (data: TEvents[TEventName]) => void,
78
- ): void;
79
-
80
- off<TEventName extends keyof TEvents & string>(
81
- type: TEventName,
82
- listener: (data: TEvents[TEventName]) => void,
83
- ): void;
84
-
85
- emit<TEventName extends keyof TEvents & string>(
86
- type: TEventName,
87
- ...args: TEvents[TEventName] extends void ? [] : [data: TEvents[TEventName]]
88
- ): void;
89
-
90
- listenerCount<TEventName extends keyof TEvents & string>(type: TEventName): number;
91
-
92
- dispose(): void;
93
- [Symbol.dispose](): void;
94
- }
95
- ```
96
-
97
- ### Type Parameter
98
-
99
- | Parameter | Description |
100
- |-----------|-------------|
101
- | `TEvents` | Object type mapping event names to their data types. Use `void` for events with no data. |
102
-
103
- ### Methods
104
-
105
- | Method | Description |
106
- |--------|-------------|
107
- | `on(type, listener)` | Register a listener. Duplicate registration for same event is ignored. |
108
- | `off(type, listener)` | Remove a listener. |
109
- | `emit(type, ...args)` | Dispatch an event. For `void` event types, no data argument is needed. |
110
- | `listenerCount(type)` | Return the number of listeners for an event type. |
111
- | `dispose()` | Remove all listeners from all events. |
112
- | `[Symbol.dispose]()` | Supports `using` statement. |
@@ -1,41 +0,0 @@
1
- # Map Extensions
2
-
3
- Prototype extensions added to the global `Map` type. Available after importing `@simplysm/core-common`.
4
-
5
- ## `Map.prototype.getOrCreate`
6
-
7
- Get the value for a key. If the key does not exist, create a new value (using the provided value or factory function), store it, and return it.
8
-
9
- ```typescript
10
- interface Map<K, V> {
11
- getOrCreate(key: K, newValue: V): V;
12
- getOrCreate(key: K, newValueFn: () => V): V;
13
- }
14
- ```
15
-
16
- | Parameter | Type | Description |
17
- |-----------|------|-------------|
18
- | `key` | `K` | The key to look up |
19
- | `newValue` | `V` | Default value to store if key is absent |
20
- | `newValueFn` | `() => V` | Factory function called only if key is absent |
21
-
22
- **Returns:** `V` -- the existing or newly created value.
23
-
24
- **Note:** If `V` is a function type (e.g., `Map<string, () => void>`), passing a function directly as the second argument will be treated as a factory. Wrap it in another function: `map.getOrCreate("key", () => myFn)`.
25
-
26
- ---
27
-
28
- ## `Map.prototype.update`
29
-
30
- Update the value for a key using a transform function. The function receives the current value (or `undefined` if the key does not exist) and its return value is stored.
31
-
32
- ```typescript
33
- interface Map<K, V> {
34
- update(key: K, updateFn: (v: V | undefined) => V): void;
35
- }
36
- ```
37
-
38
- | Parameter | Type | Description |
39
- |-----------|------|-------------|
40
- | `key` | `K` | The key to update |
41
- | `updateFn` | `(v: V \| undefined) => V` | Transform function. Receives current value or `undefined`. |
@@ -1,38 +0,0 @@
1
- # Set Extensions
2
-
3
- Prototype extensions added to the global `Set` type. Available after importing `@simplysm/core-common`.
4
-
5
- ## `Set.prototype.adds`
6
-
7
- Add multiple values at once.
8
-
9
- ```typescript
10
- interface Set<T> {
11
- adds(...values: T[]): this;
12
- }
13
- ```
14
-
15
- | Parameter | Type | Description |
16
- |-----------|------|-------------|
17
- | `values` | `T[]` | Values to add |
18
-
19
- **Returns:** `this` (for method chaining)
20
-
21
- ---
22
-
23
- ## `Set.prototype.toggle`
24
-
25
- Toggle a value in the set. If the value exists, remove it; if absent, add it. Optionally force add or delete.
26
-
27
- ```typescript
28
- interface Set<T> {
29
- toggle(value: T, addOrDel?: "add" | "del"): this;
30
- }
31
- ```
32
-
33
- | Parameter | Type | Description |
34
- |-----------|------|-------------|
35
- | `value` | `T` | The value to toggle |
36
- | `addOrDel` | `"add" \| "del" \| undefined` | Force `"add"` to always add, `"del"` to always remove. Omit for automatic toggle. |
37
-
38
- **Returns:** `this` (for method chaining)
@@ -1,87 +0,0 @@
1
- # Template Strings and Zip
2
-
3
- ## Template String Tag Functions
4
-
5
- All template tag functions perform the same operation: combine the template literals and normalize indentation. They exist as separate functions to enable IDE syntax highlighting for different languages.
6
-
7
- Each function:
8
- 1. Joins the template strings with interpolated values
9
- 2. Removes leading and trailing blank lines
10
- 3. Calculates the minimum indentation across all non-empty lines
11
- 4. Removes that minimum indentation from every line
12
-
13
- ```typescript
14
- function js(strings: TemplateStringsArray, ...values: unknown[]): string;
15
- function ts(strings: TemplateStringsArray, ...values: unknown[]): string;
16
- function html(strings: TemplateStringsArray, ...values: unknown[]): string;
17
- function tsql(strings: TemplateStringsArray, ...values: unknown[]): string;
18
- function mysql(strings: TemplateStringsArray, ...values: unknown[]): string;
19
- function pgsql(strings: TemplateStringsArray, ...values: unknown[]): string;
20
- ```
21
-
22
- | Function | Purpose |
23
- |----------|---------|
24
- | `js` | JavaScript code highlighting |
25
- | `ts` | TypeScript code highlighting |
26
- | `html` | HTML markup highlighting |
27
- | `tsql` | MSSQL T-SQL highlighting |
28
- | `mysql` | MySQL SQL highlighting |
29
- | `pgsql` | PostgreSQL SQL highlighting |
30
-
31
- ---
32
-
33
- ## `ZipArchiveProgress`
34
-
35
- Progress callback data for ZIP extraction.
36
-
37
- ```typescript
38
- interface ZipArchiveProgress {
39
- fileName: string;
40
- totalSize: number;
41
- extractedSize: number;
42
- }
43
- ```
44
-
45
- | Field | Type | Description |
46
- |-------|------|-------------|
47
- | `fileName` | `string` | Name of the file currently being extracted |
48
- | `totalSize` | `number` | Total uncompressed size of all files in bytes |
49
- | `extractedSize` | `number` | Cumulative bytes extracted so far |
50
-
51
- ---
52
-
53
- ## `ZipArchive`
54
-
55
- ZIP archive processing class. Supports reading, writing, compressing, and extracting ZIP files. Uses internal caching to avoid duplicate decompression. Built on `@zip.js/zip.js`.
56
-
57
- ```typescript
58
- class ZipArchive {
59
- constructor(data?: Blob | Bytes);
60
-
61
- get(fileName: string): Promise<Bytes | undefined>;
62
- exists(fileName: string): Promise<boolean>;
63
- write(fileName: string, bytes: Bytes): void;
64
- extractAll(progressCallback?: (progress: ZipArchiveProgress) => void): Promise<Map<string, Bytes | undefined>>;
65
- compress(): Promise<Bytes>;
66
- close(): Promise<void>;
67
- [Symbol.asyncDispose](): Promise<void>;
68
- }
69
- ```
70
-
71
- ### Constructor
72
-
73
- | Parameter | Type | Description |
74
- |-----------|------|-------------|
75
- | `data` | `Blob \| Bytes \| undefined` | Existing ZIP data to read. Omit to create a new empty archive. |
76
-
77
- ### Methods
78
-
79
- | Method | Returns | Description |
80
- |--------|---------|-------------|
81
- | `get(fileName)` | `Promise<Bytes \| undefined>` | Extract a single file by name. Returns `undefined` if not found. Caches the result. |
82
- | `exists(fileName)` | `Promise<boolean>` | Check if a file exists in the archive. |
83
- | `write(fileName, bytes)` | `void` | Write a file to the cache (for later compression). |
84
- | `extractAll(progressCallback?)` | `Promise<Map<string, Bytes \| undefined>>` | Extract all files. Returns a Map of filename to bytes. Optionally reports progress. |
85
- | `compress()` | `Promise<Bytes>` | Compress all cached files into a new ZIP. Calls `extractAll()` internally first. |
86
- | `close()` | `Promise<void>` | Close the reader and clear the cache. |
87
- | `[Symbol.asyncDispose]()` | `Promise<void>` | Supports `await using` statement. Calls `close()`. |
@@ -1,75 +0,0 @@
1
- # Type Utilities
2
-
3
- Exported from `common.types.ts`.
4
-
5
- ## `Bytes`
6
-
7
- Alias for `Uint8Array`. Used in place of Node.js `Buffer` throughout the framework.
8
-
9
- ```typescript
10
- type Bytes = Uint8Array;
11
- ```
12
-
13
- ---
14
-
15
- ## `PrimitiveTypeMap`
16
-
17
- Maps primitive type string keys to their TypeScript types. Shared with `orm-common`.
18
-
19
- ```typescript
20
- type PrimitiveTypeMap = {
21
- string: string;
22
- number: number;
23
- boolean: boolean;
24
- DateTime: DateTime;
25
- DateOnly: DateOnly;
26
- Time: Time;
27
- Uuid: Uuid;
28
- Bytes: Bytes;
29
- };
30
- ```
31
-
32
- ---
33
-
34
- ## `PrimitiveTypeStr`
35
-
36
- Union of all primitive type name strings.
37
-
38
- ```typescript
39
- type PrimitiveTypeStr = keyof PrimitiveTypeMap;
40
- // "string" | "number" | "boolean" | "DateTime" | "DateOnly" | "Time" | "Uuid" | "Bytes"
41
- ```
42
-
43
- ---
44
-
45
- ## `PrimitiveType`
46
-
47
- Union of all primitive type values, plus `undefined`.
48
-
49
- ```typescript
50
- type PrimitiveType = PrimitiveTypeMap[PrimitiveTypeStr] | undefined;
51
- ```
52
-
53
- ---
54
-
55
- ## `DeepPartial<T>`
56
-
57
- Recursively make all properties optional. Primitive types (string, number, boolean, DateTime, DateOnly, Time, Uuid, Bytes) are left as-is; only object/array types are recursively made partial.
58
-
59
- ```typescript
60
- type DeepPartial<TObject> = Partial<{
61
- [K in keyof TObject]: TObject[K] extends PrimitiveType ? TObject[K] : DeepPartial<TObject[K]>;
62
- }>;
63
- ```
64
-
65
- ---
66
-
67
- ## `Type<T>`
68
-
69
- Constructor type interface. Represents a class constructor that produces instances of type `T`. Used for dependency injection, factory patterns, and `instanceof` checks.
70
-
71
- ```typescript
72
- interface Type<TInstance> extends Function {
73
- new (...args: unknown[]): TInstance;
74
- }
75
- ```