@kellanjs/actioncraft 0.1.0 → 0.2.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 +411 -302
- package/dist/actioncraft-error.d.ts +23 -0
- package/dist/actioncraft-error.js +60 -0
- package/dist/actioncraft-error.js.map +1 -0
- package/dist/actioncraft-prev.d.ts +93 -0
- package/dist/actioncraft-prev.js +387 -0
- package/dist/actioncraft-prev.js.map +1 -0
- package/dist/actioncraft.d.ts +94 -44
- package/dist/actioncraft.js +281 -55
- package/dist/actioncraft.js.map +1 -1
- package/dist/api.d.ts +49 -0
- package/dist/api.js +84 -0
- package/dist/api.js.map +1 -0
- package/dist/classes/action-builder.d.ts +59 -0
- package/dist/classes/action-builder.js +95 -0
- package/dist/classes/action-builder.js.map +1 -0
- package/dist/classes/craft-builder.d.ts +66 -0
- package/dist/classes/craft-builder.js +129 -0
- package/dist/classes/craft-builder.js.map +1 -0
- package/dist/classes/crafter.d.ts +66 -0
- package/dist/classes/crafter.js +129 -0
- package/dist/classes/crafter.js.map +1 -0
- package/dist/classes/error.d.ts +23 -0
- package/dist/classes/error.js +60 -0
- package/dist/classes/error.js.map +1 -0
- package/dist/classes/executor/callbacks.d.ts +6 -0
- package/dist/classes/executor/callbacks.js +20 -0
- package/dist/classes/executor/callbacks.js.map +1 -0
- package/dist/classes/executor/errors.d.ts +29 -0
- package/dist/classes/executor/errors.js +114 -0
- package/dist/classes/executor/errors.js.map +1 -0
- package/dist/classes/executor/executor.d.ts +68 -0
- package/dist/classes/executor/executor.js +391 -0
- package/dist/classes/executor/executor.js.map +1 -0
- package/dist/classes/executor/logging.d.ts +2 -0
- package/dist/classes/executor/logging.js +8 -0
- package/dist/classes/executor/logging.js.map +1 -0
- package/dist/classes/executor/transformation.d.ts +17 -0
- package/dist/classes/executor/transformation.js +43 -0
- package/dist/classes/executor/transformation.js.map +1 -0
- package/dist/classes/executor/validation.d.ts +16 -0
- package/dist/classes/executor/validation.js +70 -0
- package/dist/classes/executor/validation.js.map +1 -0
- package/dist/classes/executor.d.ts +64 -0
- package/dist/classes/executor.js +354 -0
- package/dist/classes/executor.js.map +1 -0
- package/dist/classes/internal.d.ts +10 -0
- package/dist/classes/internal.js +5 -0
- package/dist/classes/internal.js.map +1 -0
- package/dist/core/errors.d.ts +2 -2
- package/dist/core/errors.js +5 -5
- package/dist/core/errors.js.map +1 -1
- package/dist/core/logging.d.ts +1 -1
- package/dist/core/transformation.d.ts +2 -2
- package/dist/core/validation.d.ts +4 -4
- package/dist/core/validation.js +14 -14
- package/dist/core/validation.js.map +1 -1
- package/dist/craft.d.ts +29 -0
- package/dist/craft.js +62 -0
- package/dist/craft.js.map +1 -0
- package/dist/error.d.ts +21 -6
- package/dist/error.js +59 -10
- package/dist/error.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/initial.d.ts +14 -0
- package/dist/initial.js +47 -0
- package/dist/initial.js.map +1 -0
- package/dist/types/actions.d.ts +67 -25
- package/dist/types/builder.d.ts +92 -0
- package/dist/types/builder.js +2 -0
- package/dist/types/builder.js.map +1 -0
- package/dist/types/crafter.d.ts +87 -0
- package/dist/types/crafter.js +2 -0
- package/dist/types/crafter.js.map +1 -0
- package/dist/types/errors.d.ts +25 -17
- package/dist/types/inference.d.ts +41 -8
- package/dist/types/result.d.ts +8 -14
- package/dist/types/result.js +36 -4
- package/dist/types/result.js.map +1 -1
- package/dist/types/schemas.d.ts +7 -7
- package/dist/types/shared.d.ts +14 -6
- package/dist/utils.d.ts +30 -6
- package/dist/utils.js +68 -8
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
package/dist/actioncraft.d.ts
CHANGED
|
@@ -1,85 +1,135 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { CrafterConfig, CrafterSchemas, CrafterErrors, CrafterCallbacks } from "./types/
|
|
1
|
+
import type { Handler, CraftedAction, InferDataFromHandler, HandlerParams } from "./types/actions.js";
|
|
2
|
+
import type { CrafterConfig, CrafterSchemas, CrafterErrors, CrafterCallbacks } from "./types/crafter.js";
|
|
3
3
|
import type { InferResult } from "./types/inference.js";
|
|
4
|
-
|
|
5
|
-
* Builder class for creating type-safe server actions with validation, error handling, and callbacks.
|
|
6
|
-
*/
|
|
4
|
+
declare const INTERNAL: unique symbol;
|
|
7
5
|
declare class Crafter<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> {
|
|
8
6
|
private readonly _config;
|
|
9
7
|
private readonly _schemas;
|
|
10
8
|
private readonly _errors;
|
|
11
9
|
private readonly _callbacks;
|
|
12
|
-
private readonly
|
|
13
|
-
constructor(config: TConfig, schemas: TSchemas, errors: TErrors, callbacks: TCallbacks,
|
|
10
|
+
private readonly _handler?;
|
|
11
|
+
constructor(config: TConfig, schemas: TSchemas, errors: TErrors, callbacks: TCallbacks, handler?: Handler<TConfig, TSchemas, TErrors, TData>);
|
|
12
|
+
/**
|
|
13
|
+
* Defines configuration options for the action.
|
|
14
|
+
* Resets previously defined handler and callbacks.
|
|
15
|
+
*/
|
|
16
|
+
config<TNewConfig extends CrafterConfig>(config: TNewConfig): Crafter<TNewConfig, TSchemas, TErrors, Record<string, never>, unknown>;
|
|
14
17
|
/**
|
|
15
18
|
* Defines validation schemas for input, output, and bind arguments.
|
|
16
|
-
* Resets previously defined
|
|
19
|
+
* Resets previously defined handler and callbacks.
|
|
17
20
|
*/
|
|
18
21
|
schemas<TNewSchemas extends CrafterSchemas>(schemas: TNewSchemas): Crafter<TConfig, TNewSchemas, TErrors, Record<string, never>, unknown>;
|
|
19
22
|
/**
|
|
20
|
-
* Defines error functions for returning typed errors from
|
|
21
|
-
* Resets previously defined
|
|
23
|
+
* Defines error functions for returning typed errors from the handler.
|
|
24
|
+
* Resets previously defined handler and callbacks.
|
|
22
25
|
*/
|
|
23
26
|
errors<const TNewErrors extends CrafterErrors>(errors: TNewErrors): Crafter<TConfig, TSchemas, TNewErrors, Record<string, never>, unknown>;
|
|
24
27
|
/**
|
|
25
|
-
* Defines the
|
|
28
|
+
* Defines the handler function containing the server action's business logic.
|
|
26
29
|
* Resets previously defined callbacks.
|
|
27
30
|
*/
|
|
28
|
-
|
|
31
|
+
handler<TFn extends (params: HandlerParams<TConfig, TSchemas, TErrors, TData>) => Promise<unknown>>(fn: TFn): Crafter<TConfig, TSchemas, TErrors, Record<string, never>, InferDataFromHandler<TFn>>;
|
|
29
32
|
/**
|
|
30
|
-
* Defines lifecycle callbacks
|
|
31
|
-
* Must be called after
|
|
33
|
+
* Defines lifecycle callbacks to be triggered during the exection of an action.
|
|
34
|
+
* Must be called after handler() for correct type inference.
|
|
32
35
|
*/
|
|
33
36
|
callbacks<TNewCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>>(callbacks: TNewCallbacks): Crafter<TConfig, TSchemas, TErrors, TNewCallbacks, TData>;
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
craft(): CraftedAction<TConfig, TSchemas, TErrors, TData>;
|
|
38
|
-
/** Orchestrates action execution including validation, business logic, callbacks, and result formatting. */
|
|
39
|
-
private _runAction;
|
|
40
|
-
/**
|
|
41
|
-
* Extracts bind arguments, previous state, and input from raw action arguments.
|
|
38
|
+
* @returns Internal properties of the Crafter instance
|
|
42
39
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
[INTERNAL](): {
|
|
41
|
+
config: TConfig;
|
|
42
|
+
schemas: TSchemas;
|
|
43
|
+
errors: TErrors;
|
|
44
|
+
callbacks: TCallbacks;
|
|
45
|
+
handler: Handler<TConfig, TSchemas, TErrors, TData> | undefined;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
declare class ActionBuilder<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> {
|
|
49
|
+
private readonly _config;
|
|
50
|
+
private readonly _schemas;
|
|
51
|
+
private readonly _errors;
|
|
52
|
+
private readonly _callbacks;
|
|
53
|
+
private readonly _handler?;
|
|
54
|
+
constructor(config: TConfig, schemas: TSchemas, errors: TErrors, callbacks: TCallbacks, handler?: Handler<TConfig, TSchemas, TErrors, TData>);
|
|
52
55
|
/**
|
|
53
|
-
*
|
|
56
|
+
* Defines configuration options for the action.
|
|
57
|
+
* Resets previously defined handler and callbacks.
|
|
54
58
|
*/
|
|
55
|
-
|
|
59
|
+
config<TNewConfig extends CrafterConfig>(config: TNewConfig): ActionBuilder<TNewConfig, TSchemas, TErrors, Record<string, never>, unknown>;
|
|
56
60
|
/**
|
|
57
|
-
*
|
|
61
|
+
* Defines validation schemas for input, output, and bind arguments.
|
|
62
|
+
* Resets previously defined handler and callbacks.
|
|
58
63
|
*/
|
|
59
|
-
|
|
64
|
+
schemas<TNewSchemas extends CrafterSchemas>(schemas: TNewSchemas): ActionBuilder<TConfig, TNewSchemas, TErrors, Record<string, never>, unknown>;
|
|
60
65
|
/**
|
|
61
|
-
*
|
|
66
|
+
* Defines error functions for returning typed errors from the handler.
|
|
67
|
+
* Resets previously defined handler and callbacks.
|
|
62
68
|
*/
|
|
63
|
-
|
|
69
|
+
errors<const TNewErrors extends CrafterErrors>(errors: TNewErrors): ActionBuilder<TConfig, TSchemas, TNewErrors, Record<string, never>, unknown>;
|
|
64
70
|
/**
|
|
65
|
-
*
|
|
71
|
+
* Defines the handler function containing the server action's business logic.
|
|
72
|
+
* Resets previously defined callbacks.
|
|
66
73
|
*/
|
|
67
|
-
|
|
74
|
+
handler<TFn extends (params: HandlerParams<TConfig, TSchemas, TErrors, TData>) => Promise<unknown>>(fn: TFn): ActionBuilder<TConfig, TSchemas, TErrors, Record<string, never>, InferDataFromHandler<TFn>>;
|
|
68
75
|
/**
|
|
69
|
-
*
|
|
76
|
+
* Defines lifecycle callbacks to be triggered during the exection of an action.
|
|
77
|
+
* Must be called after handler() for correct type inference.
|
|
70
78
|
*/
|
|
71
|
-
|
|
79
|
+
callbacks<TNewCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>>(callbacks: TNewCallbacks): ActionBuilder<TConfig, TSchemas, TErrors, TNewCallbacks, TData>;
|
|
72
80
|
/**
|
|
73
|
-
*
|
|
81
|
+
* Builds and returns the final executable server action.
|
|
82
|
+
* This is the terminal method for the ActionBuilder fluent API.
|
|
74
83
|
*/
|
|
75
|
-
|
|
84
|
+
craft(): CraftedAction<TConfig, TSchemas, TErrors, TData>;
|
|
76
85
|
}
|
|
77
86
|
/**
|
|
78
|
-
*
|
|
87
|
+
* Represents the function that the user passes to `craft()` in order to build an action.
|
|
88
|
+
*/
|
|
89
|
+
type CraftFn<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> = (crafter: Crafter<CrafterConfig, Record<string, never>, Record<string, never>, Record<string, never>, unknown>) => Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData> | Promise<Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData>>;
|
|
90
|
+
/**
|
|
91
|
+
* One of two entry points to the Actioncraft system.
|
|
92
|
+
* It provides you with an empty Crafter instance on which you can call any of the fluent
|
|
93
|
+
* Crafter methods to configure and define your action.
|
|
94
|
+
*
|
|
95
|
+
* Example Usage:
|
|
96
|
+
* ```ts
|
|
97
|
+
* const myAction = craft(async (action) => {
|
|
98
|
+
* return action
|
|
99
|
+
* .config(...)
|
|
100
|
+
* .schemas(...)
|
|
101
|
+
* .errors(...)
|
|
102
|
+
* .handler(...)
|
|
103
|
+
* .callbacks(...)
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
|
|
108
|
+
* @returns The fully-typed server action function that can be used in your app.
|
|
109
|
+
*/
|
|
110
|
+
export declare function craft<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData>(craftFn: CraftFn<TConfig, TSchemas, TErrors, TCallbacks, TData>): CraftedAction<TConfig, TSchemas, TErrors, TData>;
|
|
111
|
+
/**
|
|
112
|
+
* One of two entry points to the Actioncraft system.
|
|
113
|
+
* Creates a new ActionBuilder instance for the fluent API that ends with craft().
|
|
114
|
+
* This provides an alternative syntax for building your server actions.
|
|
115
|
+
*
|
|
116
|
+
* Example Usage:
|
|
117
|
+
* ```ts
|
|
118
|
+
* const myAction = action()
|
|
119
|
+
* .config(...)
|
|
120
|
+
* .schemas(...)
|
|
121
|
+
* .errors(...)
|
|
122
|
+
* .handler(...)
|
|
123
|
+
* .callbacks(...)
|
|
124
|
+
* .craft();
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @returns A new ActionBuilder instance to start building your action.
|
|
79
128
|
*/
|
|
80
|
-
export declare function
|
|
129
|
+
export declare function action(): ActionBuilder<Record<string, never>, Record<string, never>, Record<string, never>, Record<string, never>, unknown>;
|
|
81
130
|
/**
|
|
82
131
|
* Creates an appropriate initial state for any action based on its configuration.
|
|
132
|
+
* The initial state uses the action's real ID for consistency with actual results.
|
|
83
133
|
*
|
|
84
134
|
* For useActionState actions: returns StatefulApiResult with error and values
|
|
85
135
|
* For functional format actions: returns Result.err() with error
|