@decaf-ts/ui-decorators 0.17.11 → 0.19.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/README.md +15 -1
- package/dist/ui-decorators.cjs +1 -1
- package/dist/ui-decorators.cjs.map +1 -1
- package/dist/ui-decorators.js +1 -1
- package/dist/ui-decorators.js.map +1 -1
- package/lib/cjs/graph/constants.cjs +28 -1
- package/lib/cjs/graph/constants.cjs.map +1 -1
- package/lib/cjs/index.cjs +3 -3
- package/lib/cjs/ui/Rendering.cjs +36 -6
- package/lib/cjs/ui/Rendering.cjs.map +1 -1
- package/lib/cjs/ui/constants.cjs +3 -0
- package/lib/cjs/ui/constants.cjs.map +1 -1
- package/lib/cjs/ui/decorators.cjs +28 -0
- package/lib/cjs/ui/decorators.cjs.map +1 -1
- package/lib/cjs/user-requests/UserRequestHandler.cjs +190 -0
- package/lib/cjs/user-requests/UserRequestHandler.cjs.map +1 -0
- package/lib/cjs/user-requests/constants.cjs +22 -0
- package/lib/cjs/user-requests/constants.cjs.map +1 -0
- package/lib/cjs/user-requests/decorators.cjs +41 -0
- package/lib/cjs/user-requests/decorators.cjs.map +1 -0
- package/lib/cjs/user-requests/errors.cjs +26 -0
- package/lib/cjs/user-requests/errors.cjs.map +1 -0
- package/lib/cjs/user-requests/index.cjs +33 -0
- package/lib/cjs/user-requests/index.cjs.map +1 -0
- package/lib/cjs/user-requests/types.cjs +4 -0
- package/lib/cjs/user-requests/types.cjs.map +1 -0
- package/lib/esm/graph/constants.js +26 -0
- package/lib/esm/graph/constants.js.map +1 -1
- package/lib/esm/index.js +3 -3
- package/lib/esm/ui/Rendering.js +36 -6
- package/lib/esm/ui/Rendering.js.map +1 -1
- package/lib/esm/ui/constants.js +3 -0
- package/lib/esm/ui/constants.js.map +1 -1
- package/lib/esm/ui/decorators.js +25 -0
- package/lib/esm/ui/decorators.js.map +1 -1
- package/lib/esm/user-requests/UserRequestHandler.js +185 -0
- package/lib/esm/user-requests/UserRequestHandler.js.map +1 -0
- package/lib/esm/user-requests/constants.js +18 -0
- package/lib/esm/user-requests/constants.js.map +1 -0
- package/lib/esm/user-requests/decorators.js +37 -0
- package/lib/esm/user-requests/decorators.js.map +1 -0
- package/lib/esm/user-requests/errors.js +21 -0
- package/lib/esm/user-requests/errors.js.map +1 -0
- package/lib/esm/user-requests/index.js +16 -0
- package/lib/esm/user-requests/index.js.map +1 -0
- package/lib/esm/user-requests/types.js +8 -0
- package/lib/esm/user-requests/types.js.map +1 -0
- package/lib/types/graph/constants.d.cts +66 -0
- package/lib/types/graph/constants.d.mts +66 -0
- package/lib/types/index.d.cts +3 -3
- package/lib/types/index.d.mts +3 -3
- package/lib/types/ui/constants.d.cts +3 -0
- package/lib/types/ui/constants.d.mts +3 -0
- package/lib/types/ui/decorators.d.cts +15 -0
- package/lib/types/ui/decorators.d.mts +15 -0
- package/lib/types/user-requests/UserRequestHandler.d.cts +117 -0
- package/lib/types/user-requests/UserRequestHandler.d.mts +117 -0
- package/lib/types/user-requests/constants.d.cts +17 -0
- package/lib/types/user-requests/constants.d.mts +17 -0
- package/lib/types/user-requests/decorators.d.cts +22 -0
- package/lib/types/user-requests/decorators.d.mts +22 -0
- package/lib/types/user-requests/errors.d.cts +18 -0
- package/lib/types/user-requests/errors.d.mts +18 -0
- package/lib/types/user-requests/index.d.cts +15 -0
- package/lib/types/user-requests/index.d.mts +15 -0
- package/lib/types/user-requests/types.d.cts +36 -0
- package/lib/types/user-requests/types.d.mts +36 -0
- package/package.json +22 -4
|
@@ -37,6 +37,11 @@ export type GraphNodeMetadata = {
|
|
|
37
37
|
* (the one-vs-all toggle). See {@link GraphPortGroupMetadata}.
|
|
38
38
|
*/
|
|
39
39
|
portGroups?: GraphPortGroupMetadata[];
|
|
40
|
+
/**
|
|
41
|
+
* Node I/O inspection hints (DECAF-48 §4.6) — viewer mode and which ports
|
|
42
|
+
* map to the inputs/outputs panes. Frontend-safe metadata only.
|
|
43
|
+
*/
|
|
44
|
+
inspection?: GraphNodeIoMetadata;
|
|
40
45
|
};
|
|
41
46
|
export type GraphWorkflowNodeMetadata = {
|
|
42
47
|
id: string;
|
|
@@ -45,7 +50,68 @@ export type GraphWorkflowNodeMetadata = {
|
|
|
45
50
|
description?: string;
|
|
46
51
|
node?: unknown;
|
|
47
52
|
metadata?: Record<string, unknown>;
|
|
53
|
+
/**
|
|
54
|
+
* Node I/O inspection hints for this workflow instance (DECAF-48 §4.6).
|
|
55
|
+
* Frontend-safe metadata only.
|
|
56
|
+
*/
|
|
57
|
+
inspection?: GraphNodeIoMetadata;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A view-mode choice for the reusable I/O viewer (DECAF-48 §4.6 / Req-9).
|
|
61
|
+
* One shared component renders both the inputs and outputs panes.
|
|
62
|
+
*/
|
|
63
|
+
export type GraphNodeIoViewMode = "json" | "table" | "raw";
|
|
64
|
+
/**
|
|
65
|
+
* Node I/O inspection metadata (DECAF-48 §4.6) — hints the workflow canvas
|
|
66
|
+
* uses to open the inline split view for an already-ran node. Framework
|
|
67
|
+
* neutral, frontend-safe, no engine/runtime dependency (DECAF-24 §4).
|
|
68
|
+
*/
|
|
69
|
+
export type GraphNodeIoMetadata = {
|
|
70
|
+
/** Default view mode for the reusable viewer. Defaults to "json". */
|
|
71
|
+
view?: GraphNodeIoViewMode;
|
|
72
|
+
/** Port property names shown in the right-side inputs pane. */
|
|
73
|
+
inputPorts?: string[];
|
|
74
|
+
/** Port property names shown in the left-side outputs pane. */
|
|
75
|
+
outputPorts?: string[];
|
|
76
|
+
/** Whether the node exposes editable config (opens the edit modal instead). */
|
|
77
|
+
editable?: boolean;
|
|
78
|
+
/** Free-form extension points. */
|
|
79
|
+
metadata?: Record<string, unknown>;
|
|
48
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Visual treatment for a node/edge execution state (DECAF-48 §4.4). Maps a
|
|
83
|
+
* {@link GraphVisualState} value to the faded glow / fade-after-fail overlay
|
|
84
|
+
* colours used by the canvas renderer.
|
|
85
|
+
*/
|
|
86
|
+
export type GraphVisualStyle = {
|
|
87
|
+
/** Visual state string as defined by the shared `GraphVisualState` values (e.g. `"running"`, `"blocked"`). */
|
|
88
|
+
state: string;
|
|
89
|
+
/** Glow/border colour for the live run-feedback overlay. */
|
|
90
|
+
glow?: string;
|
|
91
|
+
/** Level of fade for unexecuted/disabled rendering (0..1). */
|
|
92
|
+
opacity?: number;
|
|
93
|
+
/** Optional fill colour when the node is in this state. */
|
|
94
|
+
color?: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The default visual-state → overlay mapping contract (DECAF-48 §4.4):
|
|
98
|
+
* running=faded green, blocked=yellow, errored=red; succeeded keeps the
|
|
99
|
+
* node's own accent; unexecuted-after-failure fades/disabled. This is the
|
|
100
|
+
* shared, framework-neutral source of truth that supersedes the DECAF-32
|
|
101
|
+
* §21.9 running colour for the live run-feedback overlay (§4.5).
|
|
102
|
+
*/
|
|
103
|
+
export declare const GRAPH_VISUAL_STATE_STYLES: {
|
|
104
|
+
[state: string]: Omit<GraphVisualStyle, "state">;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Resolves the visual style overlay for a node/edge execution state, falling
|
|
108
|
+
* back to a neutral default when the state is unknown or unregistered.
|
|
109
|
+
*
|
|
110
|
+
* @param state - The visual state string (as defined by the shared
|
|
111
|
+
* `GraphVisualState` values, e.g. `"running"`, `"blocked"`).
|
|
112
|
+
* @returns The style overlay for the given state.
|
|
113
|
+
*/
|
|
114
|
+
export declare function graphVisualStyleOf(state: string): Omit<GraphVisualStyle, "state">;
|
|
49
115
|
export type GraphWorkflowRelationMetadata = {
|
|
50
116
|
source: string | unknown;
|
|
51
117
|
sourcePort?: string;
|
|
@@ -37,6 +37,11 @@ export type GraphNodeMetadata = {
|
|
|
37
37
|
* (the one-vs-all toggle). See {@link GraphPortGroupMetadata}.
|
|
38
38
|
*/
|
|
39
39
|
portGroups?: GraphPortGroupMetadata[];
|
|
40
|
+
/**
|
|
41
|
+
* Node I/O inspection hints (DECAF-48 §4.6) — viewer mode and which ports
|
|
42
|
+
* map to the inputs/outputs panes. Frontend-safe metadata only.
|
|
43
|
+
*/
|
|
44
|
+
inspection?: GraphNodeIoMetadata;
|
|
40
45
|
};
|
|
41
46
|
export type GraphWorkflowNodeMetadata = {
|
|
42
47
|
id: string;
|
|
@@ -45,7 +50,68 @@ export type GraphWorkflowNodeMetadata = {
|
|
|
45
50
|
description?: string;
|
|
46
51
|
node?: unknown;
|
|
47
52
|
metadata?: Record<string, unknown>;
|
|
53
|
+
/**
|
|
54
|
+
* Node I/O inspection hints for this workflow instance (DECAF-48 §4.6).
|
|
55
|
+
* Frontend-safe metadata only.
|
|
56
|
+
*/
|
|
57
|
+
inspection?: GraphNodeIoMetadata;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A view-mode choice for the reusable I/O viewer (DECAF-48 §4.6 / Req-9).
|
|
61
|
+
* One shared component renders both the inputs and outputs panes.
|
|
62
|
+
*/
|
|
63
|
+
export type GraphNodeIoViewMode = "json" | "table" | "raw";
|
|
64
|
+
/**
|
|
65
|
+
* Node I/O inspection metadata (DECAF-48 §4.6) — hints the workflow canvas
|
|
66
|
+
* uses to open the inline split view for an already-ran node. Framework
|
|
67
|
+
* neutral, frontend-safe, no engine/runtime dependency (DECAF-24 §4).
|
|
68
|
+
*/
|
|
69
|
+
export type GraphNodeIoMetadata = {
|
|
70
|
+
/** Default view mode for the reusable viewer. Defaults to "json". */
|
|
71
|
+
view?: GraphNodeIoViewMode;
|
|
72
|
+
/** Port property names shown in the right-side inputs pane. */
|
|
73
|
+
inputPorts?: string[];
|
|
74
|
+
/** Port property names shown in the left-side outputs pane. */
|
|
75
|
+
outputPorts?: string[];
|
|
76
|
+
/** Whether the node exposes editable config (opens the edit modal instead). */
|
|
77
|
+
editable?: boolean;
|
|
78
|
+
/** Free-form extension points. */
|
|
79
|
+
metadata?: Record<string, unknown>;
|
|
48
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Visual treatment for a node/edge execution state (DECAF-48 §4.4). Maps a
|
|
83
|
+
* {@link GraphVisualState} value to the faded glow / fade-after-fail overlay
|
|
84
|
+
* colours used by the canvas renderer.
|
|
85
|
+
*/
|
|
86
|
+
export type GraphVisualStyle = {
|
|
87
|
+
/** Visual state string as defined by the shared `GraphVisualState` values (e.g. `"running"`, `"blocked"`). */
|
|
88
|
+
state: string;
|
|
89
|
+
/** Glow/border colour for the live run-feedback overlay. */
|
|
90
|
+
glow?: string;
|
|
91
|
+
/** Level of fade for unexecuted/disabled rendering (0..1). */
|
|
92
|
+
opacity?: number;
|
|
93
|
+
/** Optional fill colour when the node is in this state. */
|
|
94
|
+
color?: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The default visual-state → overlay mapping contract (DECAF-48 §4.4):
|
|
98
|
+
* running=faded green, blocked=yellow, errored=red; succeeded keeps the
|
|
99
|
+
* node's own accent; unexecuted-after-failure fades/disabled. This is the
|
|
100
|
+
* shared, framework-neutral source of truth that supersedes the DECAF-32
|
|
101
|
+
* §21.9 running colour for the live run-feedback overlay (§4.5).
|
|
102
|
+
*/
|
|
103
|
+
export declare const GRAPH_VISUAL_STATE_STYLES: {
|
|
104
|
+
[state: string]: Omit<GraphVisualStyle, "state">;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Resolves the visual style overlay for a node/edge execution state, falling
|
|
108
|
+
* back to a neutral default when the state is unknown or unregistered.
|
|
109
|
+
*
|
|
110
|
+
* @param state - The visual state string (as defined by the shared
|
|
111
|
+
* `GraphVisualState` values, e.g. `"running"`, `"blocked"`).
|
|
112
|
+
* @returns The style overlay for the given state.
|
|
113
|
+
*/
|
|
114
|
+
export declare function graphVisualStyleOf(state: string): Omit<GraphVisualStyle, "state">;
|
|
49
115
|
export type GraphWorkflowRelationMetadata = {
|
|
50
116
|
source: string | unknown;
|
|
51
117
|
sourcePort?: string;
|
package/lib/types/index.d.cts
CHANGED
|
@@ -15,19 +15,19 @@ export * from "./ui/index.d.cts";
|
|
|
15
15
|
* @const VERSION
|
|
16
16
|
* @memberOf module:ui-decorators
|
|
17
17
|
*/
|
|
18
|
-
export declare const VERSION = "0.
|
|
18
|
+
export declare const VERSION = "0.18.0";
|
|
19
19
|
/**
|
|
20
20
|
* @description Represents the current commit hash of the module build.
|
|
21
21
|
* @summary Stores the current git commit hash for the package. The build replaces
|
|
22
22
|
* the placeholder with the actual commit hash at publish time.
|
|
23
23
|
* @const COMMIT
|
|
24
24
|
*/
|
|
25
|
-
export declare const COMMIT = "
|
|
25
|
+
export declare const COMMIT = "23dcb33";
|
|
26
26
|
/**
|
|
27
27
|
* @description Represents the full version string of the module.
|
|
28
28
|
* @summary Stores the semver version and commit hash for the package.
|
|
29
29
|
* The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
|
|
30
30
|
* @const FULL_VERSION
|
|
31
31
|
*/
|
|
32
|
-
export declare const FULL_VERSION = "0.
|
|
32
|
+
export declare const FULL_VERSION = "0.18.0-23dcb33";
|
|
33
33
|
export declare const PACKAGE_NAME = "@decaf-ts/ui-decorators";
|
package/lib/types/index.d.mts
CHANGED
|
@@ -15,19 +15,19 @@ export * from "./ui/index.d.mts";
|
|
|
15
15
|
* @const VERSION
|
|
16
16
|
* @memberOf module:ui-decorators
|
|
17
17
|
*/
|
|
18
|
-
export declare const VERSION = "0.
|
|
18
|
+
export declare const VERSION = "0.18.0";
|
|
19
19
|
/**
|
|
20
20
|
* @description Represents the current commit hash of the module build.
|
|
21
21
|
* @summary Stores the current git commit hash for the package. The build replaces
|
|
22
22
|
* the placeholder with the actual commit hash at publish time.
|
|
23
23
|
* @const COMMIT
|
|
24
24
|
*/
|
|
25
|
-
export declare const COMMIT = "
|
|
25
|
+
export declare const COMMIT = "23dcb33";
|
|
26
26
|
/**
|
|
27
27
|
* @description Represents the full version string of the module.
|
|
28
28
|
* @summary Stores the semver version and commit hash for the package.
|
|
29
29
|
* The build replaces the placeholder with the actual `<version>-<commit>` value at publish time.
|
|
30
30
|
* @const FULL_VERSION
|
|
31
31
|
*/
|
|
32
|
-
export declare const FULL_VERSION = "0.
|
|
32
|
+
export declare const FULL_VERSION = "0.18.0-23dcb33";
|
|
33
33
|
export declare const PACKAGE_NAME = "@decaf-ts/ui-decorators";
|
|
@@ -36,6 +36,21 @@ import { CrudOperationKeys, UIEventHandler, UIEventName, UIFunctionLike, UILayou
|
|
|
36
36
|
* RenderingEngine->>UI: Render or hide based on current operation
|
|
37
37
|
*/
|
|
38
38
|
export declare function hideOn(...operations: CrudOperationKeys[]): (object: any, propertyKey?: any) => any;
|
|
39
|
+
/**
|
|
40
|
+
* @description Decorator that hides a property for specific namespaces.
|
|
41
|
+
* @summary Controls property visibility based on namespace membership.
|
|
42
|
+
*/
|
|
43
|
+
export declare function hideFor(...namespaces: string[]): (object: any, propertyKey?: any) => any;
|
|
44
|
+
/**
|
|
45
|
+
* @description Decorator that shows a property only for specific namespaces.
|
|
46
|
+
* @summary Namespace-aware counterpart to `hideFor`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function showFor(...namespaces: string[]): (object: any, propertyKey?: any) => any;
|
|
49
|
+
/**
|
|
50
|
+
* @description Decorator that renders a property only when the namespace matches.
|
|
51
|
+
* @summary Convenience alias for namespace-scoped visibility control.
|
|
52
|
+
*/
|
|
53
|
+
export declare function renderIf(...namespaces: string[]): (object: any, propertyKey?: any) => any;
|
|
39
54
|
/**
|
|
40
55
|
* @description Decorator that sets the order of a UI element
|
|
41
56
|
* @summary Specifies the rendering order for UI components
|
|
@@ -36,6 +36,21 @@ import { CrudOperationKeys, UIEventHandler, UIEventName, UIFunctionLike, UILayou
|
|
|
36
36
|
* RenderingEngine->>UI: Render or hide based on current operation
|
|
37
37
|
*/
|
|
38
38
|
export declare function hideOn(...operations: CrudOperationKeys[]): (object: any, propertyKey?: any) => any;
|
|
39
|
+
/**
|
|
40
|
+
* @description Decorator that hides a property for specific namespaces.
|
|
41
|
+
* @summary Controls property visibility based on namespace membership.
|
|
42
|
+
*/
|
|
43
|
+
export declare function hideFor(...namespaces: string[]): (object: any, propertyKey?: any) => any;
|
|
44
|
+
/**
|
|
45
|
+
* @description Decorator that shows a property only for specific namespaces.
|
|
46
|
+
* @summary Namespace-aware counterpart to `hideFor`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function showFor(...namespaces: string[]): (object: any, propertyKey?: any) => any;
|
|
49
|
+
/**
|
|
50
|
+
* @description Decorator that renders a property only when the namespace matches.
|
|
51
|
+
* @summary Convenience alias for namespace-scoped visibility control.
|
|
52
|
+
*/
|
|
53
|
+
export declare function renderIf(...namespaces: string[]): (object: any, propertyKey?: any) => any;
|
|
39
54
|
/**
|
|
40
55
|
* @description Decorator that sets the order of a UI element
|
|
41
56
|
* @summary Specifies the rendering order for UI components
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests/UserRequestHandler
|
|
3
|
+
* @summary Service-based base class for user request handlers.
|
|
4
|
+
* @description No Angular or DOM imports — safe for pure-Node (backend) bundles.
|
|
5
|
+
*
|
|
6
|
+
* Handlers extend `Service`, receive a rendering-engine facade as a
|
|
7
|
+
* `protected readonly` property and implement `handle`, either returning the
|
|
8
|
+
* resolved value or throwing (a `CancelledError` when the user cancels
|
|
9
|
+
* mid-request). Lookup and dispatch are static: `@userRequest(reference)`
|
|
10
|
+
* records the class as metadata and `UserRequestHandler.getHandler(reference)`
|
|
11
|
+
* / `UserRequestHandler.handle(request, renderingEngine)` resolve and run it,
|
|
12
|
+
* so no process-wide registry instance is needed.
|
|
13
|
+
*/
|
|
14
|
+
import { Context, ContextFlags, ContextualArgs, FlagsOf, LoggerOf, MaybeContextualArg, MethodOrOperation, Service } from "@decaf-ts/core";
|
|
15
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
16
|
+
import type { RenderingFacade, UserRequest, UserRequestHandlerMetadata } from "./types.d.cts";
|
|
17
|
+
/**
|
|
18
|
+
* @description Result of `UserRequestHandler.logCtx(...)`. Extends the
|
|
19
|
+
* standard `{ log, ctx, ctxArgs }` surface with the exact `RenderingEngine`
|
|
20
|
+
* methods a handler needs (`modal`/`toast`/`spinner`/`router`) wrapping the
|
|
21
|
+
* rendering engine handed to the handler constructor. The keys mirror the
|
|
22
|
+
* underlying engine methods without a `get` prefix, and no duplicated
|
|
23
|
+
* `UserRequest*` rendering types are introduced.
|
|
24
|
+
* @summary Contextual surface returned by `UserRequestHandler.logCtx(*, *, true)`.
|
|
25
|
+
* @template C The decaf context the handler service runs under.
|
|
26
|
+
* @template ARGS The contextual argument tuple passed to the call.
|
|
27
|
+
*/
|
|
28
|
+
export interface UserRequestLogContext<C extends Context<ContextFlags<any>> = Context<ContextFlags<any>>, ARGS extends any[] = any[]> {
|
|
29
|
+
log: LoggerOf<C>;
|
|
30
|
+
ctx: C;
|
|
31
|
+
ctxArgs: ContextualArgs<C, ARGS>;
|
|
32
|
+
readonly modal: RenderingFacade["getModal"];
|
|
33
|
+
readonly toast: RenderingFacade["getToast"];
|
|
34
|
+
readonly spinner: RenderingFacade["getSpinner"];
|
|
35
|
+
readonly router: RenderingFacade["router"];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @description Abstract base class for user request handlers.
|
|
39
|
+
*
|
|
40
|
+
* Handler methods follow the core `Service` golden rules: `handle` (and the
|
|
41
|
+
* lifecycle helpers `getInput`/`cancel`) accept rest contextual args
|
|
42
|
+
* (`...args: ContextualArgs<C>`) and obtain their `{ log, ctx, ctxArgs }` via
|
|
43
|
+
* `this.logCtx([request, ...args], this.handle, true)` — entry and resolution
|
|
44
|
+
* via `log.info`, transitions via `log.verbose`, payload details via
|
|
45
|
+
* `log.debug` and failures/cancellations via `log.error`. A `CancelledError`
|
|
46
|
+
* is thrown when the user cancels mid-request. `handle` is the one async
|
|
47
|
+
* method handlers override, returning the resolved value or throwing.
|
|
48
|
+
* @summary Service-based base class implementing the user request lifecycle.
|
|
49
|
+
* @template T The resolved payload type the handler returns.
|
|
50
|
+
* @template C The decaf context the service runs under.
|
|
51
|
+
*/
|
|
52
|
+
export declare abstract class UserRequestHandler<T = unknown, C extends Context<ContextFlags<any>> = Context<ContextFlags<any>>> extends Service<C> {
|
|
53
|
+
protected readonly renderingEngine: RenderingFacade;
|
|
54
|
+
private currentModal?;
|
|
55
|
+
private cancelled;
|
|
56
|
+
private submitted?;
|
|
57
|
+
private dismissed?;
|
|
58
|
+
/**
|
|
59
|
+
* @description Creates a handler bound to the given rendering-engine facade.
|
|
60
|
+
* The facade is the only external dependency: no context/resolver
|
|
61
|
+
* indirection.
|
|
62
|
+
* @param {RenderingFacade} renderingEngine The rendering-engine surface the
|
|
63
|
+
* handler drives (modal, toast, spinner and router).
|
|
64
|
+
*/
|
|
65
|
+
protected constructor(renderingEngine: RenderingFacade);
|
|
66
|
+
/**
|
|
67
|
+
* @description Resolves the handler class registered for the given request
|
|
68
|
+
* reference via `Metadata`. Handlers are recorded by the `@userRequest`
|
|
69
|
+
* decorator under `USER_REQUEST_KEY`.
|
|
70
|
+
* @param {string} reference The request id/type the handler is registered
|
|
71
|
+
* for.
|
|
72
|
+
* @return {.Constructor<UserRequestHandler> | undefined}
|
|
73
|
+
* The registered handler constructor, or `undefined` when unknown.
|
|
74
|
+
*/
|
|
75
|
+
static getHandler(reference: string): Constructor<UserRequestHandler> | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* @description Reads the `@userRequest` metadata recorded on a handler class
|
|
78
|
+
* via `Metadata`.
|
|
79
|
+
* @param {object} target The handler class to inspect.
|
|
80
|
+
* @return {UserRequestHandlerMetadata | undefined} The recorded metadata
|
|
81
|
+
* `{ reference }`, or `undefined` when the class is not decorated.
|
|
82
|
+
*/
|
|
83
|
+
static getMetadata(target: object): UserRequestHandlerMetadata | undefined;
|
|
84
|
+
static handle<T = unknown>(request: UserRequest<T>, renderingEngine: RenderingFacade): Promise<T>;
|
|
85
|
+
protected getInput(request: UserRequest<T>, ...args: ContextualArgs<C>): Promise<T>;
|
|
86
|
+
private awaitDismissal;
|
|
87
|
+
cancel(...args: ContextualArgs<C> | []): Promise<void>;
|
|
88
|
+
abstract handle(request: UserRequest<T>, ...args: ContextualArgs<C>): Promise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* @description Logging + rendering-engine methods for a call. Mirrors the
|
|
91
|
+
* `Service` `logCtx` contract and exposes `modal`/`toast`/`spinner`/`router`
|
|
92
|
+
* getters wrapping the rendering engine.
|
|
93
|
+
* @param {MaybeContextualArg<C, ARGS>} args Contextual args (context at the
|
|
94
|
+
* end, or pre-args plus context).
|
|
95
|
+
* @param {METHOD} operation The operation the context is created for.
|
|
96
|
+
* @param {boolean} allowCreate Whether a context is created when none is
|
|
97
|
+
* provided.
|
|
98
|
+
* @param {Partial<FlagsOf<CONTEXT>>} overrides Optional flag overrides.
|
|
99
|
+
* @return {UserRequestLogContext<C, ARGS> | Promise<UserRequestLogContext<C, ARGS>>}
|
|
100
|
+
* The contextual surface (or a promise of it when `allowCreate` is true).
|
|
101
|
+
* @template C The decaf context the service runs under.
|
|
102
|
+
* @template ARGS The contextual argument tuple passed to the call.
|
|
103
|
+
* @template CONTEXT The context type to promote to when creating one.
|
|
104
|
+
* @template METHOD The operation the context is created for.
|
|
105
|
+
*/
|
|
106
|
+
protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<C, ARGS>, operation: METHOD): UserRequestLogContext<C, ARGS>;
|
|
107
|
+
protected logCtx<CONTEXT extends Context<any> = C, ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD, allowCreate: false, overrides?: Partial<FlagsOf<CONTEXT>>): UserRequestLogContext<C, ARGS>;
|
|
108
|
+
protected logCtx<CONTEXT extends Context<any> = C, ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD, allowCreate: true, overrides?: Partial<FlagsOf<CONTEXT>>): Promise<UserRequestLogContext<C, ARGS>>;
|
|
109
|
+
/**
|
|
110
|
+
* @description Decorates the base contextual surface with the rendering
|
|
111
|
+
* engine methods exposed as `modal`/`toast`/`spinner`/`router` bound getters.
|
|
112
|
+
* @return {UserRequestLogContext<C, ARGS>} The decorated contextual surface.
|
|
113
|
+
* @template C The decaf context the service runs under.
|
|
114
|
+
* @template ARGS The contextual argument tuple passed to the call.
|
|
115
|
+
*/
|
|
116
|
+
private wrapLogContext;
|
|
117
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests/UserRequestHandler
|
|
3
|
+
* @summary Service-based base class for user request handlers.
|
|
4
|
+
* @description No Angular or DOM imports — safe for pure-Node (backend) bundles.
|
|
5
|
+
*
|
|
6
|
+
* Handlers extend `Service`, receive a rendering-engine facade as a
|
|
7
|
+
* `protected readonly` property and implement `handle`, either returning the
|
|
8
|
+
* resolved value or throwing (a `CancelledError` when the user cancels
|
|
9
|
+
* mid-request). Lookup and dispatch are static: `@userRequest(reference)`
|
|
10
|
+
* records the class as metadata and `UserRequestHandler.getHandler(reference)`
|
|
11
|
+
* / `UserRequestHandler.handle(request, renderingEngine)` resolve and run it,
|
|
12
|
+
* so no process-wide registry instance is needed.
|
|
13
|
+
*/
|
|
14
|
+
import { Context, ContextFlags, ContextualArgs, FlagsOf, LoggerOf, MaybeContextualArg, MethodOrOperation, Service } from "@decaf-ts/core";
|
|
15
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
16
|
+
import type { RenderingFacade, UserRequest, UserRequestHandlerMetadata } from "./types.d.mts";
|
|
17
|
+
/**
|
|
18
|
+
* @description Result of `UserRequestHandler.logCtx(...)`. Extends the
|
|
19
|
+
* standard `{ log, ctx, ctxArgs }` surface with the exact `RenderingEngine`
|
|
20
|
+
* methods a handler needs (`modal`/`toast`/`spinner`/`router`) wrapping the
|
|
21
|
+
* rendering engine handed to the handler constructor. The keys mirror the
|
|
22
|
+
* underlying engine methods without a `get` prefix, and no duplicated
|
|
23
|
+
* `UserRequest*` rendering types are introduced.
|
|
24
|
+
* @summary Contextual surface returned by `UserRequestHandler.logCtx(*, *, true)`.
|
|
25
|
+
* @template C The decaf context the handler service runs under.
|
|
26
|
+
* @template ARGS The contextual argument tuple passed to the call.
|
|
27
|
+
*/
|
|
28
|
+
export interface UserRequestLogContext<C extends Context<ContextFlags<any>> = Context<ContextFlags<any>>, ARGS extends any[] = any[]> {
|
|
29
|
+
log: LoggerOf<C>;
|
|
30
|
+
ctx: C;
|
|
31
|
+
ctxArgs: ContextualArgs<C, ARGS>;
|
|
32
|
+
readonly modal: RenderingFacade["getModal"];
|
|
33
|
+
readonly toast: RenderingFacade["getToast"];
|
|
34
|
+
readonly spinner: RenderingFacade["getSpinner"];
|
|
35
|
+
readonly router: RenderingFacade["router"];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @description Abstract base class for user request handlers.
|
|
39
|
+
*
|
|
40
|
+
* Handler methods follow the core `Service` golden rules: `handle` (and the
|
|
41
|
+
* lifecycle helpers `getInput`/`cancel`) accept rest contextual args
|
|
42
|
+
* (`...args: ContextualArgs<C>`) and obtain their `{ log, ctx, ctxArgs }` via
|
|
43
|
+
* `this.logCtx([request, ...args], this.handle, true)` — entry and resolution
|
|
44
|
+
* via `log.info`, transitions via `log.verbose`, payload details via
|
|
45
|
+
* `log.debug` and failures/cancellations via `log.error`. A `CancelledError`
|
|
46
|
+
* is thrown when the user cancels mid-request. `handle` is the one async
|
|
47
|
+
* method handlers override, returning the resolved value or throwing.
|
|
48
|
+
* @summary Service-based base class implementing the user request lifecycle.
|
|
49
|
+
* @template T The resolved payload type the handler returns.
|
|
50
|
+
* @template C The decaf context the service runs under.
|
|
51
|
+
*/
|
|
52
|
+
export declare abstract class UserRequestHandler<T = unknown, C extends Context<ContextFlags<any>> = Context<ContextFlags<any>>> extends Service<C> {
|
|
53
|
+
protected readonly renderingEngine: RenderingFacade;
|
|
54
|
+
private currentModal?;
|
|
55
|
+
private cancelled;
|
|
56
|
+
private submitted?;
|
|
57
|
+
private dismissed?;
|
|
58
|
+
/**
|
|
59
|
+
* @description Creates a handler bound to the given rendering-engine facade.
|
|
60
|
+
* The facade is the only external dependency: no context/resolver
|
|
61
|
+
* indirection.
|
|
62
|
+
* @param {RenderingFacade} renderingEngine The rendering-engine surface the
|
|
63
|
+
* handler drives (modal, toast, spinner and router).
|
|
64
|
+
*/
|
|
65
|
+
protected constructor(renderingEngine: RenderingFacade);
|
|
66
|
+
/**
|
|
67
|
+
* @description Resolves the handler class registered for the given request
|
|
68
|
+
* reference via `Metadata`. Handlers are recorded by the `@userRequest`
|
|
69
|
+
* decorator under `USER_REQUEST_KEY`.
|
|
70
|
+
* @param {string} reference The request id/type the handler is registered
|
|
71
|
+
* for.
|
|
72
|
+
* @return {.Constructor<UserRequestHandler> | undefined}
|
|
73
|
+
* The registered handler constructor, or `undefined` when unknown.
|
|
74
|
+
*/
|
|
75
|
+
static getHandler(reference: string): Constructor<UserRequestHandler> | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* @description Reads the `@userRequest` metadata recorded on a handler class
|
|
78
|
+
* via `Metadata`.
|
|
79
|
+
* @param {object} target The handler class to inspect.
|
|
80
|
+
* @return {UserRequestHandlerMetadata | undefined} The recorded metadata
|
|
81
|
+
* `{ reference }`, or `undefined` when the class is not decorated.
|
|
82
|
+
*/
|
|
83
|
+
static getMetadata(target: object): UserRequestHandlerMetadata | undefined;
|
|
84
|
+
static handle<T = unknown>(request: UserRequest<T>, renderingEngine: RenderingFacade): Promise<T>;
|
|
85
|
+
protected getInput(request: UserRequest<T>, ...args: ContextualArgs<C>): Promise<T>;
|
|
86
|
+
private awaitDismissal;
|
|
87
|
+
cancel(...args: ContextualArgs<C> | []): Promise<void>;
|
|
88
|
+
abstract handle(request: UserRequest<T>, ...args: ContextualArgs<C>): Promise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* @description Logging + rendering-engine methods for a call. Mirrors the
|
|
91
|
+
* `Service` `logCtx` contract and exposes `modal`/`toast`/`spinner`/`router`
|
|
92
|
+
* getters wrapping the rendering engine.
|
|
93
|
+
* @param {MaybeContextualArg<C, ARGS>} args Contextual args (context at the
|
|
94
|
+
* end, or pre-args plus context).
|
|
95
|
+
* @param {METHOD} operation The operation the context is created for.
|
|
96
|
+
* @param {boolean} allowCreate Whether a context is created when none is
|
|
97
|
+
* provided.
|
|
98
|
+
* @param {Partial<FlagsOf<CONTEXT>>} overrides Optional flag overrides.
|
|
99
|
+
* @return {UserRequestLogContext<C, ARGS> | Promise<UserRequestLogContext<C, ARGS>>}
|
|
100
|
+
* The contextual surface (or a promise of it when `allowCreate` is true).
|
|
101
|
+
* @template C The decaf context the service runs under.
|
|
102
|
+
* @template ARGS The contextual argument tuple passed to the call.
|
|
103
|
+
* @template CONTEXT The context type to promote to when creating one.
|
|
104
|
+
* @template METHOD The operation the context is created for.
|
|
105
|
+
*/
|
|
106
|
+
protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<C, ARGS>, operation: METHOD): UserRequestLogContext<C, ARGS>;
|
|
107
|
+
protected logCtx<CONTEXT extends Context<any> = C, ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD, allowCreate: false, overrides?: Partial<FlagsOf<CONTEXT>>): UserRequestLogContext<C, ARGS>;
|
|
108
|
+
protected logCtx<CONTEXT extends Context<any> = C, ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<CONTEXT, ARGS>, operation: METHOD, allowCreate: true, overrides?: Partial<FlagsOf<CONTEXT>>): Promise<UserRequestLogContext<C, ARGS>>;
|
|
109
|
+
/**
|
|
110
|
+
* @description Decorates the base contextual surface with the rendering
|
|
111
|
+
* engine methods exposed as `modal`/`toast`/`spinner`/`router` bound getters.
|
|
112
|
+
* @return {UserRequestLogContext<C, ARGS>} The decorated contextual surface.
|
|
113
|
+
* @template C The decaf context the service runs under.
|
|
114
|
+
* @template ARGS The contextual argument tuple passed to the call.
|
|
115
|
+
*/
|
|
116
|
+
private wrapLogContext;
|
|
117
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests/constants
|
|
3
|
+
* @summary Metadata keys for the User Request Resolution Engine.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @description Metadata key under which user request handlers are registered
|
|
7
|
+
* and resolved.
|
|
8
|
+
* @summary The `@userRequest(reference)` decorator stores both the handler
|
|
9
|
+
* reference and the decorating metadata under this key, and
|
|
10
|
+
* `UserRequestHandler.getHandler` / `UserRequestHandler.getMetadata` read it
|
|
11
|
+
* back. The key is scoped to the User Request Resolution Engine to avoid
|
|
12
|
+
* colliding with other reflection metadata.
|
|
13
|
+
* @const USER_REQUEST_KEY
|
|
14
|
+
* @type {string}
|
|
15
|
+
* @readonly
|
|
16
|
+
*/
|
|
17
|
+
export declare const USER_REQUEST_KEY = "user-requests.handler";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests/constants
|
|
3
|
+
* @summary Metadata keys for the User Request Resolution Engine.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @description Metadata key under which user request handlers are registered
|
|
7
|
+
* and resolved.
|
|
8
|
+
* @summary The `@userRequest(reference)` decorator stores both the handler
|
|
9
|
+
* reference and the decorating metadata under this key, and
|
|
10
|
+
* `UserRequestHandler.getHandler` / `UserRequestHandler.getMetadata` read it
|
|
11
|
+
* back. The key is scoped to the User Request Resolution Engine to avoid
|
|
12
|
+
* colliding with other reflection metadata.
|
|
13
|
+
* @const USER_REQUEST_KEY
|
|
14
|
+
* @type {string}
|
|
15
|
+
* @readonly
|
|
16
|
+
*/
|
|
17
|
+
export declare const USER_REQUEST_KEY = "user-requests.handler";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests/decorators
|
|
3
|
+
* @summary `@userRequest(reference)` class decorator.
|
|
4
|
+
* @description No Angular or DOM imports — safe for pure-Node (backend)
|
|
5
|
+
* bundles. Registration is metadata-based: the decorator records the handler
|
|
6
|
+
* class under `USER_REQUEST_KEY` and the static `UserRequestHandler` methods
|
|
7
|
+
* resolve and dispatch it, so no process-wide registry is involved.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @description Registers a handler class for the given request id/type.
|
|
11
|
+
*
|
|
12
|
+
* Mirrors `core/src/migrations/decorators.ts`:
|
|
13
|
+
* `Decoration.for(KEY).define({ decorator, args }).apply()` plus
|
|
14
|
+
* `Metadata.set(USER_REQUEST_KEY, reference, original)` so the class is
|
|
15
|
+
* retrievable by id via metadata — `UserRequestHandler.getHandler(reference)`
|
|
16
|
+
* reads it back and `UserRequestHandler.handle(request, renderingEngine)`
|
|
17
|
+
* dispatches it — and a class-level `metadata(...)` payload for
|
|
18
|
+
* introspection (`UserRequestHandler.getMetadata(target)`).
|
|
19
|
+
* @param {string} reference The request id/type the handler is registered for.
|
|
20
|
+
* @return {ClassDecorator} The class decorator to apply.
|
|
21
|
+
*/
|
|
22
|
+
export declare function userRequest(reference: string): ClassDecorator;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests/decorators
|
|
3
|
+
* @summary `@userRequest(reference)` class decorator.
|
|
4
|
+
* @description No Angular or DOM imports — safe for pure-Node (backend)
|
|
5
|
+
* bundles. Registration is metadata-based: the decorator records the handler
|
|
6
|
+
* class under `USER_REQUEST_KEY` and the static `UserRequestHandler` methods
|
|
7
|
+
* resolve and dispatch it, so no process-wide registry is involved.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @description Registers a handler class for the given request id/type.
|
|
11
|
+
*
|
|
12
|
+
* Mirrors `core/src/migrations/decorators.ts`:
|
|
13
|
+
* `Decoration.for(KEY).define({ decorator, args }).apply()` plus
|
|
14
|
+
* `Metadata.set(USER_REQUEST_KEY, reference, original)` so the class is
|
|
15
|
+
* retrievable by id via metadata — `UserRequestHandler.getHandler(reference)`
|
|
16
|
+
* reads it back and `UserRequestHandler.handle(request, renderingEngine)`
|
|
17
|
+
* dispatches it — and a class-level `metadata(...)` payload for
|
|
18
|
+
* introspection (`UserRequestHandler.getMetadata(target)`).
|
|
19
|
+
* @param {string} reference The request id/type the handler is registered for.
|
|
20
|
+
* @return {ClassDecorator} The class decorator to apply.
|
|
21
|
+
*/
|
|
22
|
+
export declare function userRequest(reference: string): ClassDecorator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests/errors
|
|
3
|
+
* @summary Decaf error hierarchy for the User Request Resolution Engine.
|
|
4
|
+
*/
|
|
5
|
+
import { InternalError } from "@decaf-ts/db-decorators";
|
|
6
|
+
/**
|
|
7
|
+
* @description Error thrown when the user cancels a user request mid-resolution.
|
|
8
|
+
* Follows the decaf error hierarchy: never a raw `Error`. Compatible with the
|
|
9
|
+
* validation error signaling used by `@devcerts/decaf` UI facades.
|
|
10
|
+
* @summary Error thrown when a user request is cancelled.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CancelledError extends InternalError {
|
|
13
|
+
/**
|
|
14
|
+
* @param {string | Error | unknown} msg The cancellation message.
|
|
15
|
+
* @return {CancelledError} A new `CancelledError`.
|
|
16
|
+
*/
|
|
17
|
+
constructor(msg?: string | Error | unknown);
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests/errors
|
|
3
|
+
* @summary Decaf error hierarchy for the User Request Resolution Engine.
|
|
4
|
+
*/
|
|
5
|
+
import { InternalError } from "@decaf-ts/db-decorators";
|
|
6
|
+
/**
|
|
7
|
+
* @description Error thrown when the user cancels a user request mid-resolution.
|
|
8
|
+
* Follows the decaf error hierarchy: never a raw `Error`. Compatible with the
|
|
9
|
+
* validation error signaling used by `@devcerts/decaf` UI facades.
|
|
10
|
+
* @summary Error thrown when a user request is cancelled.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CancelledError extends InternalError {
|
|
13
|
+
/**
|
|
14
|
+
* @param {string | Error | unknown} msg The cancellation message.
|
|
15
|
+
* @return {CancelledError} A new `CancelledError`.
|
|
16
|
+
*/
|
|
17
|
+
constructor(msg?: string | Error | unknown);
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ui-decorators/user-requests
|
|
3
|
+
* @summary Backend binding surface for the User Request Resolution Engine.
|
|
4
|
+
* @description Framework-agnostic core of the engine: no Angular or DOM
|
|
5
|
+
* imports, safe for pure-Node (backend) bundles. Handlers are registered via
|
|
6
|
+
* `@userRequest(reference)` (metadata) and resolved/dispatched through the
|
|
7
|
+
* static `UserRequestHandler` methods; example handlers and rendering-engine
|
|
8
|
+
* mocks live only in the test tree, never under `src`. Frontend bindings live
|
|
9
|
+
* in `for-angular`.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./constants.d.cts";
|
|
12
|
+
export * from "./errors.d.cts";
|
|
13
|
+
export * from "./types.d.cts";
|
|
14
|
+
export * from "./UserRequestHandler.d.cts";
|
|
15
|
+
export * from "./decorators.d.cts";
|