@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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CraftedAction } from "./types/actions.js";
|
|
2
|
+
import type { BaseError } from "./types/errors.js";
|
|
3
|
+
import type { InferErrors } from "./types/inference.js";
|
|
4
|
+
/**
|
|
5
|
+
* Error wrapper that provides standard Error semantics while preserving
|
|
6
|
+
* the original Actioncraft error data in the cause property.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ActioncraftError<TErrorData extends BaseError = BaseError> extends Error {
|
|
9
|
+
readonly cause: TErrorData;
|
|
10
|
+
readonly actionId?: string;
|
|
11
|
+
constructor(errorData: TErrorData, actionId?: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Type guard to check if an error is an ActioncraftError.
|
|
15
|
+
*
|
|
16
|
+
* When called with just an error, performs basic structural validation.
|
|
17
|
+
* When called with an error and action, performs verified action ID checking.
|
|
18
|
+
*
|
|
19
|
+
* @param error - The unknown error to check
|
|
20
|
+
* @param action - Optional action for verified checking and type inference
|
|
21
|
+
* @returns Type predicate indicating if error is ActioncraftError
|
|
22
|
+
*/
|
|
23
|
+
export declare function isActioncraftError<TAction extends CraftedAction<any, any, any, any>>(error: unknown, action?: TAction): error is ActioncraftError<TAction extends undefined ? BaseError : InferErrors<TAction>>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error wrapper that provides standard Error semantics while preserving
|
|
3
|
+
* the original Actioncraft error data in the cause property.
|
|
4
|
+
*/
|
|
5
|
+
export class ActioncraftError extends Error {
|
|
6
|
+
cause;
|
|
7
|
+
actionId;
|
|
8
|
+
constructor(errorData, actionId) {
|
|
9
|
+
super(`Actioncraft Error: ${errorData.type}${"message" in errorData ? ` - ${errorData.message}` : ""}`);
|
|
10
|
+
this.name = "ActioncraftError";
|
|
11
|
+
this.cause = errorData;
|
|
12
|
+
this.actionId = actionId;
|
|
13
|
+
// Ensure proper prototype chain for instanceof checks
|
|
14
|
+
Object.setPrototypeOf(this, ActioncraftError.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Type guard to check if an error is an ActioncraftError.
|
|
19
|
+
*
|
|
20
|
+
* When called with just an error, performs basic structural validation.
|
|
21
|
+
* When called with an error and action, performs verified action ID checking.
|
|
22
|
+
*
|
|
23
|
+
* @param error - The unknown error to check
|
|
24
|
+
* @param action - Optional action for verified checking and type inference
|
|
25
|
+
* @returns Type predicate indicating if error is ActioncraftError
|
|
26
|
+
*/
|
|
27
|
+
export function isActioncraftError(error, action) {
|
|
28
|
+
if (!(error instanceof ActioncraftError)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// Verify the cause property exists and has the expected BaseError structure
|
|
32
|
+
const cause = error.cause;
|
|
33
|
+
if (!cause || typeof cause !== "object") {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
// Verify the cause has a type property that's a string (required by BaseError)
|
|
37
|
+
if (!("type" in cause) || typeof cause.type !== "string") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// If message exists, it should be a string (optional in BaseError)
|
|
41
|
+
if ("message" in cause &&
|
|
42
|
+
cause.message !== undefined &&
|
|
43
|
+
typeof cause.message !== "string") {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
// If no action provided, just do structural validation
|
|
47
|
+
if (!action) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
// If action provided, verify the action ID matches
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
const actionId = action.__ac_id;
|
|
53
|
+
// Both action and error must have IDs for verification to be possible
|
|
54
|
+
if (!actionId || !error.actionId) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// Check if the error's action ID matches the action's ID
|
|
58
|
+
return error.actionId === actionId;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=actioncraft-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actioncraft-error.js","sourceRoot":"","sources":["../src/actioncraft-error.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,OAAO,gBAEX,SAAQ,KAAK;IACY,KAAK,CAAa;IAC3B,QAAQ,CAAU;IAElC,YAAY,SAAqB,EAAE,QAAiB;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ACtE,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,yDAAyD;IACzD,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ActionImpl, ActionImplParams, CraftedAction, InferDataFromActionImpl } from "./types/actions.js";
|
|
2
|
+
import type { CrafterCallbacks, CrafterConfig, CrafterErrors, CrafterSchemas } from "./types/config.js";
|
|
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
|
+
*/
|
|
7
|
+
declare class Crafter<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> {
|
|
8
|
+
private readonly _config;
|
|
9
|
+
private readonly _schemas;
|
|
10
|
+
private readonly _errors;
|
|
11
|
+
private readonly _callbacks;
|
|
12
|
+
private readonly _actionImpl?;
|
|
13
|
+
constructor(config: TConfig, schemas: TSchemas, errors: TErrors, callbacks: TCallbacks, actionImpl?: ActionImpl<TConfig, TSchemas, TErrors, TData>);
|
|
14
|
+
/**
|
|
15
|
+
* Defines validation schemas for input, output, and bind arguments.
|
|
16
|
+
* Resets previously defined actions and callbacks.
|
|
17
|
+
*/
|
|
18
|
+
schemas<TNewSchemas extends CrafterSchemas>(schemas: TNewSchemas): Crafter<TConfig, TNewSchemas, TErrors, Record<string, never>, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Defines error functions for returning typed errors from actions.
|
|
21
|
+
* Resets previously defined actions and callbacks.
|
|
22
|
+
*/
|
|
23
|
+
errors<const TNewErrors extends CrafterErrors>(errors: TNewErrors): Crafter<TConfig, TSchemas, TNewErrors, Record<string, never>, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Defines the action implementation function containing business logic.
|
|
26
|
+
* Resets previously defined callbacks.
|
|
27
|
+
*/
|
|
28
|
+
action<TFn extends (params: ActionImplParams<TConfig, TSchemas, TErrors, TData>) => Promise<unknown>>(fn: TFn): Crafter<TConfig, TSchemas, TErrors, Record<string, never>, InferDataFromActionImpl<TFn>>;
|
|
29
|
+
/**
|
|
30
|
+
* Defines lifecycle callbacks for action execution.
|
|
31
|
+
* Must be called after action() for correct type inference.
|
|
32
|
+
*/
|
|
33
|
+
callbacks<TNewCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>>(callbacks: TNewCallbacks): Crafter<TConfig, TSchemas, TErrors, TNewCallbacks, TData>;
|
|
34
|
+
/**
|
|
35
|
+
* Builds and returns the final executable action function.
|
|
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.
|
|
42
|
+
*/
|
|
43
|
+
private _extractActionArgs;
|
|
44
|
+
/**
|
|
45
|
+
* Transforms internal Result objects to client-facing action result format.
|
|
46
|
+
*/
|
|
47
|
+
private _toActionResult;
|
|
48
|
+
/**
|
|
49
|
+
* Handles uncaught exceptions during action execution.
|
|
50
|
+
*/
|
|
51
|
+
private _handleThrownError;
|
|
52
|
+
/**
|
|
53
|
+
* Validates input using the shared helper.
|
|
54
|
+
*/
|
|
55
|
+
private _validateInput;
|
|
56
|
+
/**
|
|
57
|
+
* Validates bound arguments using the configured bind schemas.
|
|
58
|
+
*/
|
|
59
|
+
private _validateBindArgs;
|
|
60
|
+
/**
|
|
61
|
+
* Validates output data using the configured output schema.
|
|
62
|
+
*/
|
|
63
|
+
private _validateOutput;
|
|
64
|
+
/**
|
|
65
|
+
* Executes the onStart callback if defined.
|
|
66
|
+
*/
|
|
67
|
+
private _executeOnStartCallback;
|
|
68
|
+
/**
|
|
69
|
+
* Executes result-based lifecycle callbacks (onSuccess, onError, onSettled).
|
|
70
|
+
*/
|
|
71
|
+
private _executeResultCallbacks;
|
|
72
|
+
/**
|
|
73
|
+
* Creates error functions that return Result objects when called by action implementations.
|
|
74
|
+
*/
|
|
75
|
+
private _buildErrorFunctions;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new Crafter instance for building type-safe server actions.
|
|
79
|
+
*/
|
|
80
|
+
export declare function create<TConfig extends CrafterConfig = CrafterConfig>(config?: TConfig): Crafter<TConfig, Record<string, never>, Record<string, never>, Record<string, never>, unknown>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates an appropriate initial state for any action based on its configuration.
|
|
83
|
+
*
|
|
84
|
+
* For useActionState actions: returns StatefulApiResult with error and values
|
|
85
|
+
* For functional format actions: returns Result.err() with error
|
|
86
|
+
* For regular actions: returns ApiResult with error
|
|
87
|
+
*
|
|
88
|
+
* Usage:
|
|
89
|
+
* - useActionState: const [state, action] = useActionState(myAction, initial(myAction))
|
|
90
|
+
* - useState: const [state, setState] = useState(initial(myAction))
|
|
91
|
+
*/
|
|
92
|
+
export declare function initial<TAction>(action: TAction): InferResult<TAction>;
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { unstable_rethrow } from "next/navigation.js";
|
|
2
|
+
import { safeExecuteCallback } from "./core/callbacks.js";
|
|
3
|
+
import { createImplicitReturnErrorResult, createUnhandledErrorResult, } from "./core/errors.js";
|
|
4
|
+
import { log } from "./core/logging.js";
|
|
5
|
+
import { convertToClientError, serializeRawInput, } from "./core/transformation.js";
|
|
6
|
+
import { validateBindArgs, validateInput, validateOutput, } from "./core/validation.js";
|
|
7
|
+
import { EXTERNAL_ERROR_TYPES, } from "./types/errors.js";
|
|
8
|
+
import { err, isErr, isOk, isResultErr, isResultOk } from "./types/result.js";
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// CRAFTER CLASS - TYPE-SAFE ACTION BUILDER
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Builder class for creating type-safe server actions with validation, error handling, and callbacks.
|
|
14
|
+
*/
|
|
15
|
+
class Crafter {
|
|
16
|
+
_config;
|
|
17
|
+
_schemas;
|
|
18
|
+
_errors;
|
|
19
|
+
_callbacks;
|
|
20
|
+
_actionImpl;
|
|
21
|
+
constructor(config, schemas, errors, callbacks, actionImpl) {
|
|
22
|
+
this._config = config;
|
|
23
|
+
this._schemas = schemas;
|
|
24
|
+
this._errors = errors;
|
|
25
|
+
this._callbacks = callbacks;
|
|
26
|
+
this._actionImpl = actionImpl;
|
|
27
|
+
}
|
|
28
|
+
// --------------------------------------------------------------------------
|
|
29
|
+
// FLUENT API METHODS
|
|
30
|
+
// --------------------------------------------------------------------------
|
|
31
|
+
/**
|
|
32
|
+
* Defines validation schemas for input, output, and bind arguments.
|
|
33
|
+
* Resets previously defined actions and callbacks.
|
|
34
|
+
*/
|
|
35
|
+
schemas(schemas) {
|
|
36
|
+
return new Crafter(this._config, schemas, this._errors, {}, undefined);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Defines error functions for returning typed errors from actions.
|
|
40
|
+
* Resets previously defined actions and callbacks.
|
|
41
|
+
*/
|
|
42
|
+
errors(errors) {
|
|
43
|
+
return new Crafter(this._config, this._schemas, errors, {}, undefined);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Defines the action implementation function containing business logic.
|
|
47
|
+
* Resets previously defined callbacks.
|
|
48
|
+
*/
|
|
49
|
+
action(fn) {
|
|
50
|
+
return new Crafter(this._config, this._schemas, this._errors, {}, fn);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Defines lifecycle callbacks for action execution.
|
|
54
|
+
* Must be called after action() for correct type inference.
|
|
55
|
+
*/
|
|
56
|
+
callbacks(callbacks) {
|
|
57
|
+
return new Crafter(this._config, this._schemas, this._errors, callbacks, this._actionImpl);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Builds and returns the final executable action function.
|
|
61
|
+
*/
|
|
62
|
+
craft() {
|
|
63
|
+
if (!this._actionImpl) {
|
|
64
|
+
throw new Error("Action implementation is not defined. Call .action() before calling .craft().");
|
|
65
|
+
}
|
|
66
|
+
const craftedAction = (...args) => {
|
|
67
|
+
return this._runAction(args);
|
|
68
|
+
};
|
|
69
|
+
// Attach the action's config for runtime inspection (used by `initial()`)
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
craftedAction.__ac_config = this._config;
|
|
72
|
+
return craftedAction;
|
|
73
|
+
}
|
|
74
|
+
// --------------------------------------------------------------------------
|
|
75
|
+
// ACTION EXECUTION
|
|
76
|
+
// --------------------------------------------------------------------------
|
|
77
|
+
/** Orchestrates action execution including validation, business logic, callbacks, and result formatting. */
|
|
78
|
+
async _runAction(args) {
|
|
79
|
+
// We know this exists because craft() verifies it
|
|
80
|
+
const actionImpl = this._actionImpl;
|
|
81
|
+
// Extract bindArgs, prevState, and input from the raw args
|
|
82
|
+
const { bindArgs: rawBindArgs, prevState, input: rawInput, } = this._extractActionArgs(args);
|
|
83
|
+
// Check for custom error handler
|
|
84
|
+
const handleThrownErrorFn = this._config.handleThrownError
|
|
85
|
+
? (error) => err(this._config.handleThrownError(error))
|
|
86
|
+
: null;
|
|
87
|
+
// Execute onStart callback before any processing
|
|
88
|
+
await this._executeOnStartCallback({
|
|
89
|
+
rawInput,
|
|
90
|
+
rawBindArgs,
|
|
91
|
+
prevState,
|
|
92
|
+
validatedInput: undefined,
|
|
93
|
+
validatedBindArgs: undefined,
|
|
94
|
+
});
|
|
95
|
+
// Track validation state for error handling
|
|
96
|
+
let validatedInput = undefined;
|
|
97
|
+
let validatedBindArgs = undefined;
|
|
98
|
+
try {
|
|
99
|
+
// Validate input and return on failure
|
|
100
|
+
const inputValidation = await this._validateInput(rawInput);
|
|
101
|
+
if (!isOk(inputValidation)) {
|
|
102
|
+
await this._executeResultCallbacks(inputValidation, {
|
|
103
|
+
rawInput,
|
|
104
|
+
rawBindArgs,
|
|
105
|
+
prevState,
|
|
106
|
+
validatedInput,
|
|
107
|
+
validatedBindArgs,
|
|
108
|
+
});
|
|
109
|
+
return this._toActionResult(inputValidation, rawInput);
|
|
110
|
+
}
|
|
111
|
+
// Update validation state
|
|
112
|
+
validatedInput = inputValidation.value;
|
|
113
|
+
// Validate bound arguments and return on failure
|
|
114
|
+
const bindArgsValidation = await this._validateBindArgs(rawBindArgs);
|
|
115
|
+
if (!isOk(bindArgsValidation)) {
|
|
116
|
+
await this._executeResultCallbacks(bindArgsValidation, {
|
|
117
|
+
rawInput,
|
|
118
|
+
rawBindArgs,
|
|
119
|
+
prevState,
|
|
120
|
+
validatedInput,
|
|
121
|
+
validatedBindArgs,
|
|
122
|
+
});
|
|
123
|
+
return this._toActionResult(bindArgsValidation, rawInput);
|
|
124
|
+
}
|
|
125
|
+
// Update validation state
|
|
126
|
+
validatedBindArgs = bindArgsValidation.value;
|
|
127
|
+
// Execute the user's action implementation
|
|
128
|
+
const actionImplResult = await actionImpl({
|
|
129
|
+
input: inputValidation.value,
|
|
130
|
+
bindArgs: bindArgsValidation.value,
|
|
131
|
+
errors: this._buildErrorFunctions(),
|
|
132
|
+
metadata: { rawInput, rawBindArgs, prevState },
|
|
133
|
+
});
|
|
134
|
+
// Return on `undefined` (implicit return error)
|
|
135
|
+
if (actionImplResult === undefined) {
|
|
136
|
+
const implicitReturnError = createImplicitReturnErrorResult();
|
|
137
|
+
await this._executeResultCallbacks(implicitReturnError, {
|
|
138
|
+
rawInput,
|
|
139
|
+
rawBindArgs,
|
|
140
|
+
prevState,
|
|
141
|
+
validatedInput,
|
|
142
|
+
validatedBindArgs,
|
|
143
|
+
});
|
|
144
|
+
return this._toActionResult(implicitReturnError, rawInput);
|
|
145
|
+
}
|
|
146
|
+
let finalResult;
|
|
147
|
+
// Process different return types from the action
|
|
148
|
+
if (isResultErr(actionImplResult)) {
|
|
149
|
+
finalResult = actionImplResult;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const outputData = isResultOk(actionImplResult)
|
|
153
|
+
? actionImplResult.value
|
|
154
|
+
: actionImplResult;
|
|
155
|
+
finalResult = await this._validateOutput(outputData);
|
|
156
|
+
}
|
|
157
|
+
// Execute callbacks and return final result
|
|
158
|
+
await this._executeResultCallbacks(finalResult, {
|
|
159
|
+
rawInput,
|
|
160
|
+
rawBindArgs,
|
|
161
|
+
prevState,
|
|
162
|
+
validatedInput,
|
|
163
|
+
validatedBindArgs,
|
|
164
|
+
});
|
|
165
|
+
// Use validated input for the values field on a successful run
|
|
166
|
+
const inputForValues = isOk(finalResult)
|
|
167
|
+
? this._schemas.inputSchema
|
|
168
|
+
? inputValidation.value
|
|
169
|
+
: rawInput
|
|
170
|
+
: rawInput;
|
|
171
|
+
return this._toActionResult(finalResult, inputForValues);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
// Re-throw Next.js framework errors
|
|
175
|
+
unstable_rethrow(error);
|
|
176
|
+
// Handle unexpected thrown errors
|
|
177
|
+
try {
|
|
178
|
+
const errorResult = this._handleThrownError(error, handleThrownErrorFn);
|
|
179
|
+
await this._executeResultCallbacks(errorResult, {
|
|
180
|
+
rawInput,
|
|
181
|
+
rawBindArgs,
|
|
182
|
+
prevState,
|
|
183
|
+
validatedInput,
|
|
184
|
+
validatedBindArgs,
|
|
185
|
+
});
|
|
186
|
+
return this._toActionResult(errorResult, rawInput);
|
|
187
|
+
}
|
|
188
|
+
catch (handlerError) {
|
|
189
|
+
// If we catch another error here, then we're done
|
|
190
|
+
log(this._config.logger, "warn", "Error handling failure - both primary error and error handler threw", { primaryError: error, handlerError });
|
|
191
|
+
return this._toActionResult(createUnhandledErrorResult(), rawInput);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Extracts bind arguments, previous state, and input from raw action arguments.
|
|
197
|
+
*/
|
|
198
|
+
_extractActionArgs(args) {
|
|
199
|
+
const numBindSchemas = this._schemas.bindSchemas?.length ?? 0;
|
|
200
|
+
if (this._config.useActionState) {
|
|
201
|
+
return {
|
|
202
|
+
bindArgs: args.slice(0, numBindSchemas),
|
|
203
|
+
prevState: args[numBindSchemas],
|
|
204
|
+
input: args[numBindSchemas + 1],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
bindArgs: args.slice(0, numBindSchemas),
|
|
209
|
+
// When useActionState is disabled the prevState parameter is never
|
|
210
|
+
// present, so we cast to never (or undefined) to satisfy the type.
|
|
211
|
+
prevState: undefined,
|
|
212
|
+
input: args[numBindSchemas],
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
// --------------------------------------------------------------------------
|
|
216
|
+
// RESULT TRANSFORMATION
|
|
217
|
+
// --------------------------------------------------------------------------
|
|
218
|
+
/**
|
|
219
|
+
* Transforms internal Result objects to client-facing action result format.
|
|
220
|
+
*/
|
|
221
|
+
_toActionResult(result, inputForValues) {
|
|
222
|
+
// Convert internal errors to client-facing errors
|
|
223
|
+
const clientResult = isOk(result) ? result : err(convertToClientError(result.error));
|
|
224
|
+
// Handle useActionState format (always returns StatefulApiResult)
|
|
225
|
+
if (this._config.useActionState) {
|
|
226
|
+
if (isOk(clientResult)) {
|
|
227
|
+
const successValues = this._schemas.inputSchema
|
|
228
|
+
? inputForValues
|
|
229
|
+
: serializeRawInput(inputForValues);
|
|
230
|
+
return {
|
|
231
|
+
success: true,
|
|
232
|
+
data: clientResult.value,
|
|
233
|
+
values: successValues,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
success: false,
|
|
238
|
+
error: clientResult.error,
|
|
239
|
+
values: serializeRawInput(inputForValues),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const format = this._config.resultFormat ?? "api";
|
|
243
|
+
// Return functional format if configured
|
|
244
|
+
if (format === "functional") {
|
|
245
|
+
return clientResult;
|
|
246
|
+
}
|
|
247
|
+
// Default API format
|
|
248
|
+
if (isOk(clientResult)) {
|
|
249
|
+
return {
|
|
250
|
+
success: true,
|
|
251
|
+
data: clientResult.value,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
success: false,
|
|
256
|
+
error: clientResult.error,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
// --------------------------------------------------------------------------
|
|
260
|
+
// ERROR HANDLING
|
|
261
|
+
// --------------------------------------------------------------------------
|
|
262
|
+
/**
|
|
263
|
+
* Handles uncaught exceptions during action execution.
|
|
264
|
+
*/
|
|
265
|
+
_handleThrownError(error, customHandler) {
|
|
266
|
+
const caughtErrorResult = customHandler
|
|
267
|
+
? customHandler(error)
|
|
268
|
+
: createUnhandledErrorResult();
|
|
269
|
+
return caughtErrorResult;
|
|
270
|
+
}
|
|
271
|
+
// --------------------------------------------------------------------------
|
|
272
|
+
// VALIDATION
|
|
273
|
+
// --------------------------------------------------------------------------
|
|
274
|
+
/**
|
|
275
|
+
* Validates input using the shared helper.
|
|
276
|
+
*/
|
|
277
|
+
_validateInput(rawInput) {
|
|
278
|
+
return validateInput(this._schemas, this._config, rawInput);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Validates bound arguments using the configured bind schemas.
|
|
282
|
+
*/
|
|
283
|
+
_validateBindArgs(bindArgs) {
|
|
284
|
+
return validateBindArgs(this._schemas, this._config, bindArgs);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Validates output data using the configured output schema.
|
|
288
|
+
*/
|
|
289
|
+
_validateOutput(data) {
|
|
290
|
+
return validateOutput(this._schemas, this._config, data);
|
|
291
|
+
}
|
|
292
|
+
// --------------------------------------------------------------------------
|
|
293
|
+
// CALLBACKS
|
|
294
|
+
// --------------------------------------------------------------------------
|
|
295
|
+
/**
|
|
296
|
+
* Executes the onStart callback if defined.
|
|
297
|
+
*/
|
|
298
|
+
async _executeOnStartCallback(metadata) {
|
|
299
|
+
const callbacks = this._callbacks;
|
|
300
|
+
if (callbacks.onStart) {
|
|
301
|
+
await safeExecuteCallback(() => callbacks.onStart({ metadata }), "onStart", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Executes result-based lifecycle callbacks (onSuccess, onError, onSettled).
|
|
306
|
+
*/
|
|
307
|
+
async _executeResultCallbacks(result, metadata) {
|
|
308
|
+
const callbacks = this._callbacks;
|
|
309
|
+
// Success path
|
|
310
|
+
if (isOk(result)) {
|
|
311
|
+
await safeExecuteCallback(callbacks.onSuccess
|
|
312
|
+
? () => callbacks.onSuccess({ data: result.value, metadata })
|
|
313
|
+
: undefined, "onSuccess", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
314
|
+
}
|
|
315
|
+
// Error path
|
|
316
|
+
if (isErr(result)) {
|
|
317
|
+
await safeExecuteCallback(callbacks.onError
|
|
318
|
+
? () => callbacks.onError({ error: result.error, metadata })
|
|
319
|
+
: undefined, "onError", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
320
|
+
}
|
|
321
|
+
// onSettled always runs, regardless of result
|
|
322
|
+
const finalResult = this._toActionResult(result);
|
|
323
|
+
await safeExecuteCallback(callbacks.onSettled
|
|
324
|
+
? () => callbacks.onSettled({ result: finalResult, metadata })
|
|
325
|
+
: undefined, "onSettled", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
326
|
+
}
|
|
327
|
+
// --------------------------------------------------------------------------
|
|
328
|
+
// UTILITY METHODS
|
|
329
|
+
// --------------------------------------------------------------------------
|
|
330
|
+
/**
|
|
331
|
+
* Creates error functions that return Result objects when called by action implementations.
|
|
332
|
+
*/
|
|
333
|
+
_buildErrorFunctions() {
|
|
334
|
+
const errorFns = {};
|
|
335
|
+
for (const [key, errorDefFn] of Object.entries(this._errors)) {
|
|
336
|
+
errorFns[key] = ((...args) => err(errorDefFn(...args)));
|
|
337
|
+
}
|
|
338
|
+
return errorFns;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// ============================================================================
|
|
342
|
+
// PUBLIC API EXPORTS
|
|
343
|
+
// ============================================================================
|
|
344
|
+
/**
|
|
345
|
+
* Creates a new Crafter instance for building type-safe server actions.
|
|
346
|
+
*/
|
|
347
|
+
export function create(config) {
|
|
348
|
+
return new Crafter(config ?? {}, {}, {}, {}, undefined);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Creates an appropriate initial state for any action based on its configuration.
|
|
352
|
+
*
|
|
353
|
+
* For useActionState actions: returns StatefulApiResult with error and values
|
|
354
|
+
* For functional format actions: returns Result.err() with error
|
|
355
|
+
* For regular actions: returns ApiResult with error
|
|
356
|
+
*
|
|
357
|
+
* Usage:
|
|
358
|
+
* - useActionState: const [state, action] = useActionState(myAction, initial(myAction))
|
|
359
|
+
* - useState: const [state, setState] = useState(initial(myAction))
|
|
360
|
+
*/
|
|
361
|
+
export function initial(action) {
|
|
362
|
+
const error = {
|
|
363
|
+
type: EXTERNAL_ERROR_TYPES.INITIAL_STATE,
|
|
364
|
+
message: "Action has not been executed yet",
|
|
365
|
+
};
|
|
366
|
+
// Attempt to read the ActionCraft config attached during craft()
|
|
367
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
368
|
+
const cfg = action?.__ac_config;
|
|
369
|
+
// Functional format -> Result<_, _>
|
|
370
|
+
if (cfg?.resultFormat === "functional") {
|
|
371
|
+
return err(error);
|
|
372
|
+
}
|
|
373
|
+
// useActionState enabled -> StatefulApiResult
|
|
374
|
+
if (cfg?.useActionState) {
|
|
375
|
+
return {
|
|
376
|
+
success: false,
|
|
377
|
+
error,
|
|
378
|
+
values: undefined,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
// Default ApiResult shape
|
|
382
|
+
return {
|
|
383
|
+
success: false,
|
|
384
|
+
error,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
//# sourceMappingURL=actioncraft-prev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actioncraft-prev.js","sourceRoot":"","sources":["../src/actioncraft-prev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,cAAc,GACf,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAEL,oBAAoB,GAGrB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAS9E,+EAA+E;AAC/E,2CAA2C;AAC3C,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO;IAOM,OAAO,CAAU;IACjB,QAAQ,CAAW;IACnB,OAAO,CAAU;IACjB,UAAU,CAAa;IACvB,WAAW,CAAiD;IAE7E,YACE,MAAe,EACf,OAAiB,EACjB,MAAe,EACf,SAAqB,EACrB,UAA0D;QAE1D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,6EAA6E;IAC7E,qBAAqB;IACrB,6EAA6E;IAE7E;;;OAGG;IACH,OAAO,CACL,OAAoB;QAEpB,OAAO,IAAI,OAAO,C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