@digital-alchemy/core 26.2.17 → 26.5.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/CLAUDE.md +302 -0
- package/README.md +19 -3
- package/dist/helpers/async.d.mts +37 -0
- package/dist/helpers/async.mjs +50 -15
- package/dist/helpers/async.mjs.map +1 -1
- package/dist/helpers/config-environment-loader.d.mts +39 -0
- package/dist/helpers/config-environment-loader.mjs +51 -11
- package/dist/helpers/config-environment-loader.mjs.map +1 -1
- package/dist/helpers/config-file-loader.d.mts +65 -0
- package/dist/helpers/config-file-loader.mjs +80 -4
- package/dist/helpers/config-file-loader.mjs.map +1 -1
- package/dist/helpers/config.d.mts +202 -5
- package/dist/helpers/config.mjs +60 -0
- package/dist/helpers/config.mjs.map +1 -1
- package/dist/helpers/context.d.mts +12 -1
- package/dist/helpers/cron.d.mts +154 -7
- package/dist/helpers/cron.mjs +47 -4
- package/dist/helpers/cron.mjs.map +1 -1
- package/dist/helpers/errors.d.mts +45 -0
- package/dist/helpers/errors.mjs +45 -0
- package/dist/helpers/errors.mjs.map +1 -1
- package/dist/helpers/events.d.mts +23 -0
- package/dist/helpers/events.mjs +23 -0
- package/dist/helpers/events.mjs.map +1 -1
- package/dist/helpers/extend.d.mts +50 -0
- package/dist/helpers/extend.mjs +63 -0
- package/dist/helpers/extend.mjs.map +1 -1
- package/dist/helpers/index.d.mts +9 -0
- package/dist/helpers/index.mjs +9 -0
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/helpers/lifecycle.d.mts +102 -16
- package/dist/helpers/lifecycle.mjs +19 -1
- package/dist/helpers/lifecycle.mjs.map +1 -1
- package/dist/helpers/logger.d.mts +178 -17
- package/dist/helpers/logger.mjs +41 -1
- package/dist/helpers/logger.mjs.map +1 -1
- package/dist/helpers/module.d.mts +110 -0
- package/dist/helpers/module.mjs +55 -6
- package/dist/helpers/module.mjs.map +1 -1
- package/dist/helpers/service-runner.d.mts +27 -1
- package/dist/helpers/service-runner.mjs +27 -1
- package/dist/helpers/service-runner.mjs.map +1 -1
- package/dist/helpers/utilities.d.mts +123 -3
- package/dist/helpers/utilities.mjs +110 -3
- package/dist/helpers/utilities.mjs.map +1 -1
- package/dist/helpers/wiring.d.mts +385 -0
- package/dist/helpers/wiring.mjs +120 -0
- package/dist/helpers/wiring.mjs.map +1 -1
- package/dist/services/als.service.d.mts +10 -0
- package/dist/services/als.service.mjs +49 -0
- package/dist/services/als.service.mjs.map +1 -1
- package/dist/services/configuration.service.d.mts +22 -0
- package/dist/services/configuration.service.mjs +140 -12
- package/dist/services/configuration.service.mjs.map +1 -1
- package/dist/services/index.d.mts +8 -0
- package/dist/services/index.mjs +8 -0
- package/dist/services/index.mjs.map +1 -1
- package/dist/services/internal.service.d.mts +98 -19
- package/dist/services/internal.service.mjs +91 -9
- package/dist/services/internal.service.mjs.map +1 -1
- package/dist/services/is.service.d.mts +64 -4
- package/dist/services/is.service.mjs +67 -4
- package/dist/services/is.service.mjs.map +1 -1
- package/dist/services/lifecycle.service.d.mts +26 -0
- package/dist/services/lifecycle.service.mjs +67 -9
- package/dist/services/lifecycle.service.mjs.map +1 -1
- package/dist/services/logger.service.d.mts +27 -0
- package/dist/services/logger.service.mjs +133 -9
- package/dist/services/logger.service.mjs.map +1 -1
- package/dist/services/scheduler.service.d.mts +19 -0
- package/dist/services/scheduler.service.mjs +87 -4
- package/dist/services/scheduler.service.mjs.map +1 -1
- package/dist/services/wiring.service.d.mts +28 -0
- package/dist/services/wiring.service.mjs +152 -19
- package/dist/services/wiring.service.mjs.map +1 -1
- package/dist/testing/index.d.mts +4 -0
- package/dist/testing/index.mjs +4 -0
- package/dist/testing/index.mjs.map +1 -1
- package/dist/testing/mock-logger.d.mts +8 -0
- package/dist/testing/mock-logger.mjs +9 -0
- package/dist/testing/mock-logger.mjs.map +1 -1
- package/dist/testing/test-module.d.mts +107 -27
- package/dist/testing/test-module.mjs +58 -1
- package/dist/testing/test-module.mjs.map +1 -1
- package/package.json +33 -31
package/dist/helpers/config.mjs
CHANGED
|
@@ -3,6 +3,16 @@ import path from "node:path";
|
|
|
3
3
|
import { cwd } from "node:process";
|
|
4
4
|
import dotenv from "@dotenvx/dotenvx";
|
|
5
5
|
import { is } from "../index.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Coerce a raw string (or boolean/array from argv parsing) to the target type.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Called by env/argv loaders after key lookup to normalise the raw value before
|
|
11
|
+
* it is stored in the config map. `boolean` coercion is intentionally lenient:
|
|
12
|
+
* `"true"`, `"y"`, and `"1"` all produce `true`. `string[]` handles the
|
|
13
|
+
* minimist edge case where a single flag value arrives as a plain string rather
|
|
14
|
+
* than a one-element array.
|
|
15
|
+
*/
|
|
6
16
|
export function cast(data, type) {
|
|
7
17
|
switch (type) {
|
|
8
18
|
case "boolean": {
|
|
@@ -27,6 +37,19 @@ export function cast(data, type) {
|
|
|
27
37
|
}
|
|
28
38
|
return data;
|
|
29
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Find the first key in `source` that also appears in `find`, using a
|
|
42
|
+
* case-insensitive fuzzy match that treats `-` and `_` as interchangeable.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* The search runs in two passes:
|
|
46
|
+
* 1. Exact match — fast path for the common case where cases and separators align.
|
|
47
|
+
* 2. Regex match — builds a pattern from `source[i]` that allows `-` or `_`
|
|
48
|
+
* between each word boundary, then tests every element of `find`.
|
|
49
|
+
*
|
|
50
|
+
* This is the canonical key-resolution routine called by the env and argv
|
|
51
|
+
* loaders before falling back to unqualified key search.
|
|
52
|
+
*/
|
|
30
53
|
export function findKey(source, find) {
|
|
31
54
|
return (
|
|
32
55
|
// Find an exact match (if available) first
|
|
@@ -37,11 +60,34 @@ export function findKey(source, find) {
|
|
|
37
60
|
return find.some(item => item.match(match));
|
|
38
61
|
}));
|
|
39
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Search `source` for the first key that case-insensitively matches `target`,
|
|
65
|
+
* treating `-` and `_` as interchangeable separators.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* Builds a single regex from `target` and tests it against every element of
|
|
69
|
+
* `source`. Unlike {@link findKey}, this function operates in one direction
|
|
70
|
+
* only (target → source) and is used for direct key lookups rather than
|
|
71
|
+
* cross-set intersection.
|
|
72
|
+
*/
|
|
40
73
|
export function iSearchKey(target, source) {
|
|
41
74
|
const regex = new RegExp(`^${target.replaceAll(new RegExp("[-_]", "gi"), "[-_]?")}$`, "gi");
|
|
42
75
|
return source.find(key => regex.exec(key) !== null);
|
|
43
76
|
}
|
|
44
77
|
/**
|
|
78
|
+
* Load a `.env` file into `process.env`, respecting the configured priority
|
|
79
|
+
* order.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* Priority (highest to lowest):
|
|
83
|
+
* 1. `--env-file` CLI switch
|
|
84
|
+
* 2. `BootstrapOptions.envFile`
|
|
85
|
+
* 3. `.env` in the current working directory (silent fallback)
|
|
86
|
+
*
|
|
87
|
+
* If the resolved path does not exist, a warning is emitted and loading is
|
|
88
|
+
* skipped rather than throwing. This keeps the application bootable in
|
|
89
|
+
* environments that intentionally have no `.env` file.
|
|
90
|
+
*
|
|
45
91
|
* priorities:
|
|
46
92
|
* - --env-file
|
|
47
93
|
* - bootstrap envFile
|
|
@@ -66,6 +112,7 @@ export function loadDotenv(internal, CLI_SWITCHES, logger) {
|
|
|
66
112
|
file = checkFile;
|
|
67
113
|
}
|
|
68
114
|
else {
|
|
115
|
+
// path was explicitly provided but does not exist; warn so operators notice the misconfiguration
|
|
69
116
|
logger.warn({ checkFile, envFile, name: loadDotenv }, "invalid target for dotenv file");
|
|
70
117
|
}
|
|
71
118
|
}
|
|
@@ -85,6 +132,18 @@ export function loadDotenv(internal, CLI_SWITCHES, logger) {
|
|
|
85
132
|
dotenv.config({ override: true, path: file, quiet: true });
|
|
86
133
|
}
|
|
87
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Coerce `value` to the concrete type described by `config`.
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* Called after a raw value has been retrieved from a loader to normalise it
|
|
140
|
+
* before storage. Each branch matches a `ProjectConfigTypes` discriminant:
|
|
141
|
+
* - `"string"` — `String(value)`
|
|
142
|
+
* - `"number"` — `Number(value)`
|
|
143
|
+
* - `"string[]"` — splits on commas, or parses JSON arrays starting with `[`
|
|
144
|
+
* - `"record"` / `"internal"` — passes objects through; parses strings as JSON
|
|
145
|
+
* - `"boolean"` — accepts boolean literals and the strings `"y"` / `"true"`
|
|
146
|
+
*/
|
|
88
147
|
export function parseConfig(config, value) {
|
|
89
148
|
switch (config.type) {
|
|
90
149
|
case "string": {
|
|
@@ -98,6 +157,7 @@ export function parseConfig(config, value) {
|
|
|
98
157
|
return value;
|
|
99
158
|
}
|
|
100
159
|
if (is.string(value)) {
|
|
160
|
+
// leading "[" signals a JSON-serialised array; otherwise treat as CSV
|
|
101
161
|
return value.startsWith("[") ? JSON.parse(value) : value.split(",");
|
|
102
162
|
}
|
|
103
163
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../src/helpers/config.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAStC,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../src/helpers/config.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,MAAM,MAAM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
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Request context — a branded string type that enables per-request logging and state isolation.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* `TContext` is used throughout the framework to tag operations with a unique request
|
|
6
|
+
* identifier, enabling AsyncLocalStorage to associate logs and state changes with the
|
|
7
|
+
* calling context. It is passed to error constructors and used as a key in per-request
|
|
8
|
+
* data structures.
|
|
3
9
|
*/
|
|
4
10
|
export type TContext = string & IContextBrand;
|
|
11
|
+
/**
|
|
12
|
+
* Phantom brand to enforce type safety on context identifiers.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
5
16
|
export interface IContextBrand {
|
|
6
17
|
_context: symbol;
|
|
7
18
|
}
|
package/dist/helpers/cron.d.mts
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduler types and cron expression constants.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Provides a comprehensive set of cron expressions for common scheduling patterns
|
|
6
|
+
* (second, minute, hour, day, week, month, year), three scheduler options types
|
|
7
|
+
* (cron, interval, sliding), and type definitions for time offsets and the
|
|
8
|
+
* scheduler service interface.
|
|
9
|
+
*/
|
|
1
10
|
import type { Dayjs } from "dayjs";
|
|
2
11
|
import type { Duration, DurationUnitsObjectType, DurationUnitType } from "dayjs/plugin/duration.js";
|
|
3
12
|
import type { RemoveCallback } from "../index.mts";
|
|
4
13
|
import type { TContext } from "./context.mts";
|
|
5
14
|
import type { SleepReturn, TBlackHole } from "./utilities.mts";
|
|
6
15
|
import type { Schedule, SchedulerOptions } from "./wiring.mts";
|
|
16
|
+
/**
|
|
17
|
+
* Predefined cron expressions for common scheduling patterns.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Each constant is a cron expression string (6-field format: second minute hour
|
|
21
|
+
* dayOfMonth month dayOfWeek) that can be passed to `scheduler.cron(...)`.
|
|
22
|
+
* Expressions range from sub-second (EVERY_SECOND) to yearly (EVERY_YEAR),
|
|
23
|
+
* with specific business hours and weekday patterns included.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* scheduler.cron({ exec: dailyTask, schedule: CronExpression.EVERY_DAY_AT_NOON });
|
|
28
|
+
* scheduler.cron({ exec: weeklyTask, schedule: CronExpression.EVERY_WEEKDAY });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
7
31
|
export declare enum CronExpression {
|
|
8
32
|
EVERY_SECOND = "* * * * * *",
|
|
9
33
|
EVERY_5_SECONDS = "*/5 * * * * *",
|
|
@@ -14,7 +38,9 @@ export declare enum CronExpression {
|
|
|
14
38
|
EVERY_10_MINUTES = "0 */10 * * * *",
|
|
15
39
|
EVERY_30_MINUTES = "0 */30 * * * *",
|
|
16
40
|
EVERY_HOUR = "0 0-23/1 * * *",
|
|
17
|
-
EVERY_2_HOURS = "0
|
|
41
|
+
EVERY_2_HOURS = "0 */2 * * *",
|
|
42
|
+
EVERY_2ND_HOUR = "0 */2 * * *",
|
|
43
|
+
EVERY_2ND_HOUR_FROM_1AM_THROUGH_11PM = "0 1-23/2 * * *",
|
|
18
44
|
EVERY_3_HOURS = "0 0-23/3 * * *",
|
|
19
45
|
EVERY_4_HOURS = "0 0-23/4 * * *",
|
|
20
46
|
EVERY_5_HOURS = "0 0-23/5 * * *",
|
|
@@ -54,12 +80,9 @@ export declare enum CronExpression {
|
|
|
54
80
|
EVERY_WEEKEND = "0 0 * * 6,0",
|
|
55
81
|
EVERY_1ST_DAY_OF_MONTH_AT_MIDNIGHT = "0 0 1 * *",
|
|
56
82
|
EVERY_1ST_DAY_OF_MONTH_AT_NOON = "0 12 1 * *",
|
|
57
|
-
EVERY_2ND_HOUR = "0 */2 * * *",
|
|
58
|
-
EVERY_2ND_HOUR_FROM_1AM_THROUGH_11PM = "0 1-23/2 * * *",
|
|
59
83
|
EVERY_2ND_MONTH = "0 0 1 */2 *",
|
|
60
84
|
EVERY_QUARTER = "0 0 1 */3 *",
|
|
61
85
|
EVERY_6_MONTHS = "0 0 1 */6 *",
|
|
62
|
-
EVERY_YEAR = "0 0 1 1 *",
|
|
63
86
|
EVERY_30_MINUTES_BETWEEN_9AM_AND_5PM = "0 */30 9-17 * * *",
|
|
64
87
|
EVERY_30_MINUTES_BETWEEN_9AM_AND_6PM = "0 */30 9-18 * * *",
|
|
65
88
|
EVERY_30_MINUTES_BETWEEN_10AM_AND_7PM = "0 */30 10-19 * * *",
|
|
@@ -87,36 +110,160 @@ export declare enum CronExpression {
|
|
|
87
110
|
MONDAY_TO_FRIDAY_AT_8PM = "0 0 20 * * 1-5",
|
|
88
111
|
MONDAY_TO_FRIDAY_AT_9PM = "0 0 21 * * 1-5",
|
|
89
112
|
MONDAY_TO_FRIDAY_AT_10PM = "0 0 22 * * 1-5",
|
|
90
|
-
MONDAY_TO_FRIDAY_AT_11PM = "0 0 23 * * 1-5"
|
|
113
|
+
MONDAY_TO_FRIDAY_AT_11PM = "0 0 23 * * 1-5",
|
|
114
|
+
EVERY_YEAR = "0 0 1 1 *"
|
|
91
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Schedule type identifier for cron-based schedules.
|
|
118
|
+
*
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
92
121
|
export declare const CRON_SCHEDULE = "CRON_SCHEDULE";
|
|
122
|
+
/**
|
|
123
|
+
* Schedule type identifier for interval-based schedules.
|
|
124
|
+
*
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
93
127
|
export declare const INTERVAL_SCHEDULE = "INTERVAL_SCHEDULE";
|
|
128
|
+
/**
|
|
129
|
+
* Options for a cron-based scheduled task.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* Extends `SchedulerOptions` with a `schedule` field that accepts one or more
|
|
133
|
+
* cron expressions (or `CronExpression` enum values). Multiple schedules will
|
|
134
|
+
* trigger the callback at the union of all specified times.
|
|
135
|
+
*/
|
|
94
136
|
export type SchedulerCronOptions = SchedulerOptions & {
|
|
137
|
+
/** Cron expression(s) — single or array — determining execution times. */
|
|
95
138
|
schedule: Schedule | Schedule[];
|
|
96
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Options for an interval-based scheduled task.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* Extends `SchedulerOptions` with an `interval` field specifying the time
|
|
145
|
+
* between executions (in milliseconds or a `TOffset` specification).
|
|
146
|
+
*/
|
|
97
147
|
export type SchedulerIntervalOptions = SchedulerOptions & {
|
|
148
|
+
/** Time between executions, in milliseconds. */
|
|
98
149
|
interval: number;
|
|
99
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* Options for a sliding-window scheduled task.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Executes on a computed schedule: the `reset` cron determines how often to
|
|
156
|
+
* call the `next()` function to retrieve the next execution time. If `next()`
|
|
157
|
+
* returns a valid time (Dayjs, Date, number, or string), a timeout is set for
|
|
158
|
+
* that time; undefined means skip this iteration. Useful for event-driven or
|
|
159
|
+
* data-dependent scheduling.
|
|
160
|
+
*/
|
|
100
161
|
export type SchedulerSlidingOptions = SchedulerOptions & {
|
|
101
162
|
/**
|
|
102
|
-
*
|
|
163
|
+
* Cron expression determining how often to recompute the next execution time.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* The `next()` callback is invoked on this schedule; its return value is
|
|
167
|
+
* used to compute the actual execution time.
|
|
103
168
|
*/
|
|
104
169
|
reset: Schedule;
|
|
105
170
|
/**
|
|
106
|
-
*
|
|
171
|
+
* Compute the next execution time.
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
* Called on the `reset` schedule; return a time-like value to execute,
|
|
175
|
+
* or undefined to skip this iteration.
|
|
107
176
|
*/
|
|
108
177
|
next: () => Dayjs | string | number | Date | undefined;
|
|
109
178
|
};
|
|
179
|
+
/**
|
|
180
|
+
* Scheduler service interface — methods to schedule and execute tasks.
|
|
181
|
+
*
|
|
182
|
+
* @remarks
|
|
183
|
+
* Returned by the scheduler service factory after context binding. Provides
|
|
184
|
+
* four primary scheduling methods (cron, interval, sliding, setTimeout/setInterval)
|
|
185
|
+
* and a sleep utility. All methods return a `RemoveCallback` to cancel the
|
|
186
|
+
* scheduled task.
|
|
187
|
+
*/
|
|
110
188
|
export type DigitalAlchemyScheduler = {
|
|
189
|
+
/**
|
|
190
|
+
* Schedule a task on a cron expression.
|
|
191
|
+
*
|
|
192
|
+
* @remarks
|
|
193
|
+
* Accepts one or more cron schedules (or `CronExpression` constants) and
|
|
194
|
+
* executes the callback at matching times. Returns a function to remove
|
|
195
|
+
* the scheduled task.
|
|
196
|
+
*/
|
|
111
197
|
cron: (options: SchedulerCronOptions) => RemoveCallback;
|
|
198
|
+
/**
|
|
199
|
+
* Schedule a task with a dynamically computed execution time.
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* On the `reset` schedule, calls the `next()` function to determine the next
|
|
203
|
+
* execution time. If `next()` returns a valid time, schedules execution; if
|
|
204
|
+
* undefined, skips. Useful for event-triggered or data-dependent scheduling.
|
|
205
|
+
*/
|
|
112
206
|
sliding: (options: SchedulerSlidingOptions) => RemoveCallback;
|
|
207
|
+
/**
|
|
208
|
+
* Schedule a task to run repeatedly at a fixed interval.
|
|
209
|
+
*
|
|
210
|
+
* @remarks
|
|
211
|
+
* Executes the callback after the first interval, then repeats. Useful for
|
|
212
|
+
* background polling or periodic maintenance tasks.
|
|
213
|
+
*/
|
|
113
214
|
setInterval: (callback: () => TBlackHole, target: TOffset) => RemoveCallback;
|
|
215
|
+
/**
|
|
216
|
+
* Schedule a task to run once after a delay.
|
|
217
|
+
*
|
|
218
|
+
* @remarks
|
|
219
|
+
* Executes the callback once after the specified time offset has elapsed.
|
|
220
|
+
* Useful for deferred operations or delayed initialization.
|
|
221
|
+
*/
|
|
114
222
|
setTimeout: (callback: () => TBlackHole, target: TOffset) => RemoveCallback;
|
|
223
|
+
/**
|
|
224
|
+
* Create a promise that resolves after a delay.
|
|
225
|
+
*
|
|
226
|
+
* @remarks
|
|
227
|
+
* Useful for awaiting a time offset in async code, or for testing. The
|
|
228
|
+
* returned promise is cancellable via its `cancel()` method.
|
|
229
|
+
*/
|
|
115
230
|
sleep: (target: TOffset | Date | Dayjs) => SleepReturn;
|
|
116
231
|
};
|
|
232
|
+
/**
|
|
233
|
+
* Scheduler factory function — binds context and returns the scheduler API.
|
|
234
|
+
*
|
|
235
|
+
* @remarks
|
|
236
|
+
* Called by the wiring engine with the request context; returns an object
|
|
237
|
+
* with all scheduling methods. This pattern allows per-request context
|
|
238
|
+
* binding without polluting the DI injection signature.
|
|
239
|
+
*/
|
|
117
240
|
export type SchedulerBuilder = (context: TContext) => DigitalAlchemyScheduler;
|
|
241
|
+
/**
|
|
242
|
+
* ISO 8601 partial duration string type for flexible time offset specification.
|
|
243
|
+
*
|
|
244
|
+
* @remarks
|
|
245
|
+
* Examples: "1h", "30m", "45s", "1h30m45s". Used alongside `DurationUnitsObjectType`
|
|
246
|
+
* and numeric offsets to specify time values in scheduler methods.
|
|
247
|
+
*
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
118
250
|
type Part<CHAR extends string> = `${number}${CHAR}` | "";
|
|
119
251
|
type ISO_8601_PARTIAL = Exclude<`${Part<"H" | "h">}${Part<"M" | "m">}${Part<"S" | "s">}`, "">;
|
|
252
|
+
/**
|
|
253
|
+
* Union of supported time offset representations.
|
|
254
|
+
*
|
|
255
|
+
* @remarks
|
|
256
|
+
* Can be a dayjs Duration, milliseconds (number), an object with duration units,
|
|
257
|
+
* an ISO 8601 partial string, or a tuple of [quantity, unit]. Scheduler methods
|
|
258
|
+
* accept any of these formats and normalize them internally.
|
|
259
|
+
*/
|
|
120
260
|
export type OffsetTypes = Duration | number | DurationUnitsObjectType | ISO_8601_PARTIAL | [quantity: number, unit: DurationUnitType];
|
|
261
|
+
/**
|
|
262
|
+
* Time offset — either a static value or a function that returns one.
|
|
263
|
+
*
|
|
264
|
+
* @remarks
|
|
265
|
+
* Allows dynamic offset computation at execution time. Useful for tests or
|
|
266
|
+
* when the delay depends on runtime state.
|
|
267
|
+
*/
|
|
121
268
|
export type TOffset = OffsetTypes | (() => OffsetTypes);
|
|
122
269
|
export {};
|
package/dist/helpers/cron.mjs
CHANGED
|
@@ -1,18 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduler types and cron expression constants.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Provides a comprehensive set of cron expressions for common scheduling patterns
|
|
6
|
+
* (second, minute, hour, day, week, month, year), three scheduler options types
|
|
7
|
+
* (cron, interval, sliding), and type definitions for time offsets and the
|
|
8
|
+
* scheduler service interface.
|
|
9
|
+
*/
|
|
1
10
|
import dayjs from "dayjs";
|
|
2
11
|
import duration from "dayjs/plugin/duration.js";
|
|
3
12
|
dayjs.extend(duration);
|
|
13
|
+
/**
|
|
14
|
+
* Predefined cron expressions for common scheduling patterns.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Each constant is a cron expression string (6-field format: second minute hour
|
|
18
|
+
* dayOfMonth month dayOfWeek) that can be passed to `scheduler.cron(...)`.
|
|
19
|
+
* Expressions range from sub-second (EVERY_SECOND) to yearly (EVERY_YEAR),
|
|
20
|
+
* with specific business hours and weekday patterns included.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* scheduler.cron({ exec: dailyTask, schedule: CronExpression.EVERY_DAY_AT_NOON });
|
|
25
|
+
* scheduler.cron({ exec: weeklyTask, schedule: CronExpression.EVERY_WEEKDAY });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
4
28
|
export var CronExpression;
|
|
5
29
|
(function (CronExpression) {
|
|
30
|
+
// sub-minute
|
|
6
31
|
CronExpression["EVERY_SECOND"] = "* * * * * *";
|
|
7
32
|
CronExpression["EVERY_5_SECONDS"] = "*/5 * * * * *";
|
|
8
33
|
CronExpression["EVERY_10_SECONDS"] = "*/10 * * * * *";
|
|
9
34
|
CronExpression["EVERY_30_SECONDS"] = "*/30 * * * * *";
|
|
35
|
+
// minute
|
|
10
36
|
CronExpression["EVERY_MINUTE"] = "*/1 * * * *";
|
|
11
37
|
CronExpression["EVERY_5_MINUTES"] = "0 */5 * * * *";
|
|
12
38
|
CronExpression["EVERY_10_MINUTES"] = "0 */10 * * * *";
|
|
13
39
|
CronExpression["EVERY_30_MINUTES"] = "0 */30 * * * *";
|
|
40
|
+
// hour
|
|
14
41
|
CronExpression["EVERY_HOUR"] = "0 0-23/1 * * *";
|
|
15
|
-
CronExpression["EVERY_2_HOURS"] = "0
|
|
42
|
+
CronExpression["EVERY_2_HOURS"] = "0 */2 * * *";
|
|
43
|
+
CronExpression["EVERY_2ND_HOUR"] = "0 */2 * * *";
|
|
44
|
+
CronExpression["EVERY_2ND_HOUR_FROM_1AM_THROUGH_11PM"] = "0 1-23/2 * * *";
|
|
16
45
|
CronExpression["EVERY_3_HOURS"] = "0 0-23/3 * * *";
|
|
17
46
|
CronExpression["EVERY_4_HOURS"] = "0 0-23/4 * * *";
|
|
18
47
|
CronExpression["EVERY_5_HOURS"] = "0 0-23/5 * * *";
|
|
@@ -23,6 +52,7 @@ export var CronExpression;
|
|
|
23
52
|
CronExpression["EVERY_10_HOURS"] = "0 0-23/10 * * *";
|
|
24
53
|
CronExpression["EVERY_11_HOURS"] = "0 0-23/11 * * *";
|
|
25
54
|
CronExpression["EVERY_12_HOURS"] = "0 0-23/12 * * *";
|
|
55
|
+
// day (specific times)
|
|
26
56
|
CronExpression["EVERY_DAY_AT_1AM"] = "0 01 * * *";
|
|
27
57
|
CronExpression["EVERY_DAY_AT_2AM"] = "0 02 * * *";
|
|
28
58
|
CronExpression["EVERY_DAY_AT_3AM"] = "0 03 * * *";
|
|
@@ -47,20 +77,21 @@ export var CronExpression;
|
|
|
47
77
|
CronExpression["EVERY_DAY_AT_10PM"] = "0 22 * * *";
|
|
48
78
|
CronExpression["EVERY_DAY_AT_11PM"] = "0 23 * * *";
|
|
49
79
|
CronExpression["EVERY_DAY_AT_MIDNIGHT"] = "0 0 * * *";
|
|
80
|
+
// week
|
|
50
81
|
CronExpression["EVERY_WEEK"] = "0 0 * * 0";
|
|
51
82
|
CronExpression["EVERY_WEEKDAY"] = "0 0 * * 1-5";
|
|
52
83
|
CronExpression["EVERY_WEEKEND"] = "0 0 * * 6,0";
|
|
84
|
+
// month
|
|
53
85
|
CronExpression["EVERY_1ST_DAY_OF_MONTH_AT_MIDNIGHT"] = "0 0 1 * *";
|
|
54
86
|
CronExpression["EVERY_1ST_DAY_OF_MONTH_AT_NOON"] = "0 12 1 * *";
|
|
55
|
-
CronExpression["EVERY_2ND_HOUR"] = "0 */2 * * *";
|
|
56
|
-
CronExpression["EVERY_2ND_HOUR_FROM_1AM_THROUGH_11PM"] = "0 1-23/2 * * *";
|
|
57
87
|
CronExpression["EVERY_2ND_MONTH"] = "0 0 1 */2 *";
|
|
58
88
|
CronExpression["EVERY_QUARTER"] = "0 0 1 */3 *";
|
|
59
89
|
CronExpression["EVERY_6_MONTHS"] = "0 0 1 */6 *";
|
|
60
|
-
|
|
90
|
+
// business hours
|
|
61
91
|
CronExpression["EVERY_30_MINUTES_BETWEEN_9AM_AND_5PM"] = "0 */30 9-17 * * *";
|
|
62
92
|
CronExpression["EVERY_30_MINUTES_BETWEEN_9AM_AND_6PM"] = "0 */30 9-18 * * *";
|
|
63
93
|
CronExpression["EVERY_30_MINUTES_BETWEEN_10AM_AND_7PM"] = "0 */30 10-19 * * *";
|
|
94
|
+
// weekday-specific times
|
|
64
95
|
CronExpression["MONDAY_TO_FRIDAY_AT_1AM"] = "0 0 01 * * 1-5";
|
|
65
96
|
CronExpression["MONDAY_TO_FRIDAY_AT_2AM"] = "0 0 02 * * 1-5";
|
|
66
97
|
CronExpression["MONDAY_TO_FRIDAY_AT_3AM"] = "0 0 03 * * 1-5";
|
|
@@ -86,7 +117,19 @@ export var CronExpression;
|
|
|
86
117
|
CronExpression["MONDAY_TO_FRIDAY_AT_9PM"] = "0 0 21 * * 1-5";
|
|
87
118
|
CronExpression["MONDAY_TO_FRIDAY_AT_10PM"] = "0 0 22 * * 1-5";
|
|
88
119
|
CronExpression["MONDAY_TO_FRIDAY_AT_11PM"] = "0 0 23 * * 1-5";
|
|
120
|
+
// year
|
|
121
|
+
CronExpression["EVERY_YEAR"] = "0 0 1 1 *";
|
|
89
122
|
})(CronExpression || (CronExpression = {}));
|
|
123
|
+
/**
|
|
124
|
+
* Schedule type identifier for cron-based schedules.
|
|
125
|
+
*
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
90
128
|
export const CRON_SCHEDULE = "CRON_SCHEDULE";
|
|
129
|
+
/**
|
|
130
|
+
* Schedule type identifier for interval-based schedules.
|
|
131
|
+
*
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
91
134
|
export const INTERVAL_SCHEDULE = "INTERVAL_SCHEDULE";
|
|
92
135
|
//# sourceMappingURL=cron.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cron.mjs","sourceRoot":"","sources":["../../src/helpers/cron.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cron.mjs","sourceRoot":"","sources":["../../src/helpers/cron.mts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,QAAQ,MAAM,0BAA0B,CAAC;AAMhD,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEvB;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAN,IAAY,cA6FX;AA7FD,WAAY,cAAc;IACxB,aAAa;IACb,8CAA4B,CAAA;IAC5B,mDAAiC,CAAA;IACjC,qDAAmC,CAAA;IACnC,qDAAmC,CAAA;IACnC,SAAS;IACT,8CAA4B,CAAA;IAC5B,mDAAi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1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,iEAA+C,CAAA;IAC/C,6DAA2C,CAAA;IAC3C,6DAA2C,CAAA;IAC3C,iEAA+C,CAAA;IAC/C,6DAA2C,CAAA;IAC3C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,4DAA0C,CAAA;IAC1C,6DAA2C,CAAA;IAC3C,6DAA2C,CAAA;IAC3C,OAAO;IACP,0CAAwB,CAAA;AAC1B,CAAC,EA7FW,cAAc,KAAd,cAAc,QA6FzB;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC"}
|
|
@@ -1,13 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework exception types for structured error handling and lifecycle management.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The framework uses two canonical exception classes: `BootstrapException` for
|
|
6
|
+
* wiring-time errors (configuration, module loading, dependency resolution) and
|
|
7
|
+
* `InternalError` for runtime logic errors after bootstrap. Both carry `context`,
|
|
8
|
+
* `cause` (error code), and `timestamp` to support observability and debugging.
|
|
9
|
+
*/
|
|
1
10
|
import type { TContext } from "./context.mts";
|
|
11
|
+
/**
|
|
12
|
+
* Exception thrown during application bootstrap or module wiring.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Indicates failures during dependency graph construction, configuration parsing,
|
|
16
|
+
* or module initialization. These errors should prevent the application from
|
|
17
|
+
* starting. The `cause` field carries a `SCREAMING_SNAKE_CODE` for programmatic
|
|
18
|
+
* handling; the `message` field is the human-readable description.
|
|
19
|
+
*/
|
|
2
20
|
export declare class BootstrapException extends Error {
|
|
21
|
+
/** Request context under which the exception occurred. */
|
|
3
22
|
context: TContext;
|
|
23
|
+
/**
|
|
24
|
+
* Machine-readable error code (e.g., `MISSING_CONFIG`, `UNKNOWN_MODULE`).
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Overrides the inherited `Error.cause` to ensure consistency with the
|
|
28
|
+
* framework's error classification scheme.
|
|
29
|
+
*/
|
|
4
30
|
cause: string;
|
|
31
|
+
/** Timestamp when the exception was created. */
|
|
5
32
|
timestamp: Date;
|
|
6
33
|
constructor(context: TContext, cause: string, message: string);
|
|
7
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Exception thrown during runtime operation after bootstrap.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Indicates logic errors, invalid state transitions, or failed assertions that
|
|
40
|
+
* occur after the application is fully initialized and running. These are
|
|
41
|
+
* typically unexpected but non-fatal; the `cause` field carries an error code
|
|
42
|
+
* for observability and alerting.
|
|
43
|
+
*/
|
|
8
44
|
export declare class InternalError extends Error {
|
|
45
|
+
/** Request context under which the error occurred. */
|
|
9
46
|
context: TContext;
|
|
47
|
+
/**
|
|
48
|
+
* Machine-readable error code (e.g., `NOT_FOUND`, `INVALID_STATE`).
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* Overrides the inherited `Error.cause` to ensure consistency with the
|
|
52
|
+
* framework's error classification scheme.
|
|
53
|
+
*/
|
|
10
54
|
cause: string;
|
|
55
|
+
/** Timestamp when the error was created. */
|
|
11
56
|
timestamp: Date;
|
|
12
57
|
constructor(context: TContext, cause: string, message: string);
|
|
13
58
|
}
|
package/dist/helpers/errors.mjs
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework exception types for structured error handling and lifecycle management.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The framework uses two canonical exception classes: `BootstrapException` for
|
|
6
|
+
* wiring-time errors (configuration, module loading, dependency resolution) and
|
|
7
|
+
* `InternalError` for runtime logic errors after bootstrap. Both carry `context`,
|
|
8
|
+
* `cause` (error code), and `timestamp` to support observability and debugging.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Exception thrown during application bootstrap or module wiring.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Indicates failures during dependency graph construction, configuration parsing,
|
|
15
|
+
* or module initialization. These errors should prevent the application from
|
|
16
|
+
* starting. The `cause` field carries a `SCREAMING_SNAKE_CODE` for programmatic
|
|
17
|
+
* handling; the `message` field is the human-readable description.
|
|
18
|
+
*/
|
|
1
19
|
export class BootstrapException extends Error {
|
|
20
|
+
/** Request context under which the exception occurred. */
|
|
2
21
|
context;
|
|
22
|
+
/**
|
|
23
|
+
* Machine-readable error code (e.g., `MISSING_CONFIG`, `UNKNOWN_MODULE`).
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Overrides the inherited `Error.cause` to ensure consistency with the
|
|
27
|
+
* framework's error classification scheme.
|
|
28
|
+
*/
|
|
3
29
|
cause;
|
|
30
|
+
/** Timestamp when the exception was created. */
|
|
4
31
|
timestamp;
|
|
5
32
|
constructor(context, cause, message) {
|
|
6
33
|
super();
|
|
@@ -11,9 +38,27 @@ export class BootstrapException extends Error {
|
|
|
11
38
|
this.timestamp = new Date();
|
|
12
39
|
}
|
|
13
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Exception thrown during runtime operation after bootstrap.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Indicates logic errors, invalid state transitions, or failed assertions that
|
|
46
|
+
* occur after the application is fully initialized and running. These are
|
|
47
|
+
* typically unexpected but non-fatal; the `cause` field carries an error code
|
|
48
|
+
* for observability and alerting.
|
|
49
|
+
*/
|
|
14
50
|
export class InternalError extends Error {
|
|
51
|
+
/** Request context under which the error occurred. */
|
|
15
52
|
context;
|
|
53
|
+
/**
|
|
54
|
+
* Machine-readable error code (e.g., `NOT_FOUND`, `INVALID_STATE`).
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* Overrides the inherited `Error.cause` to ensure consistency with the
|
|
58
|
+
* framework's error classification scheme.
|
|
59
|
+
*/
|
|
16
60
|
cause;
|
|
61
|
+
/** Timestamp when the error was created. */
|
|
17
62
|
timestamp;
|
|
18
63
|
constructor(context, cause, message) {
|
|
19
64
|
super();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","sourceRoot":"","sources":["../../src/helpers/errors.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.mjs","sourceRoot":"","sources":["../../src/helpers/errors.mts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,0DAA0D;IAC1D,OAAO,CAAW;IAElB;;;;;;OAMG;IACM,KAAK,CAAS;IAEvB,gDAAgD;IAChD,SAAS,CAAO;IAEhB,YAAY,OAAiB,EAAE,KAAa,EAAE,OAAe;QAC3D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC9B,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,sDAAsD;IACtD,OAAO,CAAW;IAElB;;;;;;OAMG;IACM,KAAK,CAAS;IAEvB,4CAA4C;IAC5C,SAAS,CAAO;IAEhB,YAAY,OAAiB,EAAE,KAAa,EAAE,OAAe;QAC3D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global error event names and factory functions for event bus routing.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* These constants are emitted as Node.js uncaught exception events and allow
|
|
6
|
+
* applications to attach listeners that distinguish framework-level errors
|
|
7
|
+
* (global, application, or library-scoped) from other process events.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Event name for uncaught errors at the Node.js process level.
|
|
11
|
+
*/
|
|
1
12
|
export declare const DIGITAL_ALCHEMY_NODE_GLOBAL_ERROR = "DIGITAL_ALCHEMY_NODE_GLOBAL_ERROR";
|
|
13
|
+
/**
|
|
14
|
+
* Event name for errors thrown during application bootstrap or operation.
|
|
15
|
+
*/
|
|
2
16
|
export declare const DIGITAL_ALCHEMY_APPLICATION_ERROR = "DIGITAL_ALCHEMY_APPLICATION_ERROR";
|
|
17
|
+
/**
|
|
18
|
+
* Factory for library-scoped error event names.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* When `library` is provided, returns a namespaced event name
|
|
22
|
+
* (`DIGITAL_ALCHEMY_LIBRARY_ERROR:${library}`) to allow listening for errors
|
|
23
|
+
* from a specific library. When not provided or empty, returns the base
|
|
24
|
+
* `DIGITAL_ALCHEMY_LIBRARY_ERROR` constant.
|
|
25
|
+
*/
|
|
3
26
|
export declare const DIGITAL_ALCHEMY_LIBRARY_ERROR: (library?: string) => string;
|
package/dist/helpers/events.mjs
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global error event names and factory functions for event bus routing.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* These constants are emitted as Node.js uncaught exception events and allow
|
|
6
|
+
* applications to attach listeners that distinguish framework-level errors
|
|
7
|
+
* (global, application, or library-scoped) from other process events.
|
|
8
|
+
*/
|
|
1
9
|
import { is } from "../index.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* Event name for uncaught errors at the Node.js process level.
|
|
12
|
+
*/
|
|
2
13
|
export const DIGITAL_ALCHEMY_NODE_GLOBAL_ERROR = "DIGITAL_ALCHEMY_NODE_GLOBAL_ERROR";
|
|
14
|
+
/**
|
|
15
|
+
* Event name for errors thrown during application bootstrap or operation.
|
|
16
|
+
*/
|
|
3
17
|
export const DIGITAL_ALCHEMY_APPLICATION_ERROR = "DIGITAL_ALCHEMY_APPLICATION_ERROR";
|
|
18
|
+
/**
|
|
19
|
+
* Factory for library-scoped error event names.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* When `library` is provided, returns a namespaced event name
|
|
23
|
+
* (`DIGITAL_ALCHEMY_LIBRARY_ERROR:${library}`) to allow listening for errors
|
|
24
|
+
* from a specific library. When not provided or empty, returns the base
|
|
25
|
+
* `DIGITAL_ALCHEMY_LIBRARY_ERROR` constant.
|
|
26
|
+
*/
|
|
4
27
|
export const DIGITAL_ALCHEMY_LIBRARY_ERROR = (library) => is.empty(library) ? "DIGITAL_ALCHEMY_LIBRARY_ERROR" : `DIGITAL_ALCHEMY_LIBRARY_ERROR:${library}`;
|
|
5
28
|
//# sourceMappingURL=events.mjs.map
|