@statedelta-actions/actions 0.5.0 → 0.6.0
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/CHANGELOG.md +96 -0
- package/LICENSE +21 -0
- package/dist/index.d.cts +70 -40
- package/dist/index.d.ts +70 -40
- package/package.json +16 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @statedelta-actions/actions
|
|
2
|
+
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a3a818b: `HandlerDefinition` is now a discriminated union by execution mode
|
|
8
|
+
|
|
9
|
+
`HandlerDefinition<TCtx>` is `SyncHandlerDefinition<TCtx> | AsyncHandlerDefinition<TCtx> | InteractiveHandlerDefinition<TCtx>` — the `async` / `interactive` flags discriminate, and `execute` refines its return type per mode (`ApplyResult` for sync, `Promise<ApplyResult>` for async, `Generator<unknown, ApplyResult, unknown> | AsyncGenerator<unknown, ApplyResult, unknown>` for interactive). Consumers that call `handler.execute(...)` directly (tests, wrappers) — typing the handler as a subtype, or narrowing the union via the flags — no longer get the wide `ApplyResult | Promise<ApplyResult>` union for a handler they know is sync.
|
|
10
|
+
|
|
11
|
+
New exports: `HandlerBaseDefinition`, `SyncHandlerDefinition`, `AsyncHandlerDefinition`, `InteractiveHandlerDefinition`, `SyncHandlerExecute`, `AsyncHandlerExecute`, `InteractiveHandlerExecute`.
|
|
12
|
+
|
|
13
|
+
**Breaking (minor, pre-1.0):**
|
|
14
|
+
- A V2 handler that is `async` or `interactive` must now declare the `async: true` / `interactive: true` flag to satisfy the type. `{ async execute() {} }` without `async: true` no longer matches `HandlerDefinition` (it matches no subtype: sync requires a sync return, async/interactive require the flag). Runtime auto-detection via `isAsyncFunction` / `isGeneratorFunction` still works as a safety net — the type just forces the declaration to be explicit for V2.
|
|
15
|
+
- `HandlerDefinition<TCtx>["execute"]` is wider than before (it now includes the `Generator | AsyncGenerator` arm) — code that assigned `handler.execute` to `(...) => ApplyResult | Promise<ApplyResult>` needs to narrow or use a subtype. (This also fixes a latent bug: interactive handlers' `execute` previously violated the declared type silently.)
|
|
16
|
+
- V1 handlers (plain functions) and `HandlerInput<TCtx>` are unchanged.
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 26c579a: Polish published package metadata and READMEs
|
|
21
|
+
- `@statedelta-actions/core` now ships a README (was missing on npm).
|
|
22
|
+
- `@statedelta-actions/analyzer` README: fixed pervasive missing accents.
|
|
23
|
+
- `graph` and `events` READMEs: titles are now the package name (`# @statedelta-actions/graph` / `# @statedelta-actions/events`) instead of a conceptual name.
|
|
24
|
+
- All packages: added `keywords`, `homepage`, `bugs`; package.json keys reordered to a canonical layout.
|
|
25
|
+
- All packages: `CHANGELOG.md` added to `files` so it ships to npm; a `LICENSE` (MIT) file is included in the repo root and in each package.
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [26c579a]
|
|
28
|
+
- @statedelta-actions/core@0.5.1
|
|
29
|
+
|
|
30
|
+
## 0.5.0
|
|
31
|
+
|
|
32
|
+
### Minor Changes
|
|
33
|
+
|
|
34
|
+
- f8c2b4a: Fail-fast register errors, controlled `action-not-found`, atomic registration, and events async/interactive modes
|
|
35
|
+
- **actions** — A missing handler for a directive type now throws at register
|
|
36
|
+
time (was a collected error) — fail-fast for typos and forgotten handlers.
|
|
37
|
+
Invoking an unknown action id returns `aborted: true, abortedBy:
|
|
38
|
+
"action-not-found"` instead of a soft failure. `isActionAsync` is exposed on
|
|
39
|
+
the engine ref handed to handlers (symmetric with `isActionInteractive`).
|
|
40
|
+
- **rules** — `register()` is atomic: it builds a staging set, delegates to the
|
|
41
|
+
ActionEngine, then indexes locally only on success. Structural errors from the
|
|
42
|
+
ActionEngine propagate as a throw with no local state mutated.
|
|
43
|
+
- **events** — `register()`/`defineEvents()` are atomic the same way.
|
|
44
|
+
Async detection is now per-listener transitive via the ActionEngine mini-graph,
|
|
45
|
+
so hybrid engines keep `processEvents`/`processEventsAsync` viable for
|
|
46
|
+
listeners whose subtree is fully sync. New `processEventsInteractive()` returns
|
|
47
|
+
a drainable iterator (sync or async generator) — pauses from `type:"pause"` or
|
|
48
|
+
an interactive handler flow via `yield*` up to the consumer; halt scoping is
|
|
49
|
+
preserved (a pause stops the listeners of that event, following events
|
|
50
|
+
continue). New `isInteractive` getter.
|
|
51
|
+
- **core** — `ActionEngineRef` gains an optional `isActionAsync?` accessor.
|
|
52
|
+
- **sdk** — re-exports the new event types/surface; barrel deps moved to
|
|
53
|
+
`dependencies` (`workspace:^`).
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Updated dependencies [f8c2b4a]
|
|
58
|
+
- @statedelta-actions/core@0.5.0
|
|
59
|
+
|
|
60
|
+
## 0.3.0
|
|
61
|
+
|
|
62
|
+
### Minor Changes
|
|
63
|
+
|
|
64
|
+
- Split types em definitions + engine em cada package; novo subpath sdk/definitions
|
|
65
|
+
- core: RegisterWarning movido pra core/types/engine.ts (tipo shared entre packages)
|
|
66
|
+
- actions: types.ts → types/definitions.ts + types/engine.ts
|
|
67
|
+
- rules: types.ts → types/definitions.ts + types/engine.ts
|
|
68
|
+
- events: types.ts → types/definitions.ts + types/engine.ts
|
|
69
|
+
- sdk: novo subpath ./definitions com re-export de definition types puros (zero runtime)
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- Updated dependencies []:
|
|
74
|
+
- @statedelta-actions/core@0.3.0
|
|
75
|
+
|
|
76
|
+
## 0.2.0
|
|
77
|
+
|
|
78
|
+
### Minor Changes
|
|
79
|
+
|
|
80
|
+
- Sync all packages to 0.2.0 (match SDK version)
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- Updated dependencies []:
|
|
85
|
+
- @statedelta-actions/core@0.2.0
|
|
86
|
+
|
|
87
|
+
## 0.3.0
|
|
88
|
+
|
|
89
|
+
### Minor Changes
|
|
90
|
+
|
|
91
|
+
- Sync all packages to 0.2.0 (match SDK version)
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- Updated dependencies []:
|
|
96
|
+
- @statedelta-actions/core@0.3.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anderson D. Rosa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Directive, ExecutionFrame,
|
|
1
|
+
import { Directive, ExecutionFrame, ActionEngineRef, ApplyResult, RuleEngineRef, RegisterWarning, DirectiveResult, HookFn, InterceptResult, AbortDecision, FrameLimits, SlotAnalysis } from '@statedelta-actions/core';
|
|
2
2
|
export { RegisterWarning } from '@statedelta-actions/core';
|
|
3
3
|
|
|
4
4
|
type DirectiveHandler<TCtx> = (directive: Directive, frame: ExecutionFrame<TCtx>, engine: RuleEngineRef<TCtx>) => ApplyResult | Promise<ApplyResult>;
|
|
@@ -12,52 +12,82 @@ interface ValidationResult {
|
|
|
12
12
|
error?: string;
|
|
13
13
|
warnings?: string[];
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Campos comuns a todo handler V2, independente do modo de execução.
|
|
17
|
+
* `execute` fica nos subtipos — cada modo refina seu retorno. Não é genérico
|
|
18
|
+
* porque nenhuma das fases (`analyze`/`validate`/`compile`) usa `TCtx`.
|
|
19
|
+
*/
|
|
20
|
+
interface HandlerBaseDefinition {
|
|
16
21
|
/** Register-time: extrai capabilities e dependências. */
|
|
17
22
|
analyze?: (directive: Directive) => HandlerAnalysis;
|
|
18
23
|
/** Register-time: valida estrutura da directive. */
|
|
19
24
|
validate?: (directive: Directive) => ValidationResult | void;
|
|
20
25
|
/** JIT-time: contribui código inline per-action (Fase 2c). */
|
|
21
26
|
compile?: (directive: Directive, compiler: unknown) => string | void;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
}
|
|
28
|
+
/** Função `execute` de um handler sync — retorna `ApplyResult` direto. */
|
|
29
|
+
type SyncHandlerExecute<TCtx> = (directive: Directive, frame: ExecutionFrame<TCtx>, engine: ActionEngineRef<TCtx>) => ApplyResult;
|
|
30
|
+
/** Função `execute` de um handler async — retorna `Promise<ApplyResult>`. */
|
|
31
|
+
type AsyncHandlerExecute<TCtx> = (directive: Directive, frame: ExecutionFrame<TCtx>, engine: ActionEngineRef<TCtx>) => Promise<ApplyResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Função `execute` de um handler interactive — generator (sync ou async).
|
|
34
|
+
* O yield é `unknown`: o handler controla o protocol (o que yielda, o que
|
|
35
|
+
* recebe via `next`). O engine apenas empacota o yield como `PauseEvent.payload`
|
|
36
|
+
* pro consumer no nível raiz (ver ADR-024). O return é o `ApplyResult` final.
|
|
37
|
+
*/
|
|
38
|
+
type InteractiveHandlerExecute<TCtx> = (directive: Directive, frame: ExecutionFrame<TCtx>, engine: ActionEngineRef<TCtx>) => Generator<unknown, ApplyResult, unknown> | AsyncGenerator<unknown, ApplyResult, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Handler sync — `execute` retorna `ApplyResult` direto. É o modo default:
|
|
41
|
+
* sem flag e sem `async function`/`function*`, o handler é tratado como sync.
|
|
42
|
+
*/
|
|
43
|
+
interface SyncHandlerDefinition<TCtx> extends HandlerBaseDefinition {
|
|
44
|
+
async?: false;
|
|
45
|
+
interactive?: false;
|
|
46
|
+
execute: SyncHandlerExecute<TCtx>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Handler async — `execute` retorna `Promise<ApplyResult>`. Marcado com
|
|
50
|
+
* `async: true` ou detectado via `isAsyncFunction(execute)` (cobre
|
|
51
|
+
* `async function`). Use a flag pra wrappers que retornam Promise sem serem
|
|
52
|
+
* `async function` (ex: factory que delega via `.then`).
|
|
53
|
+
*
|
|
54
|
+
* Quando o engine vê um handler async: inclui no async handler set, força
|
|
55
|
+
* `isAsync = true` no engine inteiro, e emite `await` ao invocá-lo no
|
|
56
|
+
* interpreter async e nos JITs.
|
|
57
|
+
*/
|
|
58
|
+
interface AsyncHandlerDefinition<TCtx> extends HandlerBaseDefinition {
|
|
59
|
+
async: true;
|
|
60
|
+
interactive?: false;
|
|
61
|
+
execute: AsyncHandlerExecute<TCtx>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handler interactive — `execute` é generator (sync ou async). Marcado com
|
|
65
|
+
* `interactive: true` ou detectado via `isGeneratorFunction(execute)` (cobre
|
|
66
|
+
* `function*` e `async function*`). Use a flag pra wrappers que retornam
|
|
67
|
+
* iterator sem serem generator function. Pode também ser `async` (generator
|
|
68
|
+
* async) — daí `async: true` junto.
|
|
69
|
+
*
|
|
70
|
+
* Quando o engine vê um handler interactive: inclui no interactive handler set,
|
|
71
|
+
* propaga `_interactiveActions` transitivamente no mini-graph, emite
|
|
72
|
+
* `yield* handler(...)` ao invocá-lo nas actions interactive, e exige
|
|
73
|
+
* `engine.invokeInteractive()` em actions cuja sub-árvore o use. Handler
|
|
74
|
+
* `interactive: true` em engine sem `interactive` config → erro no constructor
|
|
75
|
+
* (fail-fast).
|
|
76
|
+
*/
|
|
77
|
+
interface InteractiveHandlerDefinition<TCtx> extends HandlerBaseDefinition {
|
|
78
|
+
interactive: true;
|
|
37
79
|
async?: boolean;
|
|
38
|
-
|
|
39
|
-
* Marca o handler como interativo (opt-in explícito).
|
|
40
|
-
*
|
|
41
|
-
* Quando true (ou quando `execute` é uma `function*` / `async function*`),
|
|
42
|
-
* o engine:
|
|
43
|
-
* - inclui este handler no interactive handler set;
|
|
44
|
-
* - propaga transitividade `_interactiveActions` no mini-graph;
|
|
45
|
-
* - emite `yield* handler(...)` ao invocar nas actions interactive;
|
|
46
|
-
* - exige `engine.invokeInteractive()` em actions cuja sub-árvore use o handler.
|
|
47
|
-
*
|
|
48
|
-
* Auto-detecção via `isGeneratorFunction(execute)` cobre `function*` e
|
|
49
|
-
* `async function*`. Use a flag para wrappers que retornam iterator sem
|
|
50
|
-
* serem generator function.
|
|
51
|
-
*
|
|
52
|
-
* Handler com `interactive: true` em engine sem `interactive` config →
|
|
53
|
-
* erro no constructor (fail-fast).
|
|
54
|
-
*
|
|
55
|
-
* Sem flag e sem generator function: handler é tratado como regular.
|
|
56
|
-
*/
|
|
57
|
-
interactive?: boolean;
|
|
58
|
-
/** Runtime: executa a directive (obrigatório). */
|
|
59
|
-
execute: (directive: Directive, frame: ExecutionFrame<TCtx>, engine: ActionEngineRef<TCtx>) => ApplyResult | Promise<ApplyResult>;
|
|
80
|
+
execute: InteractiveHandlerExecute<TCtx>;
|
|
60
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Handler V2 (objeto com fases). Discriminated union pelo modo de execução —
|
|
84
|
+
* `async` e `interactive` discriminam, `execute` refina seu retorno conforme
|
|
85
|
+
* o modo. Tipar como `HandlerDefinition<TCtx>` continua válido (é o agregado);
|
|
86
|
+
* narrowing pelos flags refina pro subtipo. Quem sabe o modo do seu handler
|
|
87
|
+
* pode tipar diretamente como `SyncHandlerDefinition` etc. e chamar
|
|
88
|
+
* `handler.execute(...)` sem `await`/narrowing.
|
|
89
|
+
*/
|
|
90
|
+
type HandlerDefinition<TCtx> = SyncHandlerDefinition<TCtx> | AsyncHandlerDefinition<TCtx> | InteractiveHandlerDefinition<TCtx>;
|
|
61
91
|
/**
|
|
62
92
|
* Aceita handler V1 (função) ou V2 (objeto com fases).
|
|
63
93
|
* Backwards compat: função simples é tratada como { execute: fn }.
|
|
@@ -565,4 +595,4 @@ interface GeneratedActionExecutor {
|
|
|
565
595
|
*/
|
|
566
596
|
declare function buildActionExecutor(directives: readonly Directive[], analysis: SlotAnalysis, typeField: string, asyncHandlerSet?: ReadonlySet<string>, actionUsesAsyncOverride?: boolean, actionIsInteractive?: boolean, interactiveHandlerSet?: ReadonlySet<string>): GeneratedActionExecutor;
|
|
567
597
|
|
|
568
|
-
export { type ActionDefinition, type ActionHooks, type ActionInterceptResult, type AsyncInteractiveSession, type DirectiveExecutorFn, type DirectiveHandler, type DirectiveHandlerMap, type DirectiveHooks, type DirectivePermission, type DirectivePermissionConfig, type DirectivePermissionEntry, type DirectivePermissionStatus, type DirectiveRunnerFn, type EngineEventMap, type EngineEventName, type GeneratedActionExecutor, type GeneratedDirectiveExecutor, type HandlerAnalysis, type HandlerDefinition, type HandlerInput, type HandlerInputMap, type IActionEngine, type IActionEngineConfig, type InteractiveApplyResult, type InteractiveConfig, type InteractiveSession, type Listener, type PauseEvent, RESERVED_TYPES, type RegisterError, type RegisterEvent, type RegisterResult, type Responder, SimpleEmitter, type UnregisterEvent, type ValidationResult, buildActionExecutor, buildDirectiveExecutor, createActionEngine, createDirectiveInterpreter, drainAsync, drainSync, normalizeDirectives, replayResponder };
|
|
598
|
+
export { type ActionDefinition, type ActionHooks, type ActionInterceptResult, type AsyncHandlerDefinition, type AsyncHandlerExecute, type AsyncInteractiveSession, type DirectiveExecutorFn, type DirectiveHandler, type DirectiveHandlerMap, type DirectiveHooks, type DirectivePermission, type DirectivePermissionConfig, type DirectivePermissionEntry, type DirectivePermissionStatus, type DirectiveRunnerFn, type EngineEventMap, type EngineEventName, type GeneratedActionExecutor, type GeneratedDirectiveExecutor, type HandlerAnalysis, type HandlerBaseDefinition, type HandlerDefinition, type HandlerInput, type HandlerInputMap, type IActionEngine, type IActionEngineConfig, type InteractiveApplyResult, type InteractiveConfig, type InteractiveHandlerDefinition, type InteractiveHandlerExecute, type InteractiveSession, type Listener, type PauseEvent, RESERVED_TYPES, type RegisterError, type RegisterEvent, type RegisterResult, type Responder, SimpleEmitter, type SyncHandlerDefinition, type SyncHandlerExecute, type UnregisterEvent, type ValidationResult, buildActionExecutor, buildDirectiveExecutor, createActionEngine, createDirectiveInterpreter, drainAsync, drainSync, normalizeDirectives, replayResponder };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Directive, ExecutionFrame,
|
|
1
|
+
import { Directive, ExecutionFrame, ActionEngineRef, ApplyResult, RuleEngineRef, RegisterWarning, DirectiveResult, HookFn, InterceptResult, AbortDecision, FrameLimits, SlotAnalysis } from '@statedelta-actions/core';
|
|
2
2
|
export { RegisterWarning } from '@statedelta-actions/core';
|
|
3
3
|
|
|
4
4
|
type DirectiveHandler<TCtx> = (directive: Directive, frame: ExecutionFrame<TCtx>, engine: RuleEngineRef<TCtx>) => ApplyResult | Promise<ApplyResult>;
|
|
@@ -12,52 +12,82 @@ interface ValidationResult {
|
|
|
12
12
|
error?: string;
|
|
13
13
|
warnings?: string[];
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Campos comuns a todo handler V2, independente do modo de execução.
|
|
17
|
+
* `execute` fica nos subtipos — cada modo refina seu retorno. Não é genérico
|
|
18
|
+
* porque nenhuma das fases (`analyze`/`validate`/`compile`) usa `TCtx`.
|
|
19
|
+
*/
|
|
20
|
+
interface HandlerBaseDefinition {
|
|
16
21
|
/** Register-time: extrai capabilities e dependências. */
|
|
17
22
|
analyze?: (directive: Directive) => HandlerAnalysis;
|
|
18
23
|
/** Register-time: valida estrutura da directive. */
|
|
19
24
|
validate?: (directive: Directive) => ValidationResult | void;
|
|
20
25
|
/** JIT-time: contribui código inline per-action (Fase 2c). */
|
|
21
26
|
compile?: (directive: Directive, compiler: unknown) => string | void;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
}
|
|
28
|
+
/** Função `execute` de um handler sync — retorna `ApplyResult` direto. */
|
|
29
|
+
type SyncHandlerExecute<TCtx> = (directive: Directive, frame: ExecutionFrame<TCtx>, engine: ActionEngineRef<TCtx>) => ApplyResult;
|
|
30
|
+
/** Função `execute` de um handler async — retorna `Promise<ApplyResult>`. */
|
|
31
|
+
type AsyncHandlerExecute<TCtx> = (directive: Directive, frame: ExecutionFrame<TCtx>, engine: ActionEngineRef<TCtx>) => Promise<ApplyResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Função `execute` de um handler interactive — generator (sync ou async).
|
|
34
|
+
* O yield é `unknown`: o handler controla o protocol (o que yielda, o que
|
|
35
|
+
* recebe via `next`). O engine apenas empacota o yield como `PauseEvent.payload`
|
|
36
|
+
* pro consumer no nível raiz (ver ADR-024). O return é o `ApplyResult` final.
|
|
37
|
+
*/
|
|
38
|
+
type InteractiveHandlerExecute<TCtx> = (directive: Directive, frame: ExecutionFrame<TCtx>, engine: ActionEngineRef<TCtx>) => Generator<unknown, ApplyResult, unknown> | AsyncGenerator<unknown, ApplyResult, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Handler sync — `execute` retorna `ApplyResult` direto. É o modo default:
|
|
41
|
+
* sem flag e sem `async function`/`function*`, o handler é tratado como sync.
|
|
42
|
+
*/
|
|
43
|
+
interface SyncHandlerDefinition<TCtx> extends HandlerBaseDefinition {
|
|
44
|
+
async?: false;
|
|
45
|
+
interactive?: false;
|
|
46
|
+
execute: SyncHandlerExecute<TCtx>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Handler async — `execute` retorna `Promise<ApplyResult>`. Marcado com
|
|
50
|
+
* `async: true` ou detectado via `isAsyncFunction(execute)` (cobre
|
|
51
|
+
* `async function`). Use a flag pra wrappers que retornam Promise sem serem
|
|
52
|
+
* `async function` (ex: factory que delega via `.then`).
|
|
53
|
+
*
|
|
54
|
+
* Quando o engine vê um handler async: inclui no async handler set, força
|
|
55
|
+
* `isAsync = true` no engine inteiro, e emite `await` ao invocá-lo no
|
|
56
|
+
* interpreter async e nos JITs.
|
|
57
|
+
*/
|
|
58
|
+
interface AsyncHandlerDefinition<TCtx> extends HandlerBaseDefinition {
|
|
59
|
+
async: true;
|
|
60
|
+
interactive?: false;
|
|
61
|
+
execute: AsyncHandlerExecute<TCtx>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handler interactive — `execute` é generator (sync ou async). Marcado com
|
|
65
|
+
* `interactive: true` ou detectado via `isGeneratorFunction(execute)` (cobre
|
|
66
|
+
* `function*` e `async function*`). Use a flag pra wrappers que retornam
|
|
67
|
+
* iterator sem serem generator function. Pode também ser `async` (generator
|
|
68
|
+
* async) — daí `async: true` junto.
|
|
69
|
+
*
|
|
70
|
+
* Quando o engine vê um handler interactive: inclui no interactive handler set,
|
|
71
|
+
* propaga `_interactiveActions` transitivamente no mini-graph, emite
|
|
72
|
+
* `yield* handler(...)` ao invocá-lo nas actions interactive, e exige
|
|
73
|
+
* `engine.invokeInteractive()` em actions cuja sub-árvore o use. Handler
|
|
74
|
+
* `interactive: true` em engine sem `interactive` config → erro no constructor
|
|
75
|
+
* (fail-fast).
|
|
76
|
+
*/
|
|
77
|
+
interface InteractiveHandlerDefinition<TCtx> extends HandlerBaseDefinition {
|
|
78
|
+
interactive: true;
|
|
37
79
|
async?: boolean;
|
|
38
|
-
|
|
39
|
-
* Marca o handler como interativo (opt-in explícito).
|
|
40
|
-
*
|
|
41
|
-
* Quando true (ou quando `execute` é uma `function*` / `async function*`),
|
|
42
|
-
* o engine:
|
|
43
|
-
* - inclui este handler no interactive handler set;
|
|
44
|
-
* - propaga transitividade `_interactiveActions` no mini-graph;
|
|
45
|
-
* - emite `yield* handler(...)` ao invocar nas actions interactive;
|
|
46
|
-
* - exige `engine.invokeInteractive()` em actions cuja sub-árvore use o handler.
|
|
47
|
-
*
|
|
48
|
-
* Auto-detecção via `isGeneratorFunction(execute)` cobre `function*` e
|
|
49
|
-
* `async function*`. Use a flag para wrappers que retornam iterator sem
|
|
50
|
-
* serem generator function.
|
|
51
|
-
*
|
|
52
|
-
* Handler com `interactive: true` em engine sem `interactive` config →
|
|
53
|
-
* erro no constructor (fail-fast).
|
|
54
|
-
*
|
|
55
|
-
* Sem flag e sem generator function: handler é tratado como regular.
|
|
56
|
-
*/
|
|
57
|
-
interactive?: boolean;
|
|
58
|
-
/** Runtime: executa a directive (obrigatório). */
|
|
59
|
-
execute: (directive: Directive, frame: ExecutionFrame<TCtx>, engine: ActionEngineRef<TCtx>) => ApplyResult | Promise<ApplyResult>;
|
|
80
|
+
execute: InteractiveHandlerExecute<TCtx>;
|
|
60
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Handler V2 (objeto com fases). Discriminated union pelo modo de execução —
|
|
84
|
+
* `async` e `interactive` discriminam, `execute` refina seu retorno conforme
|
|
85
|
+
* o modo. Tipar como `HandlerDefinition<TCtx>` continua válido (é o agregado);
|
|
86
|
+
* narrowing pelos flags refina pro subtipo. Quem sabe o modo do seu handler
|
|
87
|
+
* pode tipar diretamente como `SyncHandlerDefinition` etc. e chamar
|
|
88
|
+
* `handler.execute(...)` sem `await`/narrowing.
|
|
89
|
+
*/
|
|
90
|
+
type HandlerDefinition<TCtx> = SyncHandlerDefinition<TCtx> | AsyncHandlerDefinition<TCtx> | InteractiveHandlerDefinition<TCtx>;
|
|
61
91
|
/**
|
|
62
92
|
* Aceita handler V1 (função) ou V2 (objeto com fases).
|
|
63
93
|
* Backwards compat: função simples é tratada como { execute: fn }.
|
|
@@ -565,4 +595,4 @@ interface GeneratedActionExecutor {
|
|
|
565
595
|
*/
|
|
566
596
|
declare function buildActionExecutor(directives: readonly Directive[], analysis: SlotAnalysis, typeField: string, asyncHandlerSet?: ReadonlySet<string>, actionUsesAsyncOverride?: boolean, actionIsInteractive?: boolean, interactiveHandlerSet?: ReadonlySet<string>): GeneratedActionExecutor;
|
|
567
597
|
|
|
568
|
-
export { type ActionDefinition, type ActionHooks, type ActionInterceptResult, type AsyncInteractiveSession, type DirectiveExecutorFn, type DirectiveHandler, type DirectiveHandlerMap, type DirectiveHooks, type DirectivePermission, type DirectivePermissionConfig, type DirectivePermissionEntry, type DirectivePermissionStatus, type DirectiveRunnerFn, type EngineEventMap, type EngineEventName, type GeneratedActionExecutor, type GeneratedDirectiveExecutor, type HandlerAnalysis, type HandlerDefinition, type HandlerInput, type HandlerInputMap, type IActionEngine, type IActionEngineConfig, type InteractiveApplyResult, type InteractiveConfig, type InteractiveSession, type Listener, type PauseEvent, RESERVED_TYPES, type RegisterError, type RegisterEvent, type RegisterResult, type Responder, SimpleEmitter, type UnregisterEvent, type ValidationResult, buildActionExecutor, buildDirectiveExecutor, createActionEngine, createDirectiveInterpreter, drainAsync, drainSync, normalizeDirectives, replayResponder };
|
|
598
|
+
export { type ActionDefinition, type ActionHooks, type ActionInterceptResult, type AsyncHandlerDefinition, type AsyncHandlerExecute, type AsyncInteractiveSession, type DirectiveExecutorFn, type DirectiveHandler, type DirectiveHandlerMap, type DirectiveHooks, type DirectivePermission, type DirectivePermissionConfig, type DirectivePermissionEntry, type DirectivePermissionStatus, type DirectiveRunnerFn, type EngineEventMap, type EngineEventName, type GeneratedActionExecutor, type GeneratedDirectiveExecutor, type HandlerAnalysis, type HandlerBaseDefinition, type HandlerDefinition, type HandlerInput, type HandlerInputMap, type IActionEngine, type IActionEngineConfig, type InteractiveApplyResult, type InteractiveConfig, type InteractiveHandlerDefinition, type InteractiveHandlerExecute, type InteractiveSession, type Listener, type PauseEvent, RESERVED_TYPES, type RegisterError, type RegisterEvent, type RegisterResult, type Responder, SimpleEmitter, type SyncHandlerDefinition, type SyncHandlerExecute, type UnregisterEvent, type ValidationResult, buildActionExecutor, buildDirectiveExecutor, createActionEngine, createDirectiveInterpreter, drainAsync, drainSync, normalizeDirectives, replayResponder };
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statedelta-actions/actions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Directive execution engine with JIT compilation and BailHook interception",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"statedelta",
|
|
7
|
+
"directive-engine",
|
|
8
|
+
"jit",
|
|
9
|
+
"rule-engine",
|
|
10
|
+
"state-machine",
|
|
11
|
+
"action-engine"
|
|
12
|
+
],
|
|
5
13
|
"type": "module",
|
|
6
14
|
"main": "./dist/index.cjs",
|
|
7
15
|
"module": "./dist/index.js",
|
|
@@ -15,10 +23,11 @@
|
|
|
15
23
|
},
|
|
16
24
|
"files": [
|
|
17
25
|
"dist",
|
|
18
|
-
"README.md"
|
|
26
|
+
"README.md",
|
|
27
|
+
"CHANGELOG.md"
|
|
19
28
|
],
|
|
20
29
|
"dependencies": {
|
|
21
|
-
"@statedelta-actions/core": "0.5.
|
|
30
|
+
"@statedelta-actions/core": "0.5.1"
|
|
22
31
|
},
|
|
23
32
|
"author": "Anderson D. Rosa <andersondrosa@outlook.com>",
|
|
24
33
|
"license": "MIT",
|
|
@@ -27,6 +36,10 @@
|
|
|
27
36
|
"url": "https://github.com/andersondrosa/statedelta-actions.git",
|
|
28
37
|
"directory": "packages/actions"
|
|
29
38
|
},
|
|
39
|
+
"homepage": "https://github.com/andersondrosa/statedelta-actions/tree/main/packages/actions#readme",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/andersondrosa/statedelta-actions/issues"
|
|
42
|
+
},
|
|
30
43
|
"sideEffects": false,
|
|
31
44
|
"engines": {
|
|
32
45
|
"node": ">=18"
|