@directive-run/core 0.4.0 → 0.4.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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +829 -185
- package/dist/index.d.ts +829 -185
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/migration.cjs.map +1 -1
- package/dist/migration.js.map +1 -1
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +85 -18
- package/dist/plugins/index.d.ts +85 -18
- package/dist/plugins/index.js.map +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +142 -26
- package/dist/testing.d.ts +142 -26
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +3 -2
package/dist/plugins/index.d.cts
CHANGED
|
@@ -4,18 +4,44 @@ import { M as ModuleSchema, P as Plugin, J as System } from '../plugins-cDWoL7A7
|
|
|
4
4
|
* Logging Plugin - Console logging for Directive events
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for the {@link loggingPlugin}.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* All fields are optional. The defaults produce `[Directive]`-prefixed
|
|
12
|
+
* `console.info`-level output for every lifecycle event.
|
|
13
|
+
*
|
|
14
|
+
* | Field | Default | Description |
|
|
15
|
+
* |----------|-----------------|-------------|
|
|
16
|
+
* | `level` | `"info"` | Minimum severity to emit. |
|
|
17
|
+
* | `filter` | `() => true` | Predicate that receives the event name (e.g., `"fact.set"`) and returns whether to log it. |
|
|
18
|
+
* | `logger` | `console` | Any object implementing `debug`, `info`, `warn`, `error`, `group`, and `groupEnd`. |
|
|
19
|
+
* | `prefix` | `"[Directive]"` | String prepended to every log line. |
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
7
23
|
interface LoggingPluginOptions {
|
|
8
|
-
/**
|
|
24
|
+
/** Minimum log level; events below this severity are silenced. */
|
|
9
25
|
level?: "debug" | "info" | "warn" | "error";
|
|
10
|
-
/**
|
|
26
|
+
/** Predicate that receives the event name and returns whether to log it. */
|
|
11
27
|
filter?: (event: string) => boolean;
|
|
12
|
-
/** Custom logger (defaults to console) */
|
|
28
|
+
/** Custom logger object (defaults to `console`). */
|
|
13
29
|
logger?: Pick<Console, "debug" | "info" | "warn" | "error" | "group" | "groupEnd">;
|
|
14
|
-
/**
|
|
30
|
+
/** String prepended to every log message. */
|
|
15
31
|
prefix?: string;
|
|
16
32
|
}
|
|
17
33
|
/**
|
|
18
|
-
* Create a
|
|
34
|
+
* Create a plugin that logs Directive lifecycle events to a configurable logger.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* Every plugin hook is mapped to a log call at an appropriate severity:
|
|
38
|
+
* - `debug` -- init, destroy, fact changes, derivation compute/invalidate, reconcile, constraint evaluate, resolver start/cancel, effect run, snapshot
|
|
39
|
+
* - `info` -- start, stop, requirement met, resolver complete, time-travel jump
|
|
40
|
+
* - `warn` -- resolver retry, error recovery
|
|
41
|
+
* - `error` -- constraint error, resolver error, effect error, system error
|
|
42
|
+
*
|
|
43
|
+
* @param options - Optional {@link LoggingPluginOptions} to control level, filtering, logger backend, and prefix.
|
|
44
|
+
* @returns A {@link Plugin} that can be passed to `createSystem`'s `plugins` array.
|
|
19
45
|
*
|
|
20
46
|
* @example
|
|
21
47
|
* ```ts
|
|
@@ -24,6 +50,8 @@ interface LoggingPluginOptions {
|
|
|
24
50
|
* plugins: [loggingPlugin({ level: "debug" })],
|
|
25
51
|
* });
|
|
26
52
|
* ```
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
27
55
|
*/
|
|
28
56
|
declare function loggingPlugin<M extends ModuleSchema = ModuleSchema>(options?: LoggingPluginOptions): Plugin<M>;
|
|
29
57
|
|
|
@@ -164,26 +192,60 @@ declare function emitDevToolsEvent(event: Record<string, unknown> & {
|
|
|
164
192
|
* Persistence Plugin - Save/restore facts to storage
|
|
165
193
|
*/
|
|
166
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Configuration for the {@link persistencePlugin}.
|
|
197
|
+
*
|
|
198
|
+
* @remarks
|
|
199
|
+
* At minimum, provide a `storage` backend and a `key`. Use `include` or
|
|
200
|
+
* `exclude` to control which fact keys are persisted. Saves are debounced
|
|
201
|
+
* by default (100 ms) to avoid excessive writes during rapid updates.
|
|
202
|
+
*
|
|
203
|
+
* | Field | Default | Description |
|
|
204
|
+
* |-------------|---------|-------------|
|
|
205
|
+
* | `storage` | *(required)* | A `Storage`-compatible backend (`localStorage`, `sessionStorage`, or custom). |
|
|
206
|
+
* | `key` | *(required)* | The key used to read/write from storage. |
|
|
207
|
+
* | `include` | all keys | Whitelist of fact keys to persist. |
|
|
208
|
+
* | `exclude` | `[]` | Blacklist of fact keys to skip. |
|
|
209
|
+
* | `debounce` | `100` | Milliseconds to debounce saves. |
|
|
210
|
+
* | `onRestore` | -- | Callback fired after state is restored from storage. |
|
|
211
|
+
* | `onSave` | -- | Callback fired after state is written to storage. |
|
|
212
|
+
* | `onError` | -- | Callback fired when a load or save error occurs. |
|
|
213
|
+
*
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
167
216
|
interface PersistencePluginOptions {
|
|
168
|
-
/** Storage backend (localStorage
|
|
217
|
+
/** A `Storage`-compatible backend (`localStorage`, `sessionStorage`, or custom). */
|
|
169
218
|
storage: Storage;
|
|
170
|
-
/**
|
|
219
|
+
/** The key used to read/write from the storage backend. */
|
|
171
220
|
key: string;
|
|
172
|
-
/**
|
|
221
|
+
/** Whitelist of fact keys to persist (default: all keys). */
|
|
173
222
|
include?: string[];
|
|
174
|
-
/**
|
|
223
|
+
/** Fact keys to exclude from persistence. */
|
|
175
224
|
exclude?: string[];
|
|
176
|
-
/**
|
|
225
|
+
/** Milliseconds to debounce saves (default: 100). */
|
|
177
226
|
debounce?: number;
|
|
178
|
-
/**
|
|
227
|
+
/** Callback fired after state is restored from storage on init. */
|
|
179
228
|
onRestore?: (data: Record<string, unknown>) => void;
|
|
180
|
-
/**
|
|
229
|
+
/** Callback fired after state is written to storage. */
|
|
181
230
|
onSave?: (data: Record<string, unknown>) => void;
|
|
182
|
-
/**
|
|
231
|
+
/** Callback fired when a load or save error occurs. */
|
|
183
232
|
onError?: (error: Error) => void;
|
|
184
233
|
}
|
|
185
234
|
/**
|
|
186
|
-
* Create a
|
|
235
|
+
* Create a plugin that persists selected facts to a `Storage` backend and
|
|
236
|
+
* restores them on system init.
|
|
237
|
+
*
|
|
238
|
+
* @remarks
|
|
239
|
+
* On `onInit`, the plugin reads the storage key and batch-sets any persisted
|
|
240
|
+
* facts into the store. On every `onFactSet` / `onFactDelete` / `onFactsBatch`,
|
|
241
|
+
* a debounced save is scheduled. A final synchronous save runs on `onDestroy`
|
|
242
|
+
* to capture any pending changes.
|
|
243
|
+
*
|
|
244
|
+
* Stored data is validated against prototype pollution before restoration
|
|
245
|
+
* via {@link isPrototypeSafe}.
|
|
246
|
+
*
|
|
247
|
+
* @param options - Required {@link PersistencePluginOptions} specifying storage backend, key, and optional filters/callbacks.
|
|
248
|
+
* @returns A {@link Plugin} that can be passed to `createSystem`'s `plugins` array.
|
|
187
249
|
*
|
|
188
250
|
* @example
|
|
189
251
|
* ```ts
|
|
@@ -198,6 +260,8 @@ interface PersistencePluginOptions {
|
|
|
198
260
|
* ],
|
|
199
261
|
* });
|
|
200
262
|
* ```
|
|
263
|
+
*
|
|
264
|
+
* @public
|
|
201
265
|
*/
|
|
202
266
|
declare function persistencePlugin<M extends ModuleSchema = ModuleSchema>(options: PersistencePluginOptions): Plugin<M>;
|
|
203
267
|
|
|
@@ -747,6 +811,9 @@ declare class CircuitBreakerOpenError extends Error {
|
|
|
747
811
|
/**
|
|
748
812
|
* Create a circuit breaker for protecting against cascading failures.
|
|
749
813
|
*
|
|
814
|
+
* @param config - Circuit breaker configuration (thresholds, recovery time, observability)
|
|
815
|
+
* @returns A circuit breaker instance with `execute`, `getState`, and `reset` methods
|
|
816
|
+
*
|
|
750
817
|
* @example
|
|
751
818
|
* ```typescript
|
|
752
819
|
* const breaker = createCircuitBreaker({
|
|
@@ -767,10 +834,10 @@ declare class CircuitBreakerOpenError extends Error {
|
|
|
767
834
|
* }
|
|
768
835
|
* ```
|
|
769
836
|
*
|
|
770
|
-
* @throws
|
|
771
|
-
* @throws
|
|
772
|
-
* @throws
|
|
773
|
-
* @throws
|
|
837
|
+
* @throws If failureThreshold is less than 1 or not a finite number
|
|
838
|
+
* @throws If recoveryTimeMs is not positive or not a finite number
|
|
839
|
+
* @throws If halfOpenMaxRequests is less than 1 or not a finite number
|
|
840
|
+
* @throws If failureWindowMs is not positive or not a finite number
|
|
774
841
|
*/
|
|
775
842
|
declare function createCircuitBreaker(config?: CircuitBreakerConfig): CircuitBreaker;
|
|
776
843
|
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -4,18 +4,44 @@ import { M as ModuleSchema, P as Plugin, J as System } from '../plugins-cDWoL7A7
|
|
|
4
4
|
* Logging Plugin - Console logging for Directive events
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for the {@link loggingPlugin}.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* All fields are optional. The defaults produce `[Directive]`-prefixed
|
|
12
|
+
* `console.info`-level output for every lifecycle event.
|
|
13
|
+
*
|
|
14
|
+
* | Field | Default | Description |
|
|
15
|
+
* |----------|-----------------|-------------|
|
|
16
|
+
* | `level` | `"info"` | Minimum severity to emit. |
|
|
17
|
+
* | `filter` | `() => true` | Predicate that receives the event name (e.g., `"fact.set"`) and returns whether to log it. |
|
|
18
|
+
* | `logger` | `console` | Any object implementing `debug`, `info`, `warn`, `error`, `group`, and `groupEnd`. |
|
|
19
|
+
* | `prefix` | `"[Directive]"` | String prepended to every log line. |
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
7
23
|
interface LoggingPluginOptions {
|
|
8
|
-
/**
|
|
24
|
+
/** Minimum log level; events below this severity are silenced. */
|
|
9
25
|
level?: "debug" | "info" | "warn" | "error";
|
|
10
|
-
/**
|
|
26
|
+
/** Predicate that receives the event name and returns whether to log it. */
|
|
11
27
|
filter?: (event: string) => boolean;
|
|
12
|
-
/** Custom logger (defaults to console) */
|
|
28
|
+
/** Custom logger object (defaults to `console`). */
|
|
13
29
|
logger?: Pick<Console, "debug" | "info" | "warn" | "error" | "group" | "groupEnd">;
|
|
14
|
-
/**
|
|
30
|
+
/** String prepended to every log message. */
|
|
15
31
|
prefix?: string;
|
|
16
32
|
}
|
|
17
33
|
/**
|
|
18
|
-
* Create a
|
|
34
|
+
* Create a plugin that logs Directive lifecycle events to a configurable logger.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* Every plugin hook is mapped to a log call at an appropriate severity:
|
|
38
|
+
* - `debug` -- init, destroy, fact changes, derivation compute/invalidate, reconcile, constraint evaluate, resolver start/cancel, effect run, snapshot
|
|
39
|
+
* - `info` -- start, stop, requirement met, resolver complete, time-travel jump
|
|
40
|
+
* - `warn` -- resolver retry, error recovery
|
|
41
|
+
* - `error` -- constraint error, resolver error, effect error, system error
|
|
42
|
+
*
|
|
43
|
+
* @param options - Optional {@link LoggingPluginOptions} to control level, filtering, logger backend, and prefix.
|
|
44
|
+
* @returns A {@link Plugin} that can be passed to `createSystem`'s `plugins` array.
|
|
19
45
|
*
|
|
20
46
|
* @example
|
|
21
47
|
* ```ts
|
|
@@ -24,6 +50,8 @@ interface LoggingPluginOptions {
|
|
|
24
50
|
* plugins: [loggingPlugin({ level: "debug" })],
|
|
25
51
|
* });
|
|
26
52
|
* ```
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
27
55
|
*/
|
|
28
56
|
declare function loggingPlugin<M extends ModuleSchema = ModuleSchema>(options?: LoggingPluginOptions): Plugin<M>;
|
|
29
57
|
|
|
@@ -164,26 +192,60 @@ declare function emitDevToolsEvent(event: Record<string, unknown> & {
|
|
|
164
192
|
* Persistence Plugin - Save/restore facts to storage
|
|
165
193
|
*/
|
|
166
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Configuration for the {@link persistencePlugin}.
|
|
197
|
+
*
|
|
198
|
+
* @remarks
|
|
199
|
+
* At minimum, provide a `storage` backend and a `key`. Use `include` or
|
|
200
|
+
* `exclude` to control which fact keys are persisted. Saves are debounced
|
|
201
|
+
* by default (100 ms) to avoid excessive writes during rapid updates.
|
|
202
|
+
*
|
|
203
|
+
* | Field | Default | Description |
|
|
204
|
+
* |-------------|---------|-------------|
|
|
205
|
+
* | `storage` | *(required)* | A `Storage`-compatible backend (`localStorage`, `sessionStorage`, or custom). |
|
|
206
|
+
* | `key` | *(required)* | The key used to read/write from storage. |
|
|
207
|
+
* | `include` | all keys | Whitelist of fact keys to persist. |
|
|
208
|
+
* | `exclude` | `[]` | Blacklist of fact keys to skip. |
|
|
209
|
+
* | `debounce` | `100` | Milliseconds to debounce saves. |
|
|
210
|
+
* | `onRestore` | -- | Callback fired after state is restored from storage. |
|
|
211
|
+
* | `onSave` | -- | Callback fired after state is written to storage. |
|
|
212
|
+
* | `onError` | -- | Callback fired when a load or save error occurs. |
|
|
213
|
+
*
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
167
216
|
interface PersistencePluginOptions {
|
|
168
|
-
/** Storage backend (localStorage
|
|
217
|
+
/** A `Storage`-compatible backend (`localStorage`, `sessionStorage`, or custom). */
|
|
169
218
|
storage: Storage;
|
|
170
|
-
/**
|
|
219
|
+
/** The key used to read/write from the storage backend. */
|
|
171
220
|
key: string;
|
|
172
|
-
/**
|
|
221
|
+
/** Whitelist of fact keys to persist (default: all keys). */
|
|
173
222
|
include?: string[];
|
|
174
|
-
/**
|
|
223
|
+
/** Fact keys to exclude from persistence. */
|
|
175
224
|
exclude?: string[];
|
|
176
|
-
/**
|
|
225
|
+
/** Milliseconds to debounce saves (default: 100). */
|
|
177
226
|
debounce?: number;
|
|
178
|
-
/**
|
|
227
|
+
/** Callback fired after state is restored from storage on init. */
|
|
179
228
|
onRestore?: (data: Record<string, unknown>) => void;
|
|
180
|
-
/**
|
|
229
|
+
/** Callback fired after state is written to storage. */
|
|
181
230
|
onSave?: (data: Record<string, unknown>) => void;
|
|
182
|
-
/**
|
|
231
|
+
/** Callback fired when a load or save error occurs. */
|
|
183
232
|
onError?: (error: Error) => void;
|
|
184
233
|
}
|
|
185
234
|
/**
|
|
186
|
-
* Create a
|
|
235
|
+
* Create a plugin that persists selected facts to a `Storage` backend and
|
|
236
|
+
* restores them on system init.
|
|
237
|
+
*
|
|
238
|
+
* @remarks
|
|
239
|
+
* On `onInit`, the plugin reads the storage key and batch-sets any persisted
|
|
240
|
+
* facts into the store. On every `onFactSet` / `onFactDelete` / `onFactsBatch`,
|
|
241
|
+
* a debounced save is scheduled. A final synchronous save runs on `onDestroy`
|
|
242
|
+
* to capture any pending changes.
|
|
243
|
+
*
|
|
244
|
+
* Stored data is validated against prototype pollution before restoration
|
|
245
|
+
* via {@link isPrototypeSafe}.
|
|
246
|
+
*
|
|
247
|
+
* @param options - Required {@link PersistencePluginOptions} specifying storage backend, key, and optional filters/callbacks.
|
|
248
|
+
* @returns A {@link Plugin} that can be passed to `createSystem`'s `plugins` array.
|
|
187
249
|
*
|
|
188
250
|
* @example
|
|
189
251
|
* ```ts
|
|
@@ -198,6 +260,8 @@ interface PersistencePluginOptions {
|
|
|
198
260
|
* ],
|
|
199
261
|
* });
|
|
200
262
|
* ```
|
|
263
|
+
*
|
|
264
|
+
* @public
|
|
201
265
|
*/
|
|
202
266
|
declare function persistencePlugin<M extends ModuleSchema = ModuleSchema>(options: PersistencePluginOptions): Plugin<M>;
|
|
203
267
|
|
|
@@ -747,6 +811,9 @@ declare class CircuitBreakerOpenError extends Error {
|
|
|
747
811
|
/**
|
|
748
812
|
* Create a circuit breaker for protecting against cascading failures.
|
|
749
813
|
*
|
|
814
|
+
* @param config - Circuit breaker configuration (thresholds, recovery time, observability)
|
|
815
|
+
* @returns A circuit breaker instance with `execute`, `getState`, and `reset` methods
|
|
816
|
+
*
|
|
750
817
|
* @example
|
|
751
818
|
* ```typescript
|
|
752
819
|
* const breaker = createCircuitBreaker({
|
|
@@ -767,10 +834,10 @@ declare class CircuitBreakerOpenError extends Error {
|
|
|
767
834
|
* }
|
|
768
835
|
* ```
|
|
769
836
|
*
|
|
770
|
-
* @throws
|
|
771
|
-
* @throws
|
|
772
|
-
* @throws
|
|
773
|
-
* @throws
|
|
837
|
+
* @throws If failureThreshold is less than 1 or not a finite number
|
|
838
|
+
* @throws If recoveryTimeMs is not positive or not a finite number
|
|
839
|
+
* @throws If halfOpenMaxRequests is less than 1 or not a finite number
|
|
840
|
+
* @throws If failureWindowMs is not positive or not a finite number
|
|
774
841
|
*/
|
|
775
842
|
declare function createCircuitBreaker(config?: CircuitBreakerConfig): CircuitBreaker;
|
|
776
843
|
|